cellpose icon indicating copy to clipboard operation
cellpose copied to clipboard

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

Open hey2homie opened this issue 1 year ago • 7 comments

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.

hey2homie avatar Mar 05 '24 16:03 hey2homie

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
@@            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.

codecov[bot] avatar Mar 14 '24 20:03 codecov[bot]

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

mrariden avatar Mar 14 '24 20:03 mrariden

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 avatar Mar 15 '24 14:03 hey2homie

@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 avatar Mar 21 '24 16:03 hey2homie

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:

  • Before
2024-03-21 17:17:04,229 [INFO] Started saving masks
2024-03-21 17:17:07,615 [INFO] Finished saving masks

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

hey2homie avatar Mar 22 '24 12:03 hey2homie