macro "AggregationAssay_MakeMask" { // set up dialog list = getList("image.titles"); Dialog.createNonBlocking("Make Mask From Image"); Dialog.addChoice("Select Image", list) Dialog.addNumber("Threshold Value",0); Dialog.addToSameRow(); Dialog.addCheckbox("Determine Threshold from Image", true); Dialog.addNumber("Min Cluster Size:", 0); Dialog.addToSameRow(); Dialog.addCheckbox("Determine Cluster Params from Histogram", true); Dialog.addNumber("Max Cluster Size:", -1); Dialog.show(); // get the selected params from dialog imagewindow = Dialog.getChoice(); selectWindow(imagewindow); imID = getImageID(); threshvaluestring = Dialog.getNumber(); threshimagecheck = Dialog.getCheckbox(); minclustersize = Dialog.getNumber(); clustersizecheck = Dialog.getCheckbox(); maxclustersize = Dialog.getNumber(); run("Threshold..."); // open Threshold tool selectImage(imID); //make sure we still have the same image // if user decides: threshold open image to threshold, otherwise set to be value in box getStatistics(area, mean, lower, upper, std, histogram); if (threshimagecheck || threshvaluestring<=0){ setAutoThreshold("MaxEntropy dark no-reset"); title = "Determine Threshold"; msg = "Use the \"Threshold\" tool to\nadjust the threshold, then click \"OK\"."; waitForUser(title, msg); getThreshold(lower, upper); //setThreshold(lower, upper); } else { lower = threshvaluestring; setThreshold(lower, upper); } if (lower==-1){ exit("Threshold was not set"); } // now determine if min or max clustersize is set if (clustersizecheck||minclustersize<=0 ||maxclustersize<-1){ runMacro("makeClusterHistogram"); Dialog.createNonBlocking("Cluster Params"); Dialog.addNumber("Min Cluster Size:", 0); Dialog.addNumber("Max Cluster Size (-1 is Inf):", -1); Dialog.show(); minclustersize = Dialog.getNumber(); maxclustersize = Dialog.getNumber(); } if (maxclustersize==-1){ maxclustersize = "Infinity"; } wait(0.5); close("Histogram of Cluster Sizes"); selectImage(imID); run("Analyze Particles...","size="+minclustersize+"-"+maxclustersize+"display clear add"); runMacro("makeMaskFromROIs"); selectWindow("Mask"); rename(imagewindow+"_MASK"); roiManager("Show None"); selectImage(imID); roiManager("Show None"); roiManager("Show All"); roiManager("Show None"); selectWindow(imagewindow); selectWindow(imagewindow+"_MASK"); run("Enhance Contrast", "saturated=0.35"); } // end of macro macro "AggregationAssay_CalculateOverlap"{ // set up dialog list = getList("image.titles"); Dialog.createNonBlocking("Calculate Overlap Area Fraction"); Dialog.addChoice("Select Channel 1 Image", list); Dialog.addChoice("Select Channel 2 Image", list); Dialog.show(); savedir = getDirectory("Choose a Directory to save results"); // get user selections ch1_window = Dialog.getChoice(); selectWindow(ch1_window); ch1ID = getImageID(); ch2_window = Dialog.getChoice(); selectWindow(ch2_window); ch2ID = getImageID(); print(ch1_window); print(ch2_window); // make overlap image imageCalculator("AND create", ch1_window,ch2_window); ch1_windowname = removeextension(ch1_window); ch2_windowname = removeextension(ch2_window); resultname = "Overlap of "+ch1_windowname+"_and_"+ch2_windowname; rename(resultname); run("Clear Results"); // ---------now calculate values for each imgae.... // ----overlap image // get area in total # pixels run("Set Measurements...", "integrated redirect=None decimal=3"); selectWindow(resultname); run("Select All"); run("Measure"); overlap_areaval = getResult("IntDen", 0); overlap_total = overlap_areaval/255; //---get total pixels totpixname = "totalpixels"; imageCalculator("OR create", ch1_window,ch2_window); print(ch1_window); print(ch2_window); rename(totpixname); selectWindow(totpixname); run("Set Measurements...", "integrated redirect=None decimal=3"); run("Select All"); run("Measure"); totpix_areaval = getResult("IntDen", 1); totpix_total = totpix_areaval/255; print(totpix_total); close(totpixname); // ----channel 1 // get area in total # pixels run("Set Measurements...", "integrated redirect=None decimal=3"); selectWindow(ch1_window); run("Select All"); run("Measure"); ch1_areaval = getResult("IntDen", 2); ch1_total = ch1_areaval/255; // ----channel 2 // get area in total # pixels selectWindow(ch2_window); run("Set Measurements...", "integrated redirect=None decimal=3"); run("Select All"); run("Measure"); ch2_areaval = getResult("IntDen", 3); ch2_total = ch2_areaval/255; //-----now make results table to save tablename = "Overlap of "+ch1_window+"_AND_"+ch2_window; Table.create(tablename); Table.setColumn("Overlap Fraction", newArray(1)); Table.setColumn("Overlap Area", newArray(1)); Table.setColumn("Total Area", newArray(1)); Table.setColumn("Channel1 Area", newArray(1)); Table.setColumn("Channel2 Area", newArray(1)); Table.set("Overlap Fraction", 0, overlap_total/totpix_total); Table.set("Overlap Area", 0, overlap_total); Table.set("Total Area", 0, totpix_total); Table.set("Channel1 Area", 0, ch1_total); Table.set("Channel2 Area", 0, ch2_total); //save image and table selectWindow(resultname); img_title = getTitle(); saveAs("Tiff",savedir+img_title); selectWindow(tablename); saveAs("Results", savedir+img_title+"_Results.xls"); //------ get info about each cluster individually //---ch1 selectWindow(ch1_window); saveAs("Tiff",savedir+ch1_window); run("Set Measurements...", "area redirect=None decimal=3"); run("Analyze Particles...", "clear add"); roiManager("Save", savedir+ch1_windowname+"_RoiSet.zip"); dest_filename = ch1_windowname+"_clusersizes.xls"; fullpath = savedir + dest_filename; saveAs("Measurements", fullpath); roiManager("Show None"); roiManager("Delete"); //---ch2 selectWindow(ch2_window); saveAs("Tiff",savedir+ch2_window); run("Set Measurements...", "area redirect=None decimal=3"); run("Analyze Particles...", "clear add"); roiManager("Save", savedir+ch2_windowname+"_RoiSet.zip"); dest_filename = ch2_windowname+"_clusersizes.xls"; fullpath = savedir + dest_filename; saveAs("Measurements", fullpath); roiManager("Show None"); roiManager("Delete"); selectWindow("ROI Manager"); run("Close"); function removeextension(inputname) { title = replace(inputname, ".", "-"); return title; } }