// ---------------------------------------------------------------------------------------------- //This macro calculates a binary mask given a certain threshold. // Credits: // - Reference: DeepImageJ: A user-friendly environment to run deep learning models in ImageJ, // E. Gómez-de-Mariscal, C. García-López-de-Haro, W. Ouyang, L. Donati, E. Lundberg, M. Unser, A. Muñoz-Barrutia, D. Sage, // Nat Methods 18, 1192–1195 (2021). https://doi.org/10.1038/s41592-021-01262-9 // ---------------------------------------------------------------------------------------------- // clip the range of values to the [0,1] range //get multichannel prediction; extract channel 1 and apply optimized threshold //get a binary image output with foreground 255 and background 0 // THIS CODE IS MODIFIED FROM ORIGINAL binarize macro // macro "ganglia_binarise" { //check if argument is passed, if not asks user to select label image //if(getArgument()=="") //{ // waitForUser("Select the prediction from deepImageJ"); // multi_ch_prediction=getTitle(); //} //else //{ // multi_ch_prediction=getArgument(); //} multi_ch_prediction=getTitle(); selectWindow(multi_ch_prediction); run("Select None"); //get only first channel run("Duplicate...", "title=ganglia_prediction duplicate channels=1"); close(multi_ch_prediction); selectWindow("ganglia_prediction"); //custom code end getStatistics(_, _, min, max, _, _); // Threshold the output. optimalThreshold = 0.7364705882352942; setThreshold(optimalThreshold, max); setOption("BlackBackground", true); run("Convert to Mask", "method=Default background=Dark black"); setMinAndMax(0, 255); run("8-bit"); }