fish-quant / big-fish

Toolbox for the analysis of smFISH images.
https://big-fish.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
57 stars 18 forks source link

Is there a way outside of visual inspection to set threshold value for watershed segementation? #72

Open buttf7 opened 2 years ago

buttf7 commented 2 years ago

Is this possible?

Henley13 commented 2 years ago

Hi @buttf7,

I have nothing in mind. Threshold value is used to threshold the cell image and build a binary mask of the cells. Instead of using the function bigfish.segmentation.cell_watershed, you can use bigfish.segmentation.get_watershed_relief and bigfish.segmentation.apply_watershed, providing your own binary cell mask. Something like that:

# build relief
relief = get_watershed_relief(image, nuc_label, alpha)

# build cell mask
cell_mask = None

# segment cells
cell_label = apply_watershed(relief, nuc_label, cell_mask)

To get the cell mask, maybe you can try a more subtil Otsu thresholding or directly go for a deep learning method. we also provide a pretrained Unet model with bigfish.segmentation.unet_distance_edge_double and bigfish.segmentation.apply_unet_distance_double that does exactly that. The unet is used to predict a cell mask and the relief image on which we apply a watershed.