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

'subpixel' boundaries at the edges of an image #5432

Closed
firerain42 opened this issue Jun 18, 2021 · 2 comments · Fixed by #5447
Closed

'subpixel' boundaries at the edges of an image #5432

firerain42 opened this issue Jun 18, 2021 · 2 comments · Fixed by #5447

Comments

@firerain42
Copy link
Contributor

Description

When using the function find_boundaries with mode='subpixel' the behavior at the edges of the image seems strange to me.

From the documentation it is not clear to me what the intended behavior should be. Without an option to explicitly specify the behavior at the edges of the image, I would expect a constant input image to have no boundary at all or maybe straight lines at the edges of the image. However, for constant images with a non-zero value the actual image alternates between True and False. If the image is completely zero, there is no such effect.

Way to reproduce

import skimage.segmentation
import numpy as np
skimage.segmentation.find_boundaries(np.ones((3,3), dtype=int), mode='subpixel')

returns

array([[False,  True, False,  True, False],
       [ True, False, False, False,  True],
       [False, False, False, False, False],
       [ True, False, False, False,  True],
       [False,  True, False,  True, False]])

I would expect the same output as np.zeros((5,5), dtype=bool).

Version information

from __future__ import print_function
import sys; print(sys.version)
import platform; print(platform.platform())
import skimage; print("scikit-image version: {}".format(skimage.__version__))
import numpy; print("numpy version: {}".format(numpy.__version__))
3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 16:07:37)
[GCC 9.3.0]
Linux-5.4.0-74-generic-x86_64-with-debian-bullseye-sid
scikit-image version: 0.18.1
numpy version: 1.20.3
@mkcor
Copy link
Member

mkcor commented Jun 18, 2021

Hello @firerain42,

Thanks for reporting! I agree with you, the current behaviour is not consistent.

Would you like to try and investigate by yourself?

def _find_boundaries_subpixel(label_img):

You could run this function line by line, starting with label_img = np.ones((3, 3), dtype=int) and comparing with label_img = np.zeros((3, 3), dtype=int) to see what happens. Let me know, thanks!

@firerain42
Copy link
Contributor Author

Hello @mkcor,

I think the problem is the padding in

windows = view_as_windows(np.pad(label_img_expanded, 1,
mode='constant', constant_values=0),
(3,) * ndim)

which introduces 0 as an image value. Replacing it with np.pad(label_img_expanded, 1, mode='edge') should do the trick. I would have sent a pull request, but I couldn't get the tests running on my PC (and don't have the time to find the cause).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants