Repository navigation
BUG: get_neighborhood_at_voxel treated the radius as a flattened kernel - #963
Open
Srizdebnath wants to merge 1 commit into
Open
Srizdebnath wants to merge 1 commit into
Srizdebnath wants to merge 1 commit into
Conversation
A radius such as (3, 3) was passed to the C++ code as the kernel mask and turned into radius (k-1)/2, so it returned only len(kernel) voxels of a smaller neighborhood. Radii where (k-1)/2 gives a neighborhood with fewer voxels than the list length, e.g. (2, 2), read past the end of the kernel. Binary kernel arrays were converted with tolist() and rejected or misread as a radius. Expand a radius into a (2*radius+1) hypercube of ones, as ANTsR does, and flatten binary kernel arrays in the order the ITK neighborhood iterator walks them.
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.
get_neighborhood_at_voxeldocumentskernelas either a radius per axis or a binary array the shape of the neighborhood, but neither works:The Python wrapper passes the radius list straight to
getNeighborhoodas the flattened kernel mask and computesradius = (k-1)/2from it.(3, 3)becomes a 3x3 neighborhood (radius 1), and only the first two offsets are returned, because the "mask" has two entries.(2, 2)becomes radius 0, a 1-voxel neighborhood. The C++ loop then asks the iterator for offset 1, outside the neighborhood, so the second value and index are read from out-of-range memory.ndarrayis turned into a nested list withtolist(). It is then rejected by the length check, or, when its first axis happens to equal the image dimension, misread as a radius.This follows ANTsR's
getNeighborhoodAtVoxel:(2*radius+1)hypercube of ones. It must be non-negative integers, one per dimension.image.dimensiondimensions and odd sizes. It is flattened in Fortran order, which is the order the ITK neighborhood iterator walks offsets (first axis fastest). I checked this with a one-voxel asymmetric kernel.centeris unchanged. It is 1-based, like ANTsR, because the C++ code subtracts 1, and the returned indices are 1-based too. The docstring now says so.Two new tests in
tests/test_utils.pycompare the returned values against the numpy array for a 2-D radius, a 3-D radius, a zero radius, a cross-shaped kernel and a one-voxel asymmetric kernel, and check the newValueErrors. Both fail onmainand pass here. The rest oftest_utils.pypasses.