-
-
Notifications
You must be signed in to change notification settings - Fork 868
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 Euclidean distance transform (scipy.ndimage.distance_transform_edt) #7413
Conversation
These are adapted from the PBA project at [email protected]:orzzzjq/Parallel-Banding-Algorithm-plus.git Changes have been made to support additional integer types and a variant handling floating point pixel sizes was added
float64_distances=False is faster and uses less memory, but is inconsistent with SciPy
/test mini |
1 similar comment
/test mini |
tests/cupyx_tests/scipy_tests/ndimage_tests/test_distance_transform.py
Outdated
Show resolved
Hide resolved
/test mini |
seems like it is not finding the header :(
|
Is it getting installed? If not, maybe the Edit: Or should they be added here? Lines 55 to 72 in 76906e5
|
cupy/setup.py should be enough! |
@grlee77 could you please include the header files added here as items in the |
/test mini |
updated, please try running the tests again @emcastillo |
/test mini |
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 a lot!
closes #6919
cc @jakirkham, @gigony who helped review this previously for cuCIM. Given that this is part of the SciPy rather than scikit-image API, it seems that it could live in CuPy itself.
Background
This PR has an implementation of the Euclidean distance transform (corresponding to scipy.ndimage.distance_transform_edt). The kernels in
pba_kernels_2d.h
andpba_kernels_3d.h
are adapted from MIT-licensed code in this repository. Details regarding the algorithm implementation are provided on the author's website. It is fairly complicated, so I tried to make sure the test cases are pretty extensive.Details
The primary change to the C kernels here vs. that reference implementation are:
dominate_sp
that can be used instead ofdominate
so that we can take into account floating point sample spacing. This is needed to implement thesampling
kwarg from the SciPy API. (The originaldominate
function works with integer math, assuming spacing=1 on all axes)The set of kernels is different for the 2D and 3D cases so each has its own Python wrappers in
_pba_2d.py
andpba_3d.py
, respectively. These mostly are concerned with:There are two CuPy-only keyword arguments introduced here that may need discussion.
block_params
in the API? (an advanced user could potentially fine tune to their hardware by changing this, but the default choice should be pretty reasonable).float64_distances
is set to False, then distance computations are done in 32-bit floating point math for efficiency. I left the default toTrue
here to match SciPy's output dtype, but perhaps we should default toFalse
?One point of difference with SciPy is that when
return_indices
is True, the coordinates returned do not always match SciPy in the case of pixels that are equidistant from multiple background pixels. I think the result is equally valid and we will likely be unable to get an exact match. For that reason, not all points are checked for equality in tests involving the indices returned. The distances themselves do match SciPy to within floating point precision.Benchmarks
Here are benchmarks vs. SciPy and ITK we did previously. These are for
float64_distances=False
andsampling=None
.The last two columns are the acceleration factors vs. scipy and (multi-threaded) ITK, respectively