MouseLand / cellpose

a generalist algorithm for cellular segmentation with human-in-the-loop capabilities
https://www.cellpose.org/
BSD 3-Clause "New" or "Revised" License
1.4k stars 402 forks source link

Apply image restoration sequentially before segmentation #1047

Closed Feanor007 closed 2 weeks ago

Feanor007 commented 2 weeks ago

Hi Cellpose Team,

Great work! I am wondering if Cellpose3 supports applying denoising/deblurring/upsampling in a sequential manner before the final segmentation layer. For example, I want to denoise and deblur the image before segmentation. From the document provided, I couldn't find if this is possible.

ashishUthama commented 2 weeks ago

If you can invoke cellpose from Python, you could do this using the 'DenoiseModel'

Instantiate the models you want and apply the restoration sequentially, and then call the CellposeModel to segment.

derekthirstrup commented 1 week ago

@Feanor007 @carsen-stringer I implemented a denoising script to process a folder of 3D image stacks since I found errors in the way rescaling in done within cellpose. This script also does not tile the image which leads to intensity scaling artifacts in out of focus planes with tiled denoising as implemented in cellpose. The camera pixel offset has to be subtracted before min/max or percentile rescaling and this is not done properly with current cellpose rescaling method. Camera pixel offset subtraction (no px binning images =100) works great although it is ideal to use a per pixel black reference subtraction. Often it is not necessary unless you have camera with a lot of fixed pattern noise. You can probably leverage this script for your own purpose. https://github.com/AllenCell/EMT_image_analysis/blob/bioRxiv-v1/H2B_and_EOMES_instance_segmentation/1_CP3DenoiseModel_RescalePerTimepoint.py

Feanor007 commented 1 week ago

@Feanor007 @carsen-stringer I implemented a denoising script to process a folder of 3D image stacks since I found errors in the way rescaling in done within cellpose. This script also does not tile the image which leads to intensity scaling artifacts in out of focus planes with tiled denoising as implemented in cellpose. The camera pixel offset has to be subtracted before min/max or percentile rescaling and this is not done properly with current cellpose rescaling method. Camera pixel offset subtraction (no px binning images =100) works great although it is ideal to use a per pixel black reference subtraction. Often it is not necessary unless you have camera with a lot of fixed pattern noise. You can probably leverage this script for your own purpose. https://github.com/AllenCell/EMT_image_analysis/blob/bioRxiv-v1/H2B_and_EOMES_instance_segmentation/1_CP3DenoiseModel_RescalePerTimepoint.py

Thanks for sharing! I will take a look.

derekthirstrup commented 1 week ago

This script also generates an output csv that is a record of the measured rescaling values for each timepoint. I use the measured intensity trends to determine the optimal rescale values and set them as a constant. The other script listed in the link below is in the same repo requires copying a csv in the output folder named "input_scale_values.csv" which is used to apply the constant rescaling ratio to all images in the input folder which helps to maintain the relative intensity relationships of the raw data. This constant intensity rescaling preprocessing script is important for proteins that change expression level during the timelapse. https://github.com/AllenCell/EMT_image_analysis/blob/bioRxiv-v1/H2B_and_EOMES_instance_segmentation/1_CP3DenoiseModel_ScaleValuesFromCSV_ConstantScalingOutput.py