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

skimage.segmentation.watershed not giving expected output. #3808

Closed
Vapster opened this issue Mar 19, 2019 · 1 comment
Closed

skimage.segmentation.watershed not giving expected output. #3808

Vapster opened this issue Mar 19, 2019 · 1 comment

Comments

@Vapster
Copy link

Vapster commented Mar 19, 2019

Description

watershed method from skimage.segmentation is not working as it supposed to with mask parameter (or at least not as I assumed)
I think it is even segmenting area outside of mask. Some kind of dots (at regular interval) are in segmented image.
I have attached original (image which I want to segment), mask and segmented image.

Way to reproduce

# Place the full code we need to recreate your issue here
# upload all necessary images to github too!
import SimpleITK
from matplotlib import pyplot as plt
from skimage.segmentation import clear_border, watershed, mark_boundaries

org = SimpleITK.ReadImage("original.png")
mask = SimpleITK.ReadImage("mask.png")
org_array = SimpleITK.GetArrayFromImage(org)
mask_array = SimpleITK.GetArrayFromImage(mask)

segments_watershed = watershed(org_array, 1000, mask=mask_array)
plt.imshow(segments_watershed, cmap="gray")

original
mask
seg

Version information

# Paste the output of the following python commands
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__))
# your output here
>>> from __future__ import print_function
>>> import sys; print(sys.version)
3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 18:50:55) [MSC v.1915 64 bit (AMD64)]
>>> import platform; print(platform.platform())
Windows-10-10.0.17134-SP0
>>> import skimage; print("scikit-image version: {}".format(skimage.__version__))
scikit-image version: 0.14.1
>>> import numpy; print("numpy version: {}".format(numpy.__version__))
numpy version: 1.15.4
@jni
Copy link
Member

jni commented Mar 19, 2019

Thanks for the report, @Vapster! What's happening is that we are creating markers (the points from which the watershed begins) over the whole image, rather than limiting ourselves to the mask. Then, the actual watershed only happens within the mask, but you're left with those tiny, unused markers everywhere.

It's a matter of making sure the marker creation is aware of the mask. Shouldn't be too hard to fix.

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

No branches or pull requests

2 participants