Repository navigation
BUG: make_points_image truncated point indices and ignored 4D images - #966
Open
Srizdebnath wants to merge 1 commit into
Open
Srizdebnath wants to merge 1 commit into
Srizdebnath wants to merge 1 commit into
Conversation
transform_physical_point_to_index returns a continuous index, and .astype(int) truncated it toward zero. Points more than half a voxel past a voxel center were placed in the previous voxel, and points outside the image, with a continuous index in [n - 0.5, n) or in (-1, -0.5), were written into the edge voxels instead of being dropped. Round to the nearest voxel the way ITK's TransformPhysicalPointToIndex does (halves up). Only 2D and 3D indices were written, so 4D target images silently got an empty label image. Index with the tuple for any dimension.
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.
make_points_imageplaces points in the wrong voxel, and does nothing at all for 4-D targets:transform_physical_point_to_indexreturns a continuous index, and.astype(int)truncates it toward zero:[n - 0.5, n)or(-1, -0.5)are written into the edge voxels instead of being dropped.This rounds to the nearest voxel the way ITK's
TransformPhysicalPointToIndexdoes, rounding halves up (floor(x + 0.5)), so an integer index from ITK and the label written here agree. Points that already sit on voxel centres, like the ones in the existing test, are unaffected.The write was also guarded by
if dim == 3 / elif dim == 2, so a 4-D target image silently returned all zeros. It now indexes withtuple(idx), which works for any dimension.Tests:
test_make_points_image_nearest_voxeluses an image with non-unit spacing and an origin, and checks a rounded-up point, a point inside the first voxel and two points just outside the image.test_make_points_image_4dcovers the 4-D case.Both fail on
mainand pass here, and the existingmake_points_imagetest still passes.