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 implementation? #49

Open
ma-sadeghi opened this issue Jun 5, 2021 · 16 comments
Open

skimage.segmentation.watershed implementation? #49

ma-sadeghi opened this issue Jun 5, 2021 · 16 comments
Assignees
Labels
feature request New feature or request

Comments

@ma-sadeghi
Copy link

Is your feature request related to a problem? Please describe.
It's be great if cucim implements skimage's watershed algorithm. watershed is really useful for segmentation and it'd be great if we had a GPU implementation of it.

Describe the solution you'd like
Implement skimage's watershed algorithm.

Describe alternatives you've considered
None

Additional context
None

@ma-sadeghi ma-sadeghi added the feature request New feature or request label Jun 5, 2021
@gigony
Copy link
Contributor

gigony commented Jun 9, 2021

Thanks @ma-sadeghi for the issue! We had a discussion on this issue before and we found that there are many ways to implement GPU-accelerated watershed algorithms and implementing scikit-image's watershed algorithm directly with CuPy is not feasible or tricky to implement.

We would keep follow up this issue and please let us know if you have any idea/knowledge on GPU-accelerated watershed algorithm.

Thanks!

/cc @grlee77

@jakirkham
Copy link
Member

Greg likely has more thoughts here 🙂

Though one thing worth mentioning is we do have a random_walker implementation. Admittedly not exactly what you are looking for, but may still be useful

@grlee77
Copy link
Contributor

grlee77 commented Jun 15, 2021

Looking at the scikit-image watershed demo, the seed points for the watershed are determined via scipy.distance_transform_edt. I did start a CuPy-based implementation for the distance transform based on the code in https://github.com/orzzzjq/Parallel-Banding-Algorithm-plus. I started with the 3D variant and have that working, but wanted to make things a bit more general in terms of not requiring all dimensions of the array to have the same size.

I had not started working on the watershed itself. Some reading turned up some GPU-based implementations in the literature, but I haven't looked into specifics of which might be best to implement. My initial impression of the scikit-image algorithm was that the priority queue data structure approach that is used there would likely not adapt well to the GPU.

@jakirkham
Copy link
Member

This reminds me, @JoOkuma pointed me to this watershed implementation, which might also be of interest here 🙂

@JoOkuma
Copy link

JoOkuma commented Jun 15, 2021

Hey @jakirkham.

I agree with @gigony, an implementation that produces results equivalent to skimage's watershed is tricky and might not even be that fast.

@alanpeixinho might have the GPU implementation from the article above. However, from my understanding, it does not produce the same results as the original watershed.

@grlee77
Copy link
Contributor

grlee77 commented Jun 15, 2021

Two other GPU implementations:

1.) 2D implementation based on cellular automata in recent NPP

2.) A different GPU-based algorithm with corresponding citations at watershed-cuda, but I do not see any license info in that repository. Perhaps @louismullie can indicate if it could be used under an Apache 2.0 or similar license?

@louismullie
Copy link

The implementation on my profile can be used under the Apache 2.0 license.

@grlee77
Copy link
Contributor

grlee77 commented Jun 19, 2021

The implementation on my profile can be used under the Apache 2.0 license.

Great, thanks @louismullie

@gigony gigony added this to To do in Feature Planning Sep 7, 2021
@gigony gigony moved this from Needs prioritizing to Future Release in Feature Planning Sep 7, 2021
@rijobro
Copy link

rijobro commented Nov 22, 2022

Any progress on this? @louismullie your implementation only works for 2d, correct?

@jakirkham
Copy link
Member

Based on recent discussion, another option might be to build on NPP's FloodFill

@ma-sadeghi
Copy link
Author

@jakirkham Would it work for 3D as well?

@jakirkham
Copy link
Member

No it is 2D only

@ma-sadeghi
Copy link
Author

@gigony Could you explain a little bit why porting scikit-image's watershed using cupy is not feasible? Thanks!

@jakirkham
Copy link
Member

Actually Greg's probably the best one to explain that given he's familiar with the scikit-image codebase.

That said, we talked about this again today (hence the comment on this issue). AIUI the primary challenge with the algorithm used in scikit-image is it leverages a priority queue to go through and explore each neighborhood. This isn't particularly friendly for parallelism or working on the GPU. The other algorithms mentioned above may be better for parallelism, but could render results that are qualitatively different from what scikit-image does.

@JoOkuma
Copy link

JoOkuma commented Dec 14, 2022

I would like to add that the solution to the watershed is not unique in the tie-zones (objects' boundaries where pixels have the same value). The tie-breaking strategy is usually an implementation detail and will probably yield different results in the GPU implementation.

@jakirkham
Copy link
Member

jakirkham commented Dec 14, 2022

Just noting this is something MONAI had expressed interest in using here.

cc @drbeh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
Feature Planning
Future Release
Status: No status
Development

No branches or pull requests

7 participants