MannLabs / SPARCSpy

9 stars 6 forks source link

Updated segmentation #16

Closed namsaraeva closed 1 year ago

namsaraeva commented 1 year ago

Updates the cellpose DAPI + Cytosol segmentation method by introducing several additional filtering steps based on the filtering threshold defined in the config file.

sophiamaedler commented 1 year ago

I changed the PR to merge into the development branch. At the moment I think it makes sense to keep our new developments separate until we decide that we are ready for a new version and then bring them into the main branch.

sophiamaedler commented 1 year ago

Nucleus Mask before filtering

nucleus mask before filtering

Nucleus Mask after filtering

nucleus mask after filtering

We are definitely starting to remove some of the segmentation masks we no longer want. But for some reason some of the nuclei and cytosol masks re remaining that we would also want to eliminate. For example we still have the cytosol (and one nucleus mask) for the cell highlighted in red.

Screenshot 2023-06-16 at 11 59 12

I will go back into the code to try and figure out why this is happening. I thought your filtering approach should have taken care of it but it only removes one of the nuclei masks not both of them and also doesn't remove the cytosol mask.

sophiamaedler commented 1 year ago

I implemented the changes I commented in the code and I think it's looking good now.

I also added a debugging function where we can directly compare nucleus and cyotosol mask before and after filtering.

Screenshot 2023-06-16 at 12 47 28

The final segmentations would then look like this:

Screenshot 2023-06-16 at 12 53 29 Screenshot 2023-06-16 at 12 53 34

It would be cool if we could also make some more debugging visualisations to see why we are losing specific cells. This can help us to troubleshoot segmentations in the future. Some ideas:

  1. Showing segmentation masks in blue that we keep and those in red that we filter out as an alternative to the 4 plots that I showed above. We would then ideally overlay these color coded masks over the channels we used for generating them.
  2. Only show the masks we remove through filtering overlayed over the channel information and color them with a cmap which shows the max fraction of pixels of the nucleus that are assigned to the same cytosol. this would help us to identify filtering thresholds. we might have to make the cmap logarithmic?
  3. Histogram of the proportion scores for each image tile
  4. other ideas?
sophiamaedler commented 1 year ago

So I checked the extracted single-cell images and we still have the problem that we have some nucleus ids without a matching cytosol id. I think we will need to add the same filtering step for the nucleus make as I added for the cytosol mask where we set all ids not found in the lookup table to 0.

Screenshot 2023-06-16 at 12 59 51