Skip to content

Remove Cellpose ROI overlap check #889

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

Merged
merged 8 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
**Note**: Numbers like (\#123) point to closed Pull Requests on the fractal-tasks-core repository.

# 1.4.1

* Tasks:
* Remove overlap checking for output ROIs in Cellpose task to address performance issues (\#889).

# 1.4.0

Expand Down
10 changes: 0 additions & 10 deletions fractal_tasks_core/tasks/cellpose_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
from fractal_tasks_core.roi import (
find_overlaps_in_ROI_indices,
)
from fractal_tasks_core.roi import get_overlapping_pairs_3D
from fractal_tasks_core.roi import is_ROI_table_valid
from fractal_tasks_core.roi import load_region
from fractal_tasks_core.tables import write_table
Expand Down Expand Up @@ -561,15 +560,6 @@ def cellpose_segmentation(

bbox_dataframe_list.append(bbox_df)

overlap_list = get_overlapping_pairs_3D(
bbox_df, full_res_pxl_sizes_zyx
)
if len(overlap_list) > 0:
logger.warning(
f"ROI {indices} has "
f"{len(overlap_list)} bounding-box pairs overlap"
)

# Compute and store 0-th level to disk
da.array(new_label_img).to_zarr(
url=mask_zarr,
Expand Down
43 changes: 0 additions & 43 deletions tests/tasks/test_workflows_cellpose_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,49 +602,6 @@ def test_workflow_bounding_box(
assert "encoding-version" in table_group.attrs.asdict().keys()


def test_workflow_bounding_box_with_overlap(
tmp_path: Path,
zenodo_zarr: list[str],
caplog: pytest.LogCaptureFixture,
monkeypatch: MonkeyPatch,
):
monkeypatch.setattr(
"fractal_tasks_core.tasks.cellpose_segmentation.cellpose.core.use_gpu",
patched_cellpose_core_use_gpu,
)

monkeypatch.setattr(
"fractal_tasks_core.tasks.cellpose_segmentation.segment_ROI",
patched_segment_ROI_overlapping_organoids,
)

# Setup caplog fixture, see
# https://docs.pytest.org/en/stable/how-to/logging.html#caplog-fixture
caplog.set_level(logging.WARNING)

# Use pre-made 3D zarr
zarr_dir = tmp_path / "tmp_out/"
zarr_urls = prepare_3D_zarr(str(zarr_dir), zenodo_zarr)
debug(zarr_dir)
debug(zarr_urls)

# Per-FOV labeling
channel = CellposeChannel1InputModel(
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
)
for zarr_url in zarr_urls:
cellpose_segmentation(
zarr_url=zarr_url,
channel=channel,
level=3,
relabeling=True,
diameter_level0=80.0,
output_ROI_table="bbox_table",
)
debug(caplog.text)
assert "bounding-box pairs overlap" in caplog.text


def test_cellpose_within_masked_bb_with_overlap(
tmp_path: Path,
zenodo_zarr: list[str],
Expand Down
30 changes: 30 additions & 0 deletions tests/test_unit_ROIs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
find_overlaps_in_ROI_indices,
)
from fractal_tasks_core.roi import get_image_grid_ROIs
from fractal_tasks_core.roi import get_overlapping_pairs_3D
from fractal_tasks_core.roi import get_single_image_ROI
from fractal_tasks_core.roi import is_ROI_table_valid
from fractal_tasks_core.roi import (
Expand Down Expand Up @@ -755,3 +756,32 @@ def test_create_roi_table_from_df_list_with_label_repeats():
]
)
np.testing.assert_allclose(output_array, roi_table.X)


def test_get_overlapping_pairs_3D():
common_columns = {
"y_micrometer": [0.0, 0.0],
"z_micrometer": [0.0, 0.0],
"len_x_micrometer": [1.0, 1.0],
"len_y_micrometer": [1.0, 1.0],
"len_z_micrometer": [1.0, 1.0],
"label": [1, 2],
}
df_overlapping = pd.DataFrame(
{"x_micrometer": [0.0, 0.5], **common_columns}
)
full_res_pxl_sizes_zyx = [1.0, 1.0, 1.0]
df_non_overlapping = pd.DataFrame(
{"x_micrometer": [0.0, 2.0], **common_columns}
)
res_overlapping = get_overlapping_pairs_3D(
df_overlapping,
full_res_pxl_sizes_zyx,
)
assert len(res_overlapping) == 1

res_non_overlapping = get_overlapping_pairs_3D(
df_non_overlapping,
full_res_pxl_sizes_zyx,
)
assert len(res_non_overlapping) == 0
Loading