//Michael Cammer 27 Feb 2004 //cammer@aecom.yu.edu michael@coxcammer.com //The purpose of these macros is to measure the shortest distance from a set of particles to a polygon edge. //The macro uses a brute force approach: calculate the distance from each particle to every point on the perimeter. //So the macro could be used to measure to a linear edge, but it is an inefficent method. //How to use it: //The user opens the image with particles. // The user traces along the edge of the shape that the particles are contained in. // The user runs step1. // Adjusts threshold. // runs step2. // looks at results in Log window. //GLOBAL VARIABLES // none macro 'step1 createmask and threshold [F3]' { requires('1.32a'); if ((selectionType() > 3) || (selectionType() < 1)) exit('no polygon selection -- rectangles are not considered polygons!'); original = getImageID(); while (isOpen('OutlineMask')) {selectWindow("OutlineMask"); run("Close");} run("Create Mask"); run("Rename...", "title=OutlineMask"); selectImage(original); run("Threshold..."); } macro 'step2 count [F4]' { requires('1.32a'); if (! isOpen('OutlineMask')) exit('make the mask in step1 first'); //original = getImageID(); run("Threshold", "thresholded remaining black"); //selectImage(original); title = getTitle(); run("Image Calculator...", "image1=OutlineMask operation=XOR image2="+title+" create"); run("Image Calculator...", "image1=OutlineMask operation=AND image2='Result of OutlineMask' "); selectWindow("OutlineMask"); run("Restore Selection"); run("Erode"); // dumps four pixel or fewer spots; could be done instead with minimum=## run("Dilate"); doTheMath(); selectWindow("Result of OutlineMask"); run("Close"); } function doTheMath() { getSelectionCoordinates(edgex, edgey); run("Set Measurements...", " centroid redirect=None decimal=0"); run("Analyze Particles...", "minimum=1 maximum=999999 bins=2 show=Nothing display clear "); distances = newArray(nResults()); for (a=0;a maxdistance) maxdistance = distances[a]; } // for a //put in bins binsize = 10; bins = newArray(floor(maxdistance/binsize)+2); // the "+2" makes sure the last bin always has 0 for (a=0;a