//ver 1.33: for sample images that have first channel DIC and second channel FL //********************************************************************************************************************** //The author of this ImageJ script is I. Dogsa, Chair of Microbiology, Department of Food Science and Technology, //Biotechnical Faculty,University of Ljubljana,Večna pot 111, 1000 Ljubljana , Slovenia, EU. // The script was designed for the quantitive flourescence analysis of gfp labeled genes in the bacterial culture //You can freely use the script, but, please cite the work for which the sript was developed : //Sretenovic, S., Stojković, B., Dogsa, I., Kostanjšek, R., Poberaj, I., Stopar, D. An early mechanical coupling of planktonic bacteria in dilute suspensions. Nature Communications 8, doi: 10.1038/s41467-017-00295-z (2017) //***************************************************************************************************************************************** var avg1=0; var avg2=0; var avg=0; var imageFL; var imageBIN; var image_t; var imageBIN_OUTL var imageBIN_OUTL_t var avg_std=0; var image_std; var dir_save; var imageFL_norm_FFC; var imageOutlines; function Close_All_Windows() { while (nImages>0) { selectImage(nImages); close(); } } function ff_correction_dic() { t=getTitle; rename("generic"); run("Duplicate...", "title=blur"); run("Gaussian Blur...", "sigma=7"); //change blur radius here imageCalculator("Divide create 32-bit", "generic","blur"); selectWindow("Result of generic"); run("Conversions...", "scale"); run("8-bit"); saveAs("tiff",dir_save+t+'_FFC'); //FFc =flatfield corrected } function convert_dic_bin(){ selectImage(2); // image(1) is standard; image(2) DIC; image (3) FL; ff_correction_dic();//flat field correction for DIC image; image (4) blur for correction of image(2) = generic selectImage(5); //image (5) = flatfield corrected image (2) run("Clear Results"); run("Measure"); avg1=getResult("Mean", 0); print(avg1); run("8-bit"); selectImage(5); imageA=getImageID(); run("Duplicate...", imageA); selectImage(imageA); run("Subtract...","value="+avg1); selectImage(6); imageB=getImageID(); run("32-bit"); run("Invert"); run("Clear Results"); run("Measure"); avg2=getResult("Mean", 0); print(avg2); selectImage(imageB); run("Subtract...","value="+avg2); run("8-bit"); selectImage(imageB); run("Clear Results"); run("Measure"); avg=getResult("Mean", 0); print(avg); run("Subtract...","value="+avg); selectImage(imageA); run("Clear Results"); run("Measure"); avg=getResult("Mean", 0); print(avg); run("Subtract...","value="+avg); selectImage(imageB); run("Translate...", "x=2 y=-2 interpolation=None"); //exact translation values depend on image size and DIC optics; try different values for your system; compare imageA, imageB imageCalculator("Add create 32-bit", imageA,imageB); run("8-bit"); //run("Enhance Contrast...", "saturated=1 normalize"); run("Smooth"); setAutoThreshold("Yen dark"); run("Make Binary"); run("Watershed"); run("Divide...","value=255"); setMinAndMax(0, 0); imageBIN=getImageID(); run("Duplicate...", imageBIN); setAutoThreshold("Default dark"); setThreshold(1, 255); run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=[Bare Outlines] display clear summarize"); run("Invert"); imageBIN_OUTL=getImageID(); imageBIN_OUTL_t=getTitle(); } function total_bckg_substrct() { selectImage(imageBIN); run("Duplicate...", imageBIN); run("Multiply...", "value=255.000"); run("Dilate"); run("Dilate"); run("Invert"); run("Divide...","value=255"); imageBIN_DIL=getImageID(); imageCalculator("Multiply create 32-bit", imageFL_norm_FFC,imageBIN_DIL); image_Backg=getImageID(); run("Clear Results"); run("Set Measurements...", " mean area_fraction limit display redirect=None decimal=3"); run("Measure"); avg=getResult("Mean", 0); frac=getResult("%Area", 0); avg=avg/(frac/100); print(avg); selectImage(imageFL); run("Subtract...","value="+avg); } function get_flourescence_cells() { imageCalculator("Multiply create 32-bit", imageFL_norm_FFC,imageBIN); imageFL_DIC=getImageID(); // this image has only bacteria and zero background setAutoThreshold("Default dark"); setThreshold(0.01, 10); // theoretically your upper treshold could be higher, depending on the sample and standard; so make sure you set enough high treshold run("Clear Results"); run("Set Measurements...", "area mean standard modal min integrated redirect=None decimal=3"); run("Analyze Particles...", "size=1-Infinity circularity=0.0-1.00 show=Outlines display clear summarize"); // note that in Fiji imageJ size is measured by microns2 by default, in "normal" ImageJ it is in pixels2 imageOutlines=getImageID(); run("Distribution...", "parameter=Mean automatic"); waitForUser; //check the tresholded image if it si OK selectWindow("Results"); saveAs("measurements", dir_save+image_t+"dic_fl.xls"); //selectImage(imageBIN); //imageBIN_t=getTitle(); //saveAs("tiff", dir_save+imageBIN_t); selectImage(imageOutlines); imageOutlines=getTitle(); saveAs("tiff", dir_save+imageOutlines); } function reduce_std() { showMessage("Choose the standard image-before"); open_stack_std() ; //za standard pred run("Set Measurements...", "area mean standard limit scientific redirect=None decimal=3"); selectImage(1); run("32-bit"); run("Z Project...", "start=1 stop=10 projection=[Average Intensity]"); run("Enhance Contrast", "saturated=0.35"); selectImage(1); close(); showMessage("Choose the standard image-after"); open_stack_std() ; //za standard po selectImage(2); run("32-bit"); run("Z Project...", "start=1 stop=10 projection=[Average Intensity]"); run("Enhance Contrast", "saturated=0.35"); selectImage(2); close(); selectImage(1); curr_slice0=getImageID(); selectImage(2); curr_slice1=getImageID(); imageCalculator("Average create 32-bit", curr_slice1,(curr_slice0)); selectImage(3); image_std=getImageID(); for (j=1; j<=2; j=j+1) { selectImage(1); close(); } selectImage(1); run("Clear Results"); run("Measure"); avg_std=getResult("Mean", 0); print(avg_std); } function open_stack_std() { print("locate std stack"); open(); std=getImageID(); return nSlices; } function normalize_sample(){ selectImage(3); //original FL sample image imageFL=getImageID(); run("32-bit"); run("Divide...", "value='avg_std' stack"); run("Enhance Contrast", "saturated=0.35"); imageFL_norm=getImageID(); //normalized FL sample image imageCalculator("divide create 32-bit", imageFL_norm,image_std); image_t=getTitle(); run("Subtract Background...", "rolling=50000 sliding"); saveAs("tiff", dir_save+image_t+'_norm_FFC'); imageFL_norm_FFC=getImageID(); //normalized flatfield coorected FL sample image } function light_distribution(){ selectImage(image_std); //remove noise print("removing noise"); run("Clear Results"); run("Measure"); StdDev_std_shape=getResult("StdDev", 0); run("Remove Outliers...", "radius=30 threshold=StdDev_std_shape which=Bright"); run("Enhance Contrast", "saturated=0.35"); run("Clear Results"); run("Measure"); avg_std_shape=getResult("Mean", 0); print(avg_std_shape); run("Divide...", "value='avg_std_shape'"); run("Enhance Contrast", "saturated=0.35"); } //MAIN while (nImages>-1) { Close_All_Windows(); dir_save=getDirectory("Choose a Directory to save"); reduce_std(); //makes an average flouresciante (standard) image from two images taken at the beginning of microscopy session and at the end; gets normalization factor: std_avg light_distribution(); //removes the local inpurities or small dust, aggregates from flouresciante (standard) images and normalizes on average; used for flatfield correction of sample FL image showMessage("Choose an zvi image containing DIC and FL image"); open(); convert_dic_bin(); //DIC image of the sample is converted to binary image normalize_sample(); //normalizes FL sample image on flourescein standard (std_avg); flatfield and intensity normalization total_bckg_substrct(); //substracts the remaining background from normalized sample FL image get_flourescence_cells(); //the mean flourescence of individual cells is determined }