fractal-analytics-platform / fractal-tasks-core

Main tasks for the Fractal analytics platform
https://fractal-analytics-platform.github.io/fractal-tasks-core/
BSD 3-Clause "New" or "Revised" License
11 stars 5 forks source link

Support more than one channel when masking background #639

Closed franziskamoos closed 5 months ago

franziskamoos commented 5 months ago

The original code could only work with one channel input for masking the background. This commit adds support for more than one channel.

Checklist before merging

Closes #640

franziskamoos commented 5 months ago

This is the error we got without the fix:

2024-01-16 14:49:41,035; INFO; Now processing ROI 1/3
2024-01-16 14:49:41,118; INFO; [_preprocess_input] image_array.shape=(2, 18, 296, 316)
2024-01-16 14:49:41,118; INFO; [_preprocess_input] region=(slice(0, 18, None), slice(36, 332, None), slice(140, 456, None))
2024-01-16 14:49:41,131; INFO; [_preprocess_input] ROI_table_path='/path/230828CS001AAA48h.zarr/B/02/0/tables/organoid_ROI_table'
2024-01-16 14:49:41,131; INFO; [_preprocess_input] attrs.asdict()={'encoding-type': 'anndata', 'encoding-version': '0.1.0', 'instance_key': 'label', 'region': {'path': '../labels/organoids'}, 'type': 'ngff:region_table'}
/code/fractal-tasks-core/fractal_tasks_core/tables/v1.py:41: FutureWarning: Table type `ngff:region_table` is currently accepted instead of `masking_roi_table`, but it will be deprecated in the future. Please switch to `type='masking_roi_table'`.
  warnings.warn(warning_msg, FutureWarning)
2024-01-16 14:49:41,132; INFO; masking_label_path='/path/230828CS001AAA48h.zarr/B/02/0/tables/../labels/organoids/0'
2024-01-16 14:49:41,133; INFO; [_preprocess_input] masking_label_path='/path/230828CS001AAA48h.zarr/B/02/0/tables/../labels/organoids/0', masking_label_array.shape=(18, 540, 640)
2024-01-16 14:49:41,134; INFO; [_preprocess_input] current_label_path='/path/230828CS001AAA48h.zarr/B/02/0/labels/Organoids_test/0', current_label_array.shape=(18, 2160, 2560)
2024-01-16 14:49:41,146; INFO; Upscaling of masking label is needed
2024-01-16 14:49:41,163; INFO; background_4D.shape=(1, 18, 296, 316)
Traceback (most recent call last):
  File "/code/cellpose_2D3D_merging/src/cellpose_2d3d_merging/cellpose_2D3D_merging.py", line 918, in <module>
    run_fractal_task(
  File "/code/fractal-tasks-core/fractal_tasks_core/tasks/_utils.py", line 79, in run_fractal_task
    metadata_update = task_function(**pars)
  File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
  File "pydantic/decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call
  File "pydantic/decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute
  File "/code/cellpose_2D3D_merging/src/cellpose_2d3d_merging/cellpose_2D3D_merging.py", line 806, in cellpose_segmentation
    new_label_img = masked_loading_wrapper(
  File "/code/fractal-tasks-core/fractal_tasks_core/masked_loading.py", line 238, in masked_loading_wrapper
    ) = _preprocess_input(image_array, **preprocessing_kwargs)
  File "/code/fractal-tasks-core/fractal_tasks_core/masked_loading.py", line 175, in _preprocess_input
    image_array[background_4D] = 0
IndexError: boolean index did not match indexed array along dimension 0; dimension is 2 but corresponding boolean dimension is 1
jluethi commented 5 months ago

Thanks a lot for reporting this and providing a fix for it!

@tcompa Can we reproduce this in our current test cases with a dual channel image and include a (currently failing) test that then gets solved by this PR?

tcompa commented 5 months ago

Can we reproduce this in our current test cases with a dual channel image and include a (currently failing) test that then gets solved by this PR?

Done.


Thanks a lot @FranziskaMoos-FMI!