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

Fix deprecation warning in Superpixels #672

Merged
merged 3 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed an `skimage` deprecation warning in `Superpixels`. #672
23 changes: 22 additions & 1 deletion imgaug/augmenters/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
_REPLACE_SEGMENTS_NP_BELOW_AREA = 64 * 64
_REPLACE_SEGMENTS_NP_BELOW_NSEG = 25

_SLIC_SUPPORTS_START_LABEL = (
tuple(map(int, skimage.__version__.split(".")[0:2]))
>= (0, 17)
) # Added in 0.5.0.


# TODO merge this into imresize?
def _ensure_image_max_size(image, max_size, interpolation):
Expand Down Expand Up @@ -273,8 +278,24 @@ def _augment_batch_(self, batch, random_state, parents, hooks):
image = _ensure_image_max_size(image, self.max_size,
self.interpolation)

# skimage 0.17+ introduces the start_label arg and produces a
# warning if it is not provided. We use start_label=0 here
# (old skimage style) (not entirely sure if =0 is required or =1
# could be used here too, but *seems* like both could work),
# but skimage will change the default start_label to 1 in the
# future.
kwargs = (
{"start_label": 0}
if _SLIC_SUPPORTS_START_LABEL
else {}
)

segments = skimage.segmentation.slic(
image, n_segments=n_segments_samples[i], compactness=10)
image,
n_segments=n_segments_samples[i],
compactness=10,
**kwargs
)

image_aug = replace_segments_(
image, segments, replace_samples > 0.5
Expand Down