Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove scikit image #2011

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions albumentations/augmentations/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import cv2
import numpy as np
import skimage
from albucore import (
MAX_VALUES_BY_DTYPE,
add,
Expand Down Expand Up @@ -1491,14 +1490,19 @@ def superpixels(
num_channels = get_num_channels(image)

for c in range(num_channels):
# segments+1 here because otherwise regionprops always misses the last label
regions = skimage.measure.regionprops(segments + 1, intensity_image=image[..., c])
for region_idx, region in enumerate(regions):
image_sp_c = image[..., c]
# Get unique segment labels (skip 0 if it exists as it's typically background)
unique_labels = np.unique(segments)
if unique_labels[0] == 0:
unique_labels = unique_labels[1:]
ternaus marked this conversation as resolved.
Show resolved Hide resolved

# Calculate mean intensity for each segment
for idx, label in enumerate(unique_labels):
# with mod here, because slic can sometimes create more superpixel than requested.
# replace_samples then does not have enough values, so we just start over with the first one again.
if replace_samples[region_idx % len(replace_samples)]:
mean_intensity = region.mean_intensity
image_sp_c = image[..., c]
if replace_samples[idx % len(replace_samples)]:
mask = segments == label
mean_intensity = np.mean(image_sp_c[mask])

if image_sp_c.dtype.kind in ["i", "u", "b"]:
# After rounding the value can end up slightly outside of the value_range. Hence, we need to clip.
Expand All @@ -1510,7 +1514,7 @@ def superpixels(
else:
value = mean_intensity

image_sp_c[segments == region_idx] = value
image_sp_c[mask] = value

return fgeometric.resize(image, orig_shape[:2], interpolation) if orig_shape != image.shape else image

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from setuptools import setup, find_packages

INSTALL_REQUIRES = [
"numpy>=1.24.4", "scipy>=1.10.0", "scikit-image>=0.21.0",
"numpy>=1.24.4",
"scipy>=1.10.0",
"PyYAML",
"typing-extensions>=4.9.0; python_version<'3.10'",
"pydantic>=2.7.0",
Expand Down
Loading