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

Accelerate segmentation postprocessing with sparse matrices #31

Open
tatyana-perlova opened this issue Mar 8, 2024 · 1 comment
Open

Comments

@tatyana-perlova
Copy link

If you use sparse instead of dense matrices for boolean indexing in segmentation workflows it should get much faster (at least for the cases when majority of image pixels are background and not cell).
E.g. in workflows.py instead of

for nucleus_id in all_nucleus_ids:
   nucleus = (masks_nucleus == nucleus_id)

use

from scipy.sparse import csr_matrix

masks_nucleus_sparse = csr_matrix(masks_nucleus)
for nucleus_id in all_nucleus_ids:
    nucleus = (masks_nucleus_sparse == nucleus_id)

And similarly for other cases of boolean indexing with segmentation masks.

@sophiamaedler
Copy link
Collaborator

HI :) This sounds like a great suggestion, I have unfortunately not had the time to test it out or benchmark it yet. I'd image there are a couple of places in the code where we would need to implement sparse matrix support but it should not be too complicated. Potentially it could make sense to implement the sparse matrix only for the filtering step and save the final results back to a dense matrix to ensure down stream compatibility with all other processing steps.

In case you'd like to make a PR we'd love to have you contribute :) Feel free to reach out if there is anything specific you'd need help with.

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

No branches or pull requests

2 participants