//Please set following parameters: //(Remeber to save changes) //Area of the smallest region of interest (cell) [number in pixel^2 e.g 18000] // starting value for calibration = 0; the_smallest_cell = 0; //Area of the biggest region of interest (cell) [number in pixel^2 e.g 100000] //starting value for calibration = "infinity"; the_biggest_cell = "infinity"; /////////////////////////////////////////////////////Do not change code below this line//////////////////////////////////////////////////////////////////////////////// run("Set Measurements...", "area perimeter circularity display redirect=None decimal=3"); macro_path = getInfo("macro.filepath"); choice = "Analyze next image"; while(choice == "Analyze next image" ){ print("macro has started"); run("Close All"); run("Open..."); path=getDirectory("image"); newfolder = path+substring(path,lengthOf(path)-1,lengthOf(path))+"results"+substring(path,lengthOf(path)-1,lengthOf(path)); name=getTitle; selectWindow(name); run("Set Scale...", "distance=0"); if (roiManager("Count") > 0){ roiManager("Select", 0); run("Select All"); roiManager("Deselect"); roiManager("Delete"); } selectWindow(name); run("Extend Image Borders", "left=10 right=10 top=10 bottom=10 fill=Black"); extented=getTitle; selectWindow(name); close(); closing = extented+"-Closing"; run("Morphological Filters", "operation=Closing element=Disk radius=9"); iterator=0; while(!isOpen(closing)){ wait(500); iterator++; print(iterator); } watershed=closing+"-watershed-lines"; run("Morphological Segmentation"); iterator=0; while(!isOpen("Morphological Segmentation")){ wait(500); iterator++; print(iterator); } selectWindow("Morphological Segmentation"); //setTool("point"); selectWindow("Morphological Segmentation"); call("inra.ijpb.plugins.MorphologicalSegmentation.setDisplayFormat", "Watershed lines"); selectWindow("Morphological Segmentation"); call("inra.ijpb.plugins.MorphologicalSegmentation.segment", "tolerance=8.0", "calculateDams=true", "connectivity=4"); selectWindow("Morphological Segmentation"); iterator = 0; while(!isOpen(watershed)){ wait(500); iterator++; print(iterator); selectWindow("Morphological Segmentation"); call("inra.ijpb.plugins.MorphologicalSegmentation.createResultImage"); wait(500); selectWindow(closing); close(); } selectWindow("Morphological Segmentation"); close(); selectWindow(watershed); run("Dilate"); run("Invert"); run("Analyze Particles...", "size=the_smallest_cell-the_biggest_cell circularity=0.01-1.00 show=Nothing display exclude clear add"); selectWindow(watershed); close(); selectWindow(extented); selectWindow("Log"); run("Close"); roiManager("Show None"); roiManager("Show All"); run("Brightness/Contrast..."); setMinAndMax(0, 50); if (roiManager("Count") > 0){ selectWindow(extented); if (!File.exists(newfolder)){ File.makeDirectory(newfolder); } run("From ROI Manager"); saveAs("Tiff", newfolder+extented); selectWindow("Results"); } else { waitForUser("No ROI found, adjust cell size threshold values"); } macro_path = getInfo("macro.filepath"); String.copyResults(); Dialog.create("Work finished."); Dialog.addMessage("If you intend to modify selections, now its the time"); Dialog.addMessage("Your results have been copied to clipborad"); Dialog.addChoice("What would you do next?:", newArray("Analyze next image", "Set cell size boundaries", "Modify selections or brightness","Nothing - Close this window", "Quit")); Dialog.show(); choice = Dialog.getChoice(); if(choice == "Set cell size boundaries"){ run("Edit...", "open=["+macro_path+"]"); run("Clear Results"); selectWindow(extented+".tif"); selectWindow("ROI Manager"); waitForUser("Measure area of few smallest and largest cells in the image"); } while(choice == "Modify selections or brightness"){ selectWindow("B&C"); selectWindow("ROI Manager"); waitForUser("Modify selections or brightness"); run("Clear Results"); if (roiManager("Count") > 0){ roiManager("Select", 0); roiManager("Deselect"); roiManager("Measure"); selectWindow(extented+".tif"); if (!File.exists(newfolder)){ File.makeDirectory(newfolder); } run("From ROI Manager"); saveAs("Tiff", newfolder+extented); selectWindow("Results"); } else { waitForUser("No ROI found, adjust cell size threshold values"); } String.copyResults(); Dialog.create("Work finished."); Dialog.addMessage("If you intend to modify selections, now its the time"); Dialog.addMessage("Your results have been copied to clipborad"); Dialog.addChoice("What would you do next?:", newArray("Analyze next image", "Set cell size boundaries", "Modify selections or brightness","Nothing - Close this window", "Quit")); Dialog.show(); choice = Dialog.getChoice(); } if(choice == "Quit"){ run("Close All"); selectWindow("ROI Manager"); run("Close"); selectWindow("B&C"); run("Close"); selectWindow("Results"); run("Close"); } }