/* This is the second draft of the macro. Needs a lot more documentation. v101 only marked the image. v102 adds reporting to the Log window v103 adds n=1 and fixes n=2 (framework for n=0 need to be added later); removes location reported in printed list To use, user chooses the Multi-point Tool to count objects. setTool("multipoint"); */ var tab = " \t "; var counter = 0; var fontSize = 18; //==================================================== macro "Reset Counter" { counter = 0; print("title \t #measurement \t count \t Xlocation \t Ylocation"); } //==================================================== macro "count, mark and log [q]" { if (selectionType != 10) exit("requires a few points clicked"); counter++; startcount = nResults(); run("Measure"); endcount = nResults(); counted = endcount - startcount; if (counted > 2) { run("Convex Hull"); run("Fit Spline"); // optional } color = ""; a = newArray(3); for (i=0; i<3; i++) { a[i] = round (180+(random()*(256-180))); color = color + toHex(a[i]); } setColor(a[0], a[1], a[2]); if (counted > 2) Overlay.addSelection(color); run("Set Measurements...", "centroid redirect=None decimal=0"); run("Measure"); x = getResult("X", nResults()-1); y = getResult("Y", nResults()-1); toUnscaled(x, y); radius = 20; // change for bigger or smaller circle if (counted == 2) { // convex hull does not work for 2 points, so customize marking here x = (getResult("X", endcount-1) + getResult("X", endcount-2)) / 2; y = (getResult("Y", endcount-1) + getResult("Y", endcount-2)) / 2; toUnscaled(x, y); makeOval(x-radius, y-radius, radius*2, radius*2); Overlay.addSelection(color); } if (counted == 1) { // put a circle instead of convex hull around the counted object makeOval(x-radius, y-radius, radius*2, radius*2); Overlay.addSelection(color); } // Border on number setFont("SansSerif", fontSize+3); setColor(0,0,0); Overlay.drawString("#"+counter+": "+counted, x-fontSize-fontSize-1, y+3); // number same color as ROI setColor(a[0], a[1], a[2]); setFont("SansSerif", fontSize); Overlay.drawString("#"+counter+": "+counted, x-fontSize-fontSize, y); //Overlay.addSelection(color); run("Select None"); //print(getTitle() + tab + counter + tab + counted + tab + round(x) + tab + round(y)); print(getTitle() + tab + counter + tab + counted); // selectWindow("Log"); }