Skip to content

Commit

Permalink
Merge pull request #398 from nthndy/fix-multichan-error
Browse files Browse the repository at this point in the history
fixed centroid_type error for multichannel intensity_images
  • Loading branch information
quantumjot authored Mar 5, 2024
2 parents 88efa6e + 7b90ba9 commit a933a34
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions btrack/io/_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def segmentation_to_objects( # noqa: PLR0913
use_weighted_centroid : bool, default True
If an intensity image has been provided, default to calculating the
weighted centroid. See `skimage.measure.regionprops` for more info.
Note: if measuring additional properties from a multichannel image
then use_weighted_centroid needs to be set to False, otherwise the
_props_to_dict function fails to write the output.
assign_class_ID : bool, default False
If specified, assign a class label for each individual object based on
the pixel intensity found in the mask. Requires semantic segmentation,
Expand Down Expand Up @@ -234,11 +237,21 @@ def segmentation_to_objects( # noqa: PLR0913
nodes: dict = {}
logger.info("Localizing objects from segmentation...")

centroid_type = (
"centroid_weighted"
if (use_weighted_centroid and intensity_image is not None)
else "centroid"
)
# Check if intensity image has more dimensions than segmentation
if (
intensity_image is not None
and intensity_image.ndim > segmentation.ndim
):
logger.warning(
"Multichannel intensity image detected, using unweighted centroid."
)
centroid_type = "centroid"
else:
centroid_type = (
"centroid_weighted"
if (use_weighted_centroid and intensity_image is not None)
else "centroid"
)

# we need to remove 'label' since this is a protected keyword for btrack
# objects
Expand Down

0 comments on commit a933a34

Please sign in to comment.