Login  Register

Re: Only count cells that contain nuclei (or holes in the binarized image)

Posted by kirbyfloss on Oct 15, 2015; 7:11pm
URL: http://imagej.273.s1.nabble.com/Only-count-cells-that-contain-nuclei-or-holes-in-the-binarized-image-tp5014654p5014655.html

Thanks so much! I tested the code and it runs perfectly - the solution of using include/exclude to distinguish the two populations is great.

Just one more thing, is it possible to show outlines for just the particles that contained holes? So I know which particles were counted.

This is the macro I have set up so far with the helpful suggestions of the community:
// run on the original image
run("Duplicate...", "title=workingCopy.png");
selectWindow("workingCopy.png");
run("Colour Deconvolution", "vectors=[H&E 2]");
selectWindow("workingCopy.png-(Colour_2)");
setAutoThreshold("Minimum");
run("Convert to Mask");
run("Set Measurements...", "area redirect=None decimal=5");
run("Analyze Particles...", "size=100-Infinity display exclude clear");
noHoles = newArray(nResults);
holes = newArray(nResults);
for (i = 0; i < nResults; i++) noHoles[i] = getResult("Area", i);
run("Analyze Particles...", "size=100-Infinity display exclude clear include");
print("Particles Containing Holes");
for (i = 0; i < nResults; i++) {
        n = i+1;
        holes[i] = getResult("Area", i);
        a = holes[i] - noHoles[i];
        if(a > 0) print(n + " area of hole = " + a);
}