Repository navigation
BUG: label_image_centroids returned transposed, misplaced centroids - #964
Open
Srizdebnath wants to merge 1 commit into
Open
Srizdebnath wants to merge 1 commit into
Srizdebnath wants to merge 1 commit into
Conversation
The coordinate arrays were built with x varying fastest but matched against labels.flatten(), which is C order, so every centroid was computed from the wrong voxels. The z coordinates were also built from d[1] instead of d[2]. The existing test encoded the transposed output. Take voxel indices from np.argwhere so they line up with image.numpy(), support any image dimension, and honor physical=True, which was documented but ignored.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
label_image_centroidsreturns wrong centroids for any image:The coordinate arrays are built with x varying fastest (Fortran order), but the label mask is
labels.flatten(), which is C order. So the mask selects coordinates of unrelated voxels. On top of that,zcoordsrepeatsnp.arange(d[1])instead ofnp.arange(d[2]), which only goes unnoticed whend[1] == d[2].For 2x2x2 images like the ones in the docstring and the test, the result is the true centroid with the axes reversed. The existing test asserted those reversed values: label 5 sits at numpy index
[1, 1, 0]and the test expected[0, 1, 1].Changes:
np.argwhere(labels == label), so they are in the same order asimage.numpy(), the same conventionlabel_statsuses.physical=Truewas documented but ignored; the conversion was commented out. It now maps the centroids with the image's origin, spacing and direction.verticesis a DataFrame; it is an ndarray.Tests:
label_statson a 10x12x14 image, in index space and in physical space with non-unit spacing, an origin and a flipped direction.These fail on
mainand pass here.