pathwayGran= pathwayTA= //where to save dir = getDirectory("Choose a Directory "); setBatchMode(true); //doesn't open image, but processes them without opening - much faster count = 0; countFiles(dir); n = 0; processFiles(dir); //print(count+" files processed"); function countFiles(dir) { list = getFileList(dir); for (i=0; i=0 && type <=10) { run("Enlarge...", "enlarge=-5 pixel"); run("Enlarge...", "enlarge=150 pixel"); run("Enlarge...", "enlarge=-120 pixel"); run("Invert"); run("Select None"); run("Create Selection"); roiManager("Add"); } //Stage 2 - Granuloma ROI selectWindow("Gran1"); run("Auto Threshold", "method=Otsu"); run("Create Selection"); type = selectionType(); if (type==-1) { //print("no selection"); makeRectangle(0, 0, 12000, 12000); setBackgroundColor(0, 0, 0); run("Clear", "slice"); } else if (type>=0 && type <=10) { run("Enlarge...", "enlarge=80 pixel"); run("Enlarge...", "enlarge=-120 pixel"); run("Enlarge...", "enlarge=120 pixel"); roiManager("Add"); } //Stage 3 - Granuloma ROI selectWindow("Gran2"); setAutoThreshold("Li"); //change with Stage 1 run("Convert to Mask"); run("Create Selection"); type = selectionType(); if (type==-1) { //print("no selection"); makeRectangle(0, 0, 12000, 12000); setBackgroundColor(0, 0, 0); run("Clear", "slice"); } else if (type>=0 && type <=10) { roiManager("Add"); } selectWindow("Gran3"); roiManager("Select", 0); run("Clear Outside"); roiManager("Select", 1); run("Clear Outside"); roiManager("Select", 2); run("Clear Outside"); run("Select None"); saveAs("TIFF", pathwayGran+"Gran_"+img+"_Granarea.tif"); for (i=(roiManager("count")-1); i>=0; i--) { roiManager("select", i); // select the ROI roiManager("Delete"); // delete the ROI } //setAutoThreshold("Huang"); run("Select None"); setThreshold(1, 255); setOption("BlackBackground", true); run("Convert to Mask"); run("Fill Holes"); run("Create Selection"); type = selectionType(); if (type==-1) { //print("no selection"); makeRectangle(0, 0, 12000, 12000); setBackgroundColor(0, 0, 0); run("Clear", "slice"); } else if (type>=0 && type <=10) { run("Enlarge...", "enlarge=-50 pixel"); run("Enlarge...", "enlarge=5 pixel"); roiManager("Add"); // Isolate TB signal selectWindow("TB1"); run("8-bit"); run("Median...", "radius=1"); run("Duplicate...", "title=TB2"); imageCalculator("Multiply create 32-bit", "TB1","TB2"); run("8-bit"); rename("Img_Sq"); run("Duplicate...", "title=Img_Sq2"); run("Remove Outliers", "block_radius_x=100 block_radius_y=100 standard_deviations=1.50"); imageCalculator("Subtract create", "Img_Sq","Img_Sq2"); // Clear outside granuloma ROI run("8-bit"); roiManager("Select", 0); run("Clear Outside"); } //waitForUser("continue?"); saveAs("TIFF", pathwayTA+"TB_"+img+"_TBarea.tif"); for (i=(roiManager("count")-1); i>=0; i--) { roiManager("select", i); // select the ROI roiManager("Delete"); // delete the ROI } run("Close All"); } } // RenyiEntropy autothreshold on data produced - for Imaris 3D input