// ********************************************************************** // declare global variable //var mypath="c:/"; // ********************************************************************** // "0histo_arteries" // Macro for measuring external (ex: adventis) and internal (ex: intima) perimeter and area of a ring-like structure // Fabrice Duprat august 2011, LAST MODIFICATION: 3/2/2014 // INPUT: color images with .tif extension // BEWARE the scale calculation is made for the Leica DMD 108 histology microscope (you can change the values of myscale) // OUTPUT: result file (default: analyse.txt) with image names, area and perimeter for both external and internal circles // image files (name_ANAL) with the analysis ROI // // ******************************************************************************** macro "histo_arteries" { run("Line Width...", "line=3"); mainwhile=1; run("Colors...", "foreground=black background=white selection=red"); while (mainwhile == 1) { run("Close All"); // Close all images (the plugin needs to be installed) // ADJUST THE RIGHT SCALE zoom = newArray("x4","x10","x20","x40","x63"); Dialog.create("Choose objective "); Dialog.addChoice("Objective", zoom, "x4") Dialog.addMessage("WARNING, Results table is going to be deleted !"); Dialog.addMessage("Delete the Log window if starting a new analysis serie."); Dialog.show(); choice = Dialog.getChoice(); myscale=0; run("Set Measurements...", "area perimeter display redirect=None decimal=3"); run("Clear Results"); if (choice=="x4") // values in µm for 1000 pixels {myscale=630;} else if (choice=="x10") {myscale=1580;} else if (choice=="x20") {myscale=3180;} else if (choice=="x40") {myscale=6360;} else if (choice=="x63") {myscale=10042;} // Print the headers of the log window print("File name\t External area\t External perimeter\t Internal area\t Internal perimeter"); // START LOOPING FOR EACH IMAGE while (myscale!=0) { while (roiManager("count")!= 0) // Empty the ROI manager list {roiManager("Delete");} image1 = File.openDialog("CHOOSE image to analyse"); open(image1); titre_image = getTitle(); mypath = getDirectory("image"); nb = indexOf(image1, ".tif"); nom_image = substring( image1, 0, nb ); //Get rid of .tif extension in the name run("Duplicate...", "title=TEMP"); rename(titre_image+"_original"); // Create a copy of the original image called nameofimage_original // Split selected image in 3 colors (binary images) to be used for mask creation selectWindow(titre_image); run("RGB Split"); selectWindow(titre_image+" (blue)"); close(); // ADVENTIS MEASUREMENT (on green image) selectWindow(titre_image+" (green)"); rename(titre_image); run("Threshold..."); setThreshold(0, 160); waitForUser("Adjust threshold for EXTERNAL PART without background"); run("Convert to Mask"); run("Make Binary"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Fill Holes"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Analyze Particles...", "size=20000-Infinity circularity=0.00-1.00 show=[Overlay Outlines] exclude add"); // Create automatic ROI for adventis (generates a hidden unwanted line in result window) selectWindow(titre_image+"_original"); roiManager("Select", 0); run("Convex Hull"); // Creates the adventis ROI if (choice=="x4") {run("In");} setTool("polygon"); waitForUser("CORRECT the selection:\n- by moving the points\n- delete points with ALT\n- add points with SHIFT\nCREATE A NEW SELECTION:\n- click on the image to deselect\n- make a new selection with Polygon selection tool"); run("Measure"); // Add the external part measurement to result window area_adventis = getResult("Area", nResults-1); // Get the last measurement perim_adventis = getResult("Perim.", nResults-1); run("Add to Manager"); // Delete original ROI and keep the modified one roiManager("Select", 0); roiManager("Delete"); // INTIMA MEASUREMENT (on red image) selectWindow(titre_image+" (red)"); run("Threshold..."); setThreshold(0, 160); waitForUser("ADJUST threshold to select a maximum of INTERNAL PART (intima)"); run("Convert to Mask"); run("Make Binary"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); setTool("wand"); waitForUser("CLICK inside the vessel"); run("Convex Hull"); // Creates the intima ROI selectWindow(titre_image+"_original"); run("Restore Selection"); setTool("polygon"); waitForUser("CORRECT the selection:\n- by moving the points\n- delete points with ALT\n- add points with SHIFT\nCREATE A NEW SELECTION:\n- click on the image to deselect\n- make a new selection with Polygon selection tool"); run("Measure"); // Add the internal part measurement to result window area_intima= getResult("Area", nResults-1); // Get the last measurement perim_intima= getResult("Perim.", nResults-1); updateResults(); run("Add to Manager"); // Write in Log window the formated results for the current image print( titre_image + "\t" + toString(area_adventis) + "\t" + toString(perim_adventis) + "\t" + toString(area_intima) + "\t" + toString(perim_intima) ); // Close open windows, save a copy of the analysed image with the 2 ROI selectWindow(titre_image); close(); selectWindow(titre_image+" (red)"); close(); selectWindow(titre_image+"_original"); roiManager("Select", 0); run("Draw"); roiManager("Select", 1); run("Draw"); nom_image = nom_image + "_ANAL.tif"; saveAs("Tiff", nom_image); Dialog.create("CONTINUE"); Dialog.addMessage("An image with the 2 ROI has been saved in :"); Dialog.addMessage("< " + nom_image + " >"); Dialog.addMessage("Measurements have been added to Log window."); Dialog.addMessage(" "); Dialog.addMessage("CONTINUE ANALYSIS ?"); Dialog.addCheckbox("NO, save the results", false); Dialog.show() saveresult = Dialog.getCheckbox(); if (saveresult == true) { myscale = 0; } else { run("Close All"); } } // end while myscale (image loop) // SAVE THE RESULTS namefile = "analyse"; myfile = mypath + namefile +".txt"; overwrite = false; filexist = File.exists(myfile); // Check if file name already exist while ( (filexist== 1) && (overwrite == false) ) { // This name already exist for analyse file Dialog.create("ANALYSE FILE"); Dialog.addString(namefile + ".txt file already exists, other name : ", namefile ); Dialog.addCheckbox("Or overwrite file ? ", false); Dialog.show(); namefile = Dialog.getString(); overwrite = Dialog.getCheckbox(); myfile = mypath + namefile + ".txt"; filexist = File.exists(myfile); } selectWindow("Log"); saveAs("Text", myfile); mainwhile = 0; waitForUser("The formatted results have been saved in < " + myfile + " >"); } // end main while }