/* ImageJ Macro to count the number of uniqe objects touching the each object Uniqueness is guaranteed by G. Landini's binary labeling plugin (part of "Morphology" package Uses histogram macro functions so that no additional particle analysis is required. Assumes that touching objects have been separated by one pixel. 5/31/2016 10:50 AM Peter J. Lee (NHMFL) */ start = getTime(); // start timer after last requester for debugging setBatchMode(true); saveSettings(); /* To restore settings at the end */ run("Options...", "iterations=1 count=1 black do=Nothing"); //The binary count setting is set to "1" for consistent outlines TitleOriginalBinaryImage = getTitle(); if (roiManager("count")==0) restoreExit("An existing ROI set must be loaded into the ROI manager."); imageWidth = getWidth(); imageHeight = getHeight(); if (is("binary")==0) restoreExit("Needs to work from binary image."); // Make sure white objects on black background for consistency if (((getPixel(0, 0))!=0 || (getPixel(0, 1))!=0 || (getPixel(1, 0))!=0 || (getPixel(1, 1))!=0)) run("Invert"); // Sometimes the outline procedure will leave a pixel border around the outside - this next step checks for this. // i.e. the corner 4 pixesl shoul now be all black, if not, we have a "border issue". if (((getPixel(0, 0))+(getPixel(0, 1))+(getPixel(1, 0))+(getPixel(1, 1))) != 0 ) restoreExit("Border Issue"); run("BinaryLabel", "white"); //requires G. Landini Morphology plugins: 8-way connected TitleGrayLabeledImage = getTitle(); roiOriginalCount = roiManager("count"); showStatus("Looping through all " + roiOriginalCount + " objects for touching neighbors . . ."); for (i=0 ; i