MouseLand / cellpose

a generalist algorithm for cellular segmentation with human-in-the-loop capabilities
https://www.cellpose.org/
BSD 3-Clause "New" or "Revised" License
1.24k stars 360 forks source link

Add option not to fill masks. Compression to TIFF files. #884

Open hey2homie opened 3 months ago

hey2homie commented 3 months ago

Often with the glial cells Cellpose fills in masks where the hole between processes is present. This affects the downstream morphological analysis and intensities computations. Added an option to disable this behaviour when calling eval.

Also, noticed that saved masks in .tif or .tiff format are quite large in size, so added compression which significantly reduced the size of the file.

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 56.27%. Comparing base (cc4e62c) to head (0975ecf). Report is 14 commits behind head on main.

:exclamation: Current head 0975ecf differs from pull request most recent head 8ea29d3. Consider uploading reports for the commit 8ea29d3 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #884 +/- ## ========================================== + Coverage 56.26% 56.27% +0.01% ========================================== Files 16 16 Lines 3784 3785 +1 ========================================== + Hits 2129 2130 +1 Misses 1655 1655 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mrariden commented 3 months ago

@hey2homie Can you post some example image/masks to demonstrate this issue?

hey2homie commented 3 months ago

Sure, this usually gets quite prominent with the ramified glia cells like on this two crops (left is grey-scale, right are masks with holes): holes_examples

I've also added the possibility to filter out holes based on their area as single pixel holes are quite prominent. Need a bit more time to test though.

hey2homie commented 3 months ago

@mrariden, I've also added options to fill in holes that are less than certain threshold.

I've also added in the same PR option to save masks with/without holes in geojson format instead of using save_txt. This dramatically speeds up the exporting of the polygonal representation of the masks. Also allows to import segmentation results directly into QuPath without any extra hassle. Slightly modified part for saving outlines to account for possible holes in the masks.

I'll add tomorrow some tests and time measurements.

hey2homie commented 3 months ago

Here is example of plotted outlines: example_1 example_2

Time it takes to save tiff, write coordinates and plot outlines for a single mask 512 by 512:

2024-03-21 17:17:34,865 [INFO] Started saving masks 2024-03-21 17:17:38,305 [INFO] Finished saving masks

2024-03-21 17:17:41,645 [INFO] Started saving masks 2024-03-21 17:17:45,201 [INFO] Finished saving masks

* After

2024-03-21 16:08:24,113 [INFO] Started saving masks 2024-03-21 16:08:24,225 [INFO] Finished saving masks

2024-03-21 16:08:24,469 [INFO] Started saving masks 2024-03-21 16:08:24,495 [INFO] Finished saving masks

2024-03-21 16:08:24,526 [INFO] Started saving masks 2024-03-21 16:08:24,555 [INFO] Finished saving masks


Time it takes to save `tiff`, write coordinates and plot outlines for a single mask 26609 by 20824 with 28k objects:
* Before

2024-03-22 11:37:51,037 [INFO] Started saving masks 2024-03-22 12:25:36,460 [INFO] Finished saving masks

* After

2024-03-21 17:01:48,731 [INFO] Started saving masks 2024-03-21 17:02:43,550 [INFO] Finished saving masks