Created
March 16, 2022 13:48
-
-
Save romainGuiet/9392916523f4f8b6b1cf3aaa882af8d3 to your computer and use it in GitHub Desktop.
A groovy script to batch test param for cellpose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@File file_path | |
IJ.run("Close All", ""); | |
// the folder containing the lif | |
dir = file_path.getParent() | |
// a subfolder to save images | |
output_dir = new File( dir ,"outputRom1PC") | |
output_dir.mkdir() | |
imp = IJ.openImage( file_path.toString() ); | |
mb_ch = 1 | |
//diam_array = [120,90,60,30] | |
//nucCh_array = [-1,2] | |
//model_array = ["cyto", "cyto2"] | |
diam_array = [60,90,100,110] | |
nucCh_array = [0,2] | |
model_array = ["cyto","cyto2","cyto2_omni"] | |
ImagePlus[] channels_imp = ChannelSplitter.split(imp); | |
mb_imp = channels_imp[0].duplicate(); | |
mb_imp.setTitle("mb") | |
mb_imp.show() | |
nucCh_array.each{ nucCh -> | |
diam_array.each{ diam -> | |
model_array.each{ model -> | |
// Here is the Cellpose Magic | |
Cellpose_SegmentImgPlusAdvanced cellCellpose = new Cellpose_SegmentImgPlusAdvanced(); | |
cellCellpose.imp = imp; | |
cellCellpose.diameter = diam; | |
cellCellpose.cellproba_threshold = 0; | |
cellCellpose.flow_threshold = 0.4; | |
cellCellpose.model = model; | |
cellCellpose.nuclei_channel = nucCh ; | |
cellCellpose.cyto_channel = 1 ; | |
cellCellpose.dimensionMode = "3D"; | |
cellCellpose.run(); | |
cell_cellpose_imp = cellCellpose.cellpose_imp ; | |
cell_cellpose_imp.show() | |
IJ.run(cell_cellpose_imp, "glasbey_inverted", ""); | |
IJ.run(cell_cellpose_imp, mb_imp.getBitDepth()+"-bit", "");// to merge with input mb use same BitDepth | |
cell_cellpose_imp.setTitle("cellpose") | |
cell_cellpose_imp.changes = false | |
IJ.run( "Merge Channels...", "c1=[mb] c2=[cellpose] create keep"); | |
merged_imp = IJ.getImage(); | |
IJ.saveAs(merged_imp, "Tiff", new File ( output_dir, imp.getTitle()+"-"+nucCh.toString()+"-"+diam.toString()+"-"+model+".tif").toString() ) | |
//close currents images | |
merged_imp.close() | |
cell_cellpose_imp.close() | |
} | |
} | |
} | |
return | |
//IJ.run( "Merge Channels...", "c1=["+enhancedMb_imp.getTitle()+"] c2=["+dapi_imp.getTitle()+"] create keep"); | |
//dapi_enhanced_imp = IJ.getImage(); | |
import ij.* | |
import ch.epfl.biop.wrappers.cellpose.ij2commands.Cellpose_SegmentImgPlusAdvanced | |
import ij.process.* | |
import ij.gui.* | |
import java.awt.* | |
import ij.plugin.* | |
import ij.io.FileSaver | |
import ij.process.StackStatistics |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment