Skip to content

Commit

Permalink
Fix for yx images in Cellpose task
Browse files Browse the repository at this point in the history
  • Loading branch information
jluethi committed Jul 16, 2024
1 parent 558997c commit 364c5e3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Tasks:
* Fix issue with masked ROI & relabeling in Cellpose task (\#785).
* Fix issue with masking ROI label types in masked_loading_wrapper for Cellpose task (\#785).
* Enable workaround to support yx images in Cellpose task (\#789).

# 1.1.0

Expand Down
41 changes: 27 additions & 14 deletions fractal_tasks_core/tasks/cellpose_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,21 @@ def cellpose_segmentation(
output_label_name = f"label_{ind_channel}"

# Load ZYX data
data_zyx = da.from_zarr(f"{zarr_url}/{level}")[ind_channel]
# Workaround for #788: Only load channel index when there is a channel
# dimension
if ngff_image_meta.axes_names[0] != "c":
data_zyx = da.from_zarr(f"{zarr_url}/{level}")
if channel2.is_set():
raise ValueError(

Check notice on line 322 in fractal_tasks_core/tasks/cellpose_segmentation.py

View workflow job for this annotation

GitHub Actions / Coverage

Missing coverage

Missing coverage on lines 320-322
"Dual channel input was specified for an OME-Zarr image "
"without a channel axis"
)
else:
data_zyx = da.from_zarr(f"{zarr_url}/{level}")[ind_channel]
if channel2.is_set():
data_zyx_c2 = da.from_zarr(f"{zarr_url}/{level}")[ind_channel_c2]
logger.info(f"Second channel: {data_zyx_c2.shape=}")
logger.info(f"{data_zyx.shape=}")
if channel2.is_set():
data_zyx_c2 = da.from_zarr(f"{zarr_url}/{level}")[ind_channel_c2]
logger.info(f"Second channel: {data_zyx_c2.shape=}")

# Read ROI table
ROI_table_path = f"{zarr_url}/tables/{input_ROI_table}"
Expand Down Expand Up @@ -365,18 +375,21 @@ def cellpose_segmentation(
logger.info(f"Anisotropy: {advanced_cellpose_model_params.anisotropy}")

# Rescale datasets (only relevant for level>0)
# Workaround for #788
if ngff_image_meta.axes_names[0] != "c":
raise ValueError(
"Cannot set `remove_channel_axis=True` for multiscale "
f"metadata with axes={ngff_image_meta.axes_names}. "
'First axis should have name "c".'
new_datasets = rescale_datasets(

Check notice on line 380 in fractal_tasks_core/tasks/cellpose_segmentation.py

View workflow job for this annotation

GitHub Actions / Coverage

Missing coverage

Missing coverage on line 380
datasets=[ds.dict() for ds in ngff_image_meta.datasets],
coarsening_xy=coarsening_xy,
reference_level=level,
remove_channel_axis=False,
)
else:
new_datasets = rescale_datasets(
datasets=[ds.dict() for ds in ngff_image_meta.datasets],
coarsening_xy=coarsening_xy,
reference_level=level,
remove_channel_axis=True,
)
new_datasets = rescale_datasets(
datasets=[ds.dict() for ds in ngff_image_meta.datasets],
coarsening_xy=coarsening_xy,
reference_level=level,
remove_channel_axis=True,
)

label_attrs = {
"image-label": {
Expand Down

0 comments on commit 364c5e3

Please sign in to comment.