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

Data is always 1 despite input image #219

Closed
TimMonko opened this issue Oct 20, 2023 · 6 comments
Closed

Data is always 1 despite input image #219

TimMonko opened this issue Oct 20, 2023 · 6 comments

Comments

@TimMonko
Copy link
Contributor

When I pass skel_array
image
to csr_skeleton = skan.csr.Skeleton(skeleton_image=skel_array, source_image=skel_array) I would expect that the paths.data along each branch matches the original pixel value of skel_array (i.e. 1, 2, 3 or 4, depending on the label). However, all branches have mean-pixel-value of 1.0.

csr_skeleton.path_with_data(idx) does return 1 for all corresponding pixel indices. I don't understand why, and tracking the .paths.data definition back into scipy is not increasing clarity for me.

My hope is to use the mean-pixel-value of each branch as a way to identify the label corresponding to each skeleton_id. This way I don't need to iterate the csr.Skeleton over each label individually.

@jni
Copy link
Owner

jni commented Oct 23, 2023

Ah, I don't know whether this is a bug or a documentation issue or both 😅, but what is happening is that skan only interprets your image as an intensity image (ie as non-boolean) if it is of a float dtype. So, while we discuss the right path forward for the API, you should be able to work around this by using skan.Skeleton(skeleton_image=skel_array.astype(float). Can you double check that this produces the output you'd expect?

@TimMonko
Copy link
Contributor Author

TimMonko commented Oct 24, 2023

Yes, passing the array as a float dtype did give the expected behavior!
I have a hard time imagining a use for binarizing non-float images, so I would propose either converting all images to float or only treating the input as a boolean if it is boolean.
Thank you for the help!

@jni
Copy link
Owner

jni commented Oct 25, 2023

Agreed. Since we produce mean values even for bool, as you have noted, I don't know why I even implemented the check in the first place. 😂 These seem to be the offending lines:

skan/src/skan/csr.py

Lines 507 to 510 in 20ab48d

if np.issubdtype(skeleton_image.dtype, np.float_):
self.pixel_values = skeleton_image[coords]
else:
self.pixel_values = None

If you're happy to contribute a PR (including a test based on your example above), I'd be happy to merge it! If you're too busy that's all good, I'll get to it "soon". 😊

@TimMonko
Copy link
Contributor Author

Just updating to say I'm working on making a pull request. This will be my first time ever contributing to anything but my own stuff, so please be understanding and I'm happy to be guided however. Also the tests folder is full of great examples, so hopefully I will write one that is ok (and put this in practice for my own things). Thanks!

@TimMonko
Copy link
Contributor Author

Ok, pretty sure I did a pull request correctly? I'll be sure to follow. I'm glad I finally did something like this, was less intimidating than I expected. :)

@jni
Copy link
Owner

jni commented Oct 30, 2023

Closed by #220. Thank you @TimMonko!

@jni jni closed this as completed Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants