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 spacing to regionprops and moments. #6296
Conversation
Hello @tibuch! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2022-04-04 07:12:59 UTC |
Thanks @tibuch, we are very keen to have this functionality. I will try to review this soon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tibuch awesome! Thank you for tackling this, apologies that I never got round to it! 😅 I really appreciate it. I have made a couple of suggestions, most are nitpicky and I would consider optional for approval, but the ones I really care about are adding indices
or coords_scaled
as a property (since coords are in many cases used for indexing so you don't want the scaling), and removing pixel_area
as a property since it is a property of the image, not the region, and trivial to compute outside of the function.
Thank you again!
skimage/measure/_regionprops.py
Outdated
'Non-integer image types are ambiguous: ' | ||
'use skimage.measure.label to label the connected' | ||
'components of label_image,' | ||
'or label_image.astype(np.uint8) to interpret' | ||
'the True values as a single label.') | ||
else: | ||
raise TypeError( | ||
'Non-integer label_image types are ambiguous') | ||
'Non-integer label_image types are ambiguous') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind reverting unrelated formatting changes? They will make git-blame harder to follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope I caught all of them 😇
@@ -198,51 +338,75 @@ def test_coordinates(): | |||
prop_coords = regionprops(sample)[0].coords | |||
assert_array_equal(prop_coords, coords) | |||
|
|||
spacing = (1, 0.5) | |||
prop_coords = regionprops(sample, spacing=spacing)[0].coords | |||
assert_array_equal(prop_coords, coords * np.array(spacing)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all of these tests, I'd prefer if there was a separate test function for unit spacing, isotropic spacing, and anisotropic spacing, perhaps using pytest.parametrize
? It makes it much easier to find failing tests in the future...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
You will also notice that not all features are tested with anisotropy, because I could not find reference numbers. Do you know of some implementations that could be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't. Typically I would try to hand-check the numbers (going step by step in the implementation) and then save those as a reference. Or you can derive some from first principles, for example, drawing an ellipse with a particular orientation using skimage.draw
, then taking away every other row of pixels and using spacing=(2, 1)
and making sure that the results are close to the isotropic case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tibuch, this is looking pretty good. I just had some small fixes and suggestions.
I implemented the requested changes. Additionally I found that the normalized moments were wrong. Could you have a close look at this commit: 41322934dcfbb5db74b98e369d8264997465a43a Thanks! |
Nice catch @tibuch! Looks good to me. It looks like the tolerance on some of the tests needs to be reduced to
|
Don't know why these are failing:
|
Pillow 9.1 was released Apr 1 so I presume that is the culprit, nothing to do with your work @tibuch! |
Yeah, see #6314 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I was wondering when this code will make it into an official release? Cheers |
Hey @tibuch. We've just started with the preparation of the next release 0.20. We are not certain on the precise target date yet but somewhere around 2022-10-24. You can follow along our 0.20 milestone if you want to stay informed on the progress. |
…d regionprops (#422) related to #419 This PR ports features related to image moments and `regionprops` from scikit-image 0.20 to cuCIM - Improve performance of ``cucim.skimage.measure.moments_central`` by ~2x by avoiding redundant computations (adaptation of scikit-image/scikit-image#6188 to the GPU) - Support anisotropic images with different voxel spacings. Spacings can be defined with the new parameter ``spacing`` of the following functions in ``skimage.measure``: ``regionprops``, ``regionprops_table``, ``moments``, ``moments_central``, ``moments_normalized``, ``centroid``, ``inertia_tensor``, and ``inertia_tensor_eigvals`` (scikit-image/scikit-image#6296) - Voxel spacing is taken into account for the following existing properties in ``skimage.measure.regionprops``: ``area``, ``area_bbox``, ``centroid``, ``area_convex``, ``extent``, ``feret_diameter_max``, ``area_filled``, ``inertia_tensor``, ``moments``, ``moments_central``, ``moments_hu``, ``moments_normalized``, ``perimeter``, ``perimeter_crofton``, ``solidity``, ``moments_weighted_central``, and ``moments_weighted_hu``. (scikit-image/scikit-image#6296) - Raise a specific error message when accessing region properties from skimage.measure.regionprops when the required intensity_image is unavailable (scikit-image/scikit-image#6584). Authors: - Gregory Lee (https://github.com/grlee77) Approvers: - Gigon Bae (https://github.com/gigony) URL: #422
This pull request has been mentioned on Image.sc Forum. There might be relevant details there: https://forum.image.sc/t/scaling-regionprops-for-non-isotropic-images/61971/5 |
Description
Enhancement, closes #5112.
Checklist
./doc/examples
(new features only)For reviewers
later.
__init__.py
.doc/release/release_dev.rst
.example, to backport to v0.19.x after merging, add the following in a PR
comment:
@meeseeksdev backport to v0.19.x
run-benchmark
label. To rerun, the labelcan be removed and then added again. The benchmark output can be checked in
the "Actions" tab.