Skip to content

Commit

Permalink
add robust_perimeter flag
Browse files Browse the repository at this point in the history
  • Loading branch information
grlee77 committed Mar 4, 2025
1 parent d21edcb commit 80199fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
33 changes: 27 additions & 6 deletions python/cucim/src/cucim/skimage/measure/_regionprops_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def regionprops_dict(
moment_order=None,
max_label=None,
pixels_per_thread=16,
robust_perimeter=True,
):
"""Compute image properties and return them as a pandas-compatible table.
Expand Down Expand Up @@ -259,6 +260,15 @@ def regionprops_dict(
from each GPU thread. The number of adjacent pixels processed
corresponds to `pixels_per_thread` and can be used as a performance
tuning parameter.
robust_perimeter : bool, optional
Batch computation of perimeter and euler characteristics can give
incorrect results for perimeter pixels that are not more than 1 pixel
spacing from another label. If True, a check for this condition is
performed and any labels close to another label have their perimeter
recomputed in isolation. Doing this check results in performance
overhead so can optionally be disabled. This parameter effects the
following regionprops: {"perimeter", "perimeter_crofton",
"euler_number"}.
"""
supported_properties = CURRENT_PROPS_GPU | GLOBAL_PROPS
properties = set(properties)
Expand Down Expand Up @@ -583,16 +593,27 @@ def regionprops_dict(
labels_mask = label_image.view("bool")
else:
labels_mask = label_image > 0
labels_close = _find_close_labels(
label_image, binary_image=labels_mask, max_label=max_label
)
if robust_perimeter:
# avoid repeatedly computing "labels_close" for
# perimeter, perimeter_crofton and euler_number regionprops
labels_close = _find_close_labels(
label_image, binary_image=labels_mask, max_label=max_label
)
if labels_close.size > 0:
print(
f"Found {labels_close.size} regions with <=1 background "
"pixel spacing from another region. Using slower robust "
"perimeter/euler measurements for these regions."
)
else:
labels_close = None

if compute_perimeter:
regionprops_perimeter(
label_image,
neighborhood=4,
max_label=max_label,
robust=True,
robust=robust_perimeter,
labels_close=labels_close,
props_dict=out,
)
Expand All @@ -601,7 +622,7 @@ def regionprops_dict(
label_image,
directions=4,
max_label=max_label,
robust=True,
robust=robust_perimeter,
omit_image_edges=False,
labels_close=labels_close,
props_dict=out,
Expand All @@ -612,7 +633,7 @@ def regionprops_dict(
label_image,
connectivity=None,
max_label=max_label,
robust=True,
robust=robust_perimeter,
labels_close=labels_close,
props_dict=out,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"regionprops_moments_normalized",
]


# Store information on which other properties a given property depends on
# This information will be used by `regionprops_dict` to make sure that when
# a particular property is requested any dependent properties are computed
Expand Down

0 comments on commit 80199fd

Please sign in to comment.