Skip to content
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

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hey2homie
Copy link

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.

Copy link

codecov bot commented Mar 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

❗ 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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mrariden
Copy link
Collaborator

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

@hey2homie
Copy link
Author

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.

Dramatically speeds up the saving masks outlines compared to already existing methods.
Added missing arguments, more consistent documentation/type-hints, little refactoring of the function for making polygons.
@hey2homie
Copy link
Author

@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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants