-
Notifications
You must be signed in to change notification settings - Fork 59
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 for images/volumes #318
Add Euclidean distance transform for images/volumes #318
Conversation
fix automated setting of m1, m2, m3 parameters for 2D PBA+
When switching to 64-bit int can go up to size 2**20 on each axis.
The failure here is due to use of |
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 understand detailed algorithms so I feel I am not capable of reviewing this patch in detail.
Overall, it looks good to me.
@@ -281,3 +281,9 @@ StainTools | |||
- https://github.com/Peter554/StainTools/blob/master/LICENSE.txt | |||
- Copyright: Peter Byfield | |||
- Usage: reference for stain color normalization algorithm | |||
|
|||
PBA+ |
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.
Thank you for updating license texts! :)
python/cucim/src/cucim/core/operations/morphology/tests/test_distance_transform.py
Outdated
Show resolved
Hide resolved
python/cucim/src/cucim/core/operations/morphology/tests/test_distance_transform.py
Outdated
Show resolved
Hide resolved
remove irrelevant text (copy/paste error)
Thanks @gigony. I think the kernels are pretty well tested both here and in the original PBA+ repo, so probably doesn't need to much review in the details of the kernels in the This PR is a bit unique for cuCIM in that I kept the bulk of the kernel code in the form of CUDA C++ header files so that it is easier to view than if it was stored within a Python string. The file gets loaded into a string for purposes of runtime compilation, but keeping it in a separate file makes it easier to view with proper code highlighting either on GitHub or in an IDE. |
Made an edit to the OP to xref the related upstream CuPy issue. Hope that is ok 🙂 |
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 Greg! 🙏
Would suggest converting any TODOs into issues so we can track them better
@gpucibot merge |
closes #334 This adds a simple function that can be used to expand a set of labels in a label image. It should be reviewed after #318 is merged. The new commits only start from 6241bd2. Authors: - Gregory Lee (https://github.com/grlee77) Approvers: - https://github.com/jakirkham URL: #341
closes #335 This PR adds a function for segmentation based on active-contours. Test cases are directly from scikit-image, but the code itself was heavily refactored to make extensive use of kernel fusion via `cupy.fuse()`. I will add benchmark results here soon. It should be reviewed after #318 is merged. The new commits only start from 502f41a Authors: - Gregory Lee (https://github.com/grlee77) Approvers: - https://github.com/jakirkham URL: #343
closes #336 This PR adds a function for skeletonization of 2D images via the medial axis transform. It should be reviewed after #318 is merged. The new commits only start from 19a6fed. There is one sequential component to this algorithm that still must be run on the CPU, but the majority of the computations are on the GPU and acceleration is good. I will add benchmark results here soon. Authors: - Gregory Lee (https://github.com/grlee77) - https://github.com/jakirkham Approvers: - https://github.com/jakirkham - Gigon Bae (https://github.com/gigony) URL: #342
Filed upstream issue ( cupy/cupy#7400 ) about moving this to CuPy |
Overview
closes #319
This PR adds an implementation of
scipy.ndimage.distance_transform_edt
. For each foreground pixel in a binary image, this function computes the minimal Euclidean distance to reach a background pixel. This is a SciPy function rather than a scikit-image one so I have put it undercucim.core
instead ofcucim.skimage
. Longer term we could move this upstream to CuPy, but I think we want to have a copy here so that we can use it in the near term to implement some of the missing scikit-image functionality. This function is used by the following functions in the scikit-image API, so this PR will help us implement these in future PRs:skimage.morphology.medial_axis
(update: see #342)skimage.segmentation.expand_labels
(update: see #341)skimage.segmentation.chan_vese
(update: see #343)It is also used in examples related to
skimage.segmentation.watershed
and is needed for implementation of ITK'sSignedMaurerDistanceMapImageFilter
for itk-cucim.The algorithm used here is adapted from the C++ code in the PBA+ repository (MIT-licensed)
extensions made to PBA+ kernel source
current known limitations
sampling
argument is not fully supported. This can likely be done with a bit of effort, but will require modifications to the CUDA kernelsreturn_indices=True
are equally valid, but not always identical to those returned by SciPy. This is because there can be multiple indices with an identical distance, so which one gets chosen in that case is implementation-dependent.initial benchmarks relative to SciPy
Here
% true
is the percentage of the image that corresponds to foreground pixels. Even for fairly small images there is some benefit, with the benefit becoming two orders of magnitude at larger sizes.other comments
can likely reduce memory overhead and improve performance a bit by refactoring some of the pre/post-processing code into elementwise kernels. (e.g.
encode3d
/decode3d
, etc.)(JK) This may be able to leverage CuPy in the future ( scipy.ndimage.distance_transform_edt (Euclidean distance transform) cupy/cupy#6919 )