How to mark objects that are touching the edge to be able to treat them differently in later analysis

StackOverflow https://stackoverflow.com/questions/21525714

Question

I have one challenge for all advanced ImageJ users and developers. In my macro (see macro below) I would like to insert the following task:

I am analyzing particles in ROI and those particles/objects that are touching the edge of the picture, I would like to mark with “*” in a special column in the result table. Probable if sentence will do the task but I am a pure beginner of macros and really need some tips.

(I am aware of the option “exclude on edges” but I need areas of those objects to calculate the sum of all areas on the image; but I need to exclude them to calculate average area)

id = getImageID();
for (i=0 ; i<roiManager("count"); i++) {
    selectImage(id);
    roiManager("select", i);
    run("Analyze Particles...", "size=0.008-Infinity circularity=0.00-1.00 show=Outlines clear");
}

Your help is appreciated, Jernej

Was it helpful?

Solution

Just process the edge-touching and interior particles separately. You can get an image with only the edge-touching particles by XORing the image with all particles and the image with touching particles excluded.

This macro creates three images: one with all particles, one without edge-touching particles and one with only the edge-touching particles:

run("Blobs (25K)");
setThreshold(126, 255);
run("Analyze Particles...", "size=0.01-Infinity circularity=0.00-1.00 show=Masks clear");
rename("all");
run("Analyze Particles...", "size=0.01-Infinity circularity=0.00-1.00 show=Masks exclude clear");
rename("not touching");
imageCalculator("XOR create", "all","not touching");
rename("touching");

You can then analyze each of them separately and add a marker:

selectWindow("touching");
run("Analyze Particles...", "size=0.01-Infinity circularity=0.00-1.00 show=Outlines display clear in_situ");
for(row = 0; row < nResults; row++){
    setResult("touching", row, "*");
}

selectWindow("not touching");
run("Analyze Particles...", "size=0.01-Infinity circularity=0.00-1.00 show=Outlines display in_situ");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top