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

Add napari plugin with skeletonize widget #184

Merged
merged 7 commits into from
Jan 26, 2023

Conversation

jamesyan-git
Copy link
Contributor

This PR adds a napari plugin with a basic widget for skeletonizing a labels layer.

@jamesyan-git
Copy link
Contributor Author

@jni This does not work for because of an strange error regarding label dimensionality. Strange because it says it expects a 2d or 3d layer but it has certainly been passed a 2d layer.
Tried this in ipython with a numpy array and did not error. We checked the attributes of the data and it all seems to be what skeletonize requires, so I'm a bit lost. Would love your insights!

import numpy as np
from skimage.morphology import skeletonize
img = np.zeros(shape=(100, 100), dtype=np.uint8)
img[0:10, 0:10] = 1
skeletonize(img, method='zhang')


def skeletonize_labels(labels: "napari.types.LabelsData", method: SkeletonizeMethod) -> "napari.types.LabelsData":
binary_labels = (labels > 0).astype(np.uint8)
skeletonized = skeletonize(binary_labels, method=method)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesyan-git yeah this was super tricky and confusing! But I finally cracked it! 😅

Suggested change
skeletonized = skeletonize(binary_labels, method=method)
skeletonized = skeletonize(binary_labels, method=method.value)

What's happening is that skimage doesn't understand the enum method, so it finds no valid method and ends up in the else clause. It's a confusing error message, because apparently it never occurred to us that one could pass in an invalid argument. 😂 Would you mind raising an issue in skimage? I get the same error with:

import numpy as np
from skimage.morphology import skeletonize

result = skeletonize(np.ones((5, 5)), method='foo')

@jni
Copy link
Owner

jni commented Dec 22, 2022

That was super tricky! 😅 Sorry for the misleading error message — good chance I wrote it at some point! 😂

As a minor comment, I would like this function to be in the skan package itself, not in a new napari_skan package.

Thank you! 😊 🙏

jamesyan-git and others added 2 commits December 23, 2022 12:26
Co-authored-by: Juan Nunez-Iglesias <jni@fastmail.com>
@jamesyan-git
Copy link
Contributor Author

Thank you very much for the help @jni! It works now!

@jni
Copy link
Owner

jni commented Dec 24, 2022

@jamesyan-git so cool! 😊 Should we merge this one as-is and do the skeleton analysis in the next step? Or do you want to wait until you add the shapes layer?

@jni
Copy link
Owner

jni commented Jan 9, 2023

@jamesyan-git 👋

@jamesyan-git jamesyan-git marked this pull request as ready for review January 11, 2023 01:20
@jamesyan-git
Copy link
Contributor Author

Hi @jni, sorry I missed that. I've added a docstring, I think we can merge now.
I wanted to add some instructions on the widget for the user, but it seems non trivial if we want to continue auto-generating it.
Not auto-generating it would introduce dependencies though (magicgui for decorator at least), but this is necessary even for something trivial like changing the button text. I'm happy to go this route if you are, can do in separate PR if you approve.
I was thinking of just adding an example for usage, but I'm not sure if that alone is sufficient for a new user.
Let me know what you think and I'll follow up.

@jni
Copy link
Owner

jni commented Jan 12, 2023

LOL New networkx just dropped and broke everything! 😂🤦

@jni jni merged commit 7498831 into jni:main Jan 26, 2023
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 this pull request may close these issues.

2 participants