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

Qupath 24bit images #21

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/nimbus_inference/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def handle_qupath_segmentation_map(instance_mask: np.array):
logging.warning("QuPath RGB segmentation map detected. Converting to instance map by")
logging.warning("combining the RGB channels into a single channel via the following formula:")
logging.warning("label = RED*256**2 + GREEN * 256 + BLUE")
# move channel axis to last if not already
if instance_mask.shape.index(3) == 0:
instance_mask = np.moveaxis(instance_mask, 0, -1)
instance_mask_handled = instance_mask[..., 0] * 256**2 + instance_mask[..., 1] * 256 \
+ instance_mask[..., 2]
instance_mask_handled = instance_mask_handled.round(0).astype(np.uint64)
Expand Down Expand Up @@ -263,10 +266,11 @@ def get_segmentation(self, fov: str):
fov_path = self.fov_paths[idx]
instance_path = self.segmentation_naming_convention(fov_path)
if isinstance(instance_path, str):
instance_mask = np.squeeze(io.imread(instance_path))
instance_mask = io.imread(instance_path)
else:
instance_mask = np.squeeze(instance_path)
if len(instance_mask.shape) == 3 and instance_mask.shape[-1] == 3:
instance_mask = instance_path
instance_mask = np.squeeze(instance_mask)
if len(instance_mask.shape) == 3:
instance_mask = handle_qupath_segmentation_map(instance_mask)
instance_mask = instance_mask.astype(np.uint32)
return instance_mask
Expand Down
Loading