Skip to content
Advertisement

Skimage Rescale Segmentation Mask

Can somebody explain why I cannot use rescale() from here to rescale a segmentation mask? I tried the following:

JavaScript

I’d expect the result to contain only ones, but this does not happen. What is the correct way of downscaling the height and width of a segmentation mask by half?

Advertisement

Answer

I think we can classify this as a bug. The origin of your problem is the way scikit-image views data types, which is detailed in this page:

https://scikit-image.org/docs/dev/user_guide/data_types.html

In some sense, scikit-image sees those values (float 0.00392157) as “equivalent” to (uint8 1).

You can use the keyword argument preserve_range=True in order to keep the scale as the input, but you will still get the incorrect dtype.

JavaScript

I think for order=0 we should not change the dtype, and have made an issue here:

https://github.com/scikit-image/scikit-image/issues/5268

In the meantime, I hope you can use preserve_range=True and .astype(int) to get unstuck.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement