Automatically adding circles around user-drawn points, then calculate the area

I want to analyze scans of diseased tissues (stored as TIFF, 1200dpi, 24-bits color). The tissues are brownish/greyish with varying tones and some damages. A colleague tried to analyze it automatically (using thresholds and shape analysis) but couldn’t, as there is no single threshold between background color and symptoms. So I’m down to do it manually, at least at the beginning. What I want is: the proportion of the surface which is circled, in the example below (the steps are explained below, too).

  1. using ObjectJ, I add a blue rectangle around the symptomatic area, on a layer (not on the original image).
  2. I add dots on certain symptoms, and on the same layer. For instance, I add 5 red crosses (red crosses to be clearly different from the image).
  3. Now I want to automatically add circles around each red cross. Circles are of known, user-defined, diameter. ObjectJ gives me XPos and YPos for each red cross, so this may be a way to do it; alternatively, an automatic detection of the red crosses might work.
  4. When the circles are drawn, I want to calculate the proportion of pixels that are “under the circles” (covered with circles). I guess it won’t be that complicated, using ObjectJ or base ImageJ, though I’m not sure how to do it. Since the overlapping areas shouldn’t be counted twice, ObjectJ may not work (plus the Area calculation works for object of type “polygon”). And since the calculation is to be done on an ObjectJ-layer rather than the image itself, I’m not sure base-ImageJ can do it.

EDIT: some progress
I found a way to add the circles around the points. I dropped ObjectJ and used the ROI manager instead, combined with a macro (as explained here).

The macro output are circles drawn around the points, plus some coordinates stored in the ROI manager (6 coordinates for 3 points, I guess it is normal for circles?). One question remains: now that the circles are drawn (and some coordinates stored), how to calculate the circles area (without counting twice the overlapping parts)?

I have tried to use the ROI manager: “Measure”. Alas, it yields the area of each circle separetely, which is of little value since 1)I know the circles diameters (defined in the macro) and 2)the overlapping areas are still counted twice. See the image below.

EDIT: area calculation
Combining macro lines from the link above and imagejan’s answer made it! See the example here:

The complete code for the macro is:

getSelectionCoordinates(xpoints, ypoints);
roiManager("Delete");
radius=6;
for (i=0; i<lengthOf(xpoints); i++) {
  makeOval(xpoints[i]-radius, ypoints[i]-radius, 2*radius, 2*radius);
  roiManager("Add");
}
roiManager("Show All");
roiManager("Deselect");
roiManager("Combine");
run("Set Measurements...", "area redirect=None");
run("Measure");

Note that some lines may be inefficient/redundant, as I’m very much new at this (who said cargo-cult programming?). Also note the macro seems to be running for a while after the calculation is done, either because of an unsufficient RAM or because the macro lacks a “break” or “end” command. In any case it works, the combined area of the circles is slightly off-centered but the area in itself is correct.

Thanks again for the help!

K.

1 Like

How about combining all circle selections into a single composite selection using the ROI Manager’s More >> OR (Combine) command? Here’s a macro that illustrates this:

roiManager("Deselect");
roiManager("Combine");
run("Set Measurements...", "area redirect=None");
run("Measure");
2 Likes

Many thanks! It works like a charm. I edited the post to show the code and an example.