// ********************************************************************** // declare global variable //var mypath="c:/"; // ********************************************************************** // "0metafluor_intensity_2images" // Macro to measure mean intensity of one large object (ex: artery) at two wavelength (pairs of images), using each image to create a mask and measuring both images with both masks. // Fabrice Duprat october 2012 // INPUT: Serie of 2 images (2 wavelength, tif) from Metafluor, named with no blank, wavelength code (from 1 to 5) at the end of the name and extension indicating the rank (from 000 to 999) (ex: photo3.012 and photo4.012) // INPUT: wavelength code (from 1 to 5) of first and second image MUST be indicated in the variables "mywave1" and "mywave2" // INPUT: Asks to choose Image1 of the first pair of images and the macro automatically opens Image2 based on the wavelength codes, and then ask for the next Image1, …. // OUTPUT: A formatted file (called by default: analyse.txt) with : // image names, Mean intensity of Image1 measure with Mask1, idem for Image2 with Mask2, idem for Image1 with Mask2, idem for Image2 with Mask2, // Area of Mask1, Area of Mask2, Ratio of Images 1 and 2 measured with Mask1, Ratio of Images 1 and 2 measured with Mask2, Ratio of Images 1 measured with Mask1 and Images 2 measured with Mask2 // OUTPUT: Results window contains the same results but with one line per measurement (4 lines for each pair of images). // // ******************************************************************************** // // If you are using this script for a research article, please cite this web page: https://www.ipmc.cnrs.fr/~duprat/scripts/ // macro "Metafluor_intensity_2images" { ////////////////////////// // TO BE CHOOSEN BY THE USER // Code of first image wavelength mywave1=4; // Code of second image wavelength mywave2=3; ////////////////////////// // INITIAL SETTINGS run("Clear Results"); run("Colors...", "foreground=black background=white selection=red"); run("Set Measurements...", "area mean integrated area_fraction display redirect=None decimal=1"); mycounterarray= newArray(500); // array to save the interesting lines number of result file (1 to mycounter) mycounter=-1; // number of interesting lines in results window, start at 0 mainwhile=1; run("Close All Without Saving"); // Close all images (the plugin needs to be installed) while (roiManager("count")!= 0) // Empty the ROI manager list {roiManager("Delete");} // START LOOPING FOR EACH IMAGE while (mainwhile ==1) { // Open Image 1 image1 = File.openDialog("CHOOSE image1 of 1/2 to analyse"); open(image1); titre_image1 = getTitle(); mypath = getDirectory("image"); nb = indexOf(titre_image1, mywave1+"."); image2_debut = substring( titre_image1, 0, nb ); //Get image1 file name before the wavelength digit image2_fin = substring( titre_image1, nb+1 ); //Get image1 file name after the "." titre_image2 = image2_debut + mywave2 + image2_fin; image2 = mypath + image2_debut + mywave2 + image2_fin; run("Duplicate...", "title=TEMP"); rename(titre_image1+"_mask1"); // Open automaticaly Image 2 //image2 = File.openDialog("CHOOSE image2 of 1/2 to analyse"); open(image2); //titre_image2 = getTitle(); //mypath = getDirectory("image"); //nb = indexOf(image2, ".tif"); //nom_image2 = substring( image2, 0, nb ); //Get rid of .tif extension in the name run("Duplicate...", "title=TEMP"); rename(titre_image2+"_mask2"); selectWindow(titre_image1); setLocation(10, 10); selectWindow(titre_image2); setLocation(10, 600); // ANALYSE BOTH IMAGES WITH IMAGE1 MASK // Create mask1 from Image1 selectWindow(titre_image1+"_mask1"); run("8-bit"); run("Threshold..."); //setAutoThreshold("Default dark"); setThreshold(25, 255); waitForUser("Adjust threshold"); run("Convert to Mask"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); // Clean the image for mask1 //run("Color Picker..."); setForegroundColor(255, 255, 255); setBackgroundColor(0,0,0); //close(); setTool(19); waitForUser("Delete bad pixels"); run("Create Selection"); // Analyse Image1 with mask1 selectWindow(titre_image1); run("Restore Selection"); run("Measure"); mycounter +=1; mycounterarray[mycounter] = nResults; // Add a counter to identify the right result line (1 to nResults) // Analyse Image2 with mask1 selectWindow(titre_image2); run("Restore Selection"); run("Measure"); mycounter +=1; mycounterarray[mycounter] = nResults; // Add a counter to identify the right result line (1 to nResults) // ANALYSE BOTH IMAGES WITH IMAGE2 MASK // Create mask2 from Image2 selectWindow(titre_image2+"_mask2"); run("8-bit"); run("Threshold..."); //setAutoThreshold("Default dark"); setThreshold(25, 255); waitForUser("Adjust threshold"); run("Convert to Mask"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); // Clean the image for mask1 //run("Color Picker..."); setForegroundColor(255, 255, 255); setBackgroundColor(0,0,0); //close(); setTool(19); waitForUser("Delete bad pixels"); run("Create Selection"); // Analyse Image1 with mask2 selectWindow(titre_image1); run("Restore Selection"); run("Set Measurements...", "area mean integrated display redirect=None decimal=1"); run("Measure"); mycounter +=1; mycounterarray[mycounter] = nResults; // Add a counter to identify the right result line (1 to nResults) // Analyse Image2 with mask2 selectWindow(titre_image2); run("Restore Selection"); run("Set Measurements...", "area mean integrated display redirect=None decimal=1"); run("Measure"); mycounter +=1; mycounterarray[mycounter] = nResults; // Add a counter to identify the right result line (1 to nResults) Dialog.create("Continue ?"); Dialog.addCheckbox("NO, save the results", false); Dialog.show() saveresult = Dialog.getCheckbox(); if (saveresult == true) {mainwhile= 0;} } // end mainwhile // SAVE THE RESULTS namefile = "analyse"; myfile = mypath + namefile +".txt"; overwrite = false; namefile2 = ""; while ( File.exists(myfile) ) { Dialog.create("ANALYSE FILE"); Dialog.addString("analyse.txt file already exists, other name : ", namefile ); Dialog.addCheckbox("Or overwrite file ? ", false); Dialog.show(); namefile2 = Dialog.getString(); overwrite = Dialog.getCheckbox(); if (overwrite == true) {myfile = "";} else {myfile = mypath + namefile2;} } if (overwrite == true) myfile = mypath + namefile; myname= newArray(nResults); myarea= newArray(nResults); mymean= newArray(nResults); mytemp = ""; for (i=0; i