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

Watershed does not segment my array #5279

Closed
Make42 opened this issue Mar 20, 2021 · 1 comment
Closed

Watershed does not segment my array #5279

Make42 opened this issue Mar 20, 2021 · 1 comment

Comments

@Make42
Copy link

Make42 commented Mar 20, 2021

Description

The watershed function produces an unexpected result: It seems not to be able to segment my array even though I expect it to.

Way to reproduce

from skimage.segmentation import watershed
import numpy as np
myarray = np.array([
       [ 2.50148667,  9.44388663,  3.44389182,  3.02727774,  2.40108087,  1.61053155,  0.82294687],
       [ 3.31356207, 10.55797911,  4.69412493,  4.41801194,  3.80963218,  2.70408164,  1.35735552],
       [ 3.28787642,  4.59215029,  4.97735914, 11.08993154,  4.7925308 ,  9.6116032 ,  1.79749649],
       [ 2.87281939,  4.15976317,  4.70572275, 10.95797537,  4.73970551,  9.56800396,  1.7571604 ],
       [ 1.98065752,  2.97293194,  3.42830952,  3.56329229,  3.27749856,  2.33718172,  1.1267278 ]])
isLocalMaxArray = np.array([
       [False, False, False, False, False, False, False],
       [False,  True, False, False, False, False, False],
       [False, False, False,  True, False,  True, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False]])
watershed(-myarray, isLocalMaxArray, watershed_line=True)

produces

array([
       [1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1]], dtype=int32)

while I expected

array([
       [1, 1, 0, 3, 0, 2, 2],
       [1, 1, 0, 3, 0, 2, 2],
       [1, 1, 0, 3, 0, 2, 2],
       [1, 1, 0, 3, 0, 2, 2],
       [1, 1, 0, 3, 0, 2, 2]], dtype=int32)

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.8.8 (default, Feb 24 2021, 21:46:12)
[GCC 7.3.0]
Linux-5.4.0-67-generic-x86_64-with-glibc2.10
scikit-image version: 0.17.2
numpy version: 1.19.2

@Make42
Copy link
Author

Make42 commented Mar 20, 2021

After quite a bit of trying out, I found out, that it is not enough to simply provide if there is a peak at a certain position, but a label that indicates which peaks belong together. This can be done with skimage.measure.label

from skimage import measure
watershed(-myarray, measure.label(isLocalMaxArray, background=0), watershed_line=True)

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

1 participant