Skip to content

Cellpose Filtering Workflow Bug #34

@sophiamaedler

Description

@sophiamaedler

When applying the cell pose segmentation workflow some cytosol masks are not filtered out even though they do not have a matching nucleus.

Code and data to reproduce:

from sparcscore.pipeline.project import TimecourseProject
from sparcscore.pipeline.workflows import Multithreaded_Cytosol_Cellpose_Downsampling_TimecourseSegmentation, Cytosol_Cellpose_Downsampling_TimecourseSegmentation
from sparcscore.pipeline.extraction import TimecourseHDF5CellExtraction

project_location = f"test_project"
config_file = "config_segmentation.yml"

project = TimecourseProject(project_location, 
                            config_path=config_file, 
                            segmentation_f=Multithreaded_Cytosol_Cellpose_Downsampling_TimecourseSegmentation,
                            extraction_f = TimecourseHDF5CellExtraction,
                            overwrite=False,
                            debug=True)

#load data
images = np.load("images.npy")
labels = pd.read_csv("labels.csv", index_col = 0)

project.load_input_from_array(images, label = labels, overwrite = True)

project.segment()

All of the ids found in the nucleus mask should also be found in the cytosol mask but in this specific example that is not the case for the first image tile. This statement should return true but it returns false.

nucleus_ids = set(np.unique(segmentation[0][0]))
cytosol_ids = set(np.unique(segmentation[0][1]))

print(cytosol_ids.issubset(nucleus_ids))
Screenshot 2024-05-07 at 10 42 50

Data to reproduce:
Archive.zip

I have already implemented a warning which is issued during segmentation when this occurs, but the source of the problem needs to be identified. This bug was the reason why during extraction we sometimes got empty cells. This problem has been fixed as we now only look at cell_ids contained in the nucleus mask.

[06/05/2024 16:33:09] Warning: Different classes in different segmentatio channels. Please report this example to the developers
[06/05/2024 16:33:09] set1 nucleus: set(np.unique(shifted_map[0]))
[06/05/2024 16:33:09] set2 cytosol: set(np.unique(shifted_map[1]))
[06/05/2024 16:33:09] {48} not in nucleus mask
[06/05/2024 16:33:10] set() not in cytosol mask

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions