Skip to content
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

Region Properties Performance Overhaul - Part 6: Public API (regionprops_table) #848

Open
wants to merge 18 commits into
base: branch-25.04
Choose a base branch
from

Conversation

grlee77
Copy link
Contributor

@grlee77 grlee77 commented Mar 4, 2025

Please review #843 first as that explains the general approach in more detail.

Overview

All of the available region properties were implemented for regionprops_dict in parts 1-5.

This MR's purpose is just to add ability for the existing cucim.skimage.measure.regionprops_table function to call regionprops_dict by default under the hood. This will allow existing code based on regionprops_table to see an immediate performance benefit.

The user can set kwarg batch_processing=False to keep using the old implementation based on the RegionProperties class. I am not sure if we should provide that option or just remove it. I think the only case it may be useful is that memory requirements could be lower for the non-batch approach as properties are computed on individual regions in isolation. Due to caching behavior of RegionProperties, though, the memory usage might not actually be all that much lower.

For compatibility with regionprops_table API, the regionprops_dict implementation is updated to support user-provided callables for extra_properties. For such "extra" properties there will not be a performance benefit to regionprops_dict vs. legacy regionprops_table as it will also loop over individual regions and apply this function on each.

The functions introduced here are not being added to the public API. They will
be used behind the scenes from `regionprops_table` to enable orders of magnitude
faster computation of region properties for all labels in an image. The basic
approach here is to compute a property for all labels in an image from a single
CUDA kernel call. This is in contrast to the approach from the `RegionProperties`
class which first splits the full image into small sub-images corresponding to
each region and then loops over these small sub-images, computing the requested
property for each small region in turn. That approach is not amenable to good
acceleration on the GPU as individual regions are typically small.

Provides batch implementation that computes the following properties for all properties
in a single kernel call:

- bbox
- label_filled (creates version of label_image with all holes filled)
- num_pixels
- num_pixels_filled
- num_perimeter_pixels (number of pixels at perimeter of each labeled region)
- num_boundary_pixels (number of pixels touching the image boundary for each region)

The following properties are simple transformations of the properties above and
have negligable additional cost to compute:

- area
- area_bbox
- area_filled
- equivalent_diameter_area
- equivalent_spherical_perimeter (as in ITK)
- extent
- perimeter_on_border_ratio (as in ITK)
- slice

The following split the label image into a list of sub-images or subsets of coordinates
where each element in the list corresponds to a label. The background of the label image
has value 0 and is not represented in the sequences. Sequence entry `i` corresponds to
label `i + 1`. In most cases, these will not be needed as properties are now computed
for all regions at once from the labels image, but they are provided for completeness
and to match the scikit-image API.

- coords
- coords_scaled
- image (label mask subimages)
- image_convex (convex label mask subimages)
- image_intensity (intensity_image subimages)
- image_filled (subimages of label mask but with holes filled)
- label (sequence of integer label ids)

Test cases are added that compare the results of these batch computations to results
from scikit-image `regionprops_table`.
This function operates similarly to `regionprops_table`. In a future commit,
once all properties have been supported, it will be used within the existing
regionprops_table function so that it will provide much higher performance.
- intensity_mean
- intensity_std
- intensity_min
- intensity_max

Both single and multi-channel intensity images are supported
These properties are computed based on the image_convex subimages:

- area_convex
- feret_diameter_max
- solidity
@grlee77 grlee77 added improvement Improves an existing functionality non-breaking Introduces a non-breaking change performance Performance improvement labels Mar 4, 2025
@grlee77 grlee77 added this to the v25.04.00 milestone Mar 4, 2025
@grlee77 grlee77 self-assigned this Mar 4, 2025
@grlee77 grlee77 requested review from a team as code owners March 4, 2025 03:10
@grlee77 grlee77 requested a review from msarahan March 4, 2025 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality non-breaking Introduces a non-breaking change performance Performance improvement
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant