# Sum of areas with the command OR (Combine)

#1

Hi everyone!
I notice that if I select some areas in ImageJ (NOT overlapped), press OR (Combine) and Measure, the value given (that should be the sum of the areas) is not the same as if I sum the single areas with the calculator. Does someone know why this is happening?
Thank you

#2

Good day,

Here is a test image with three ROIs, where the third ROI is the combination of the previous two ROIs.

TestImage.zip (646 Bytes)

Unzip the above zip-archive and open the image in ImageJ. Then run the following ImageJ-macro:

``````run("Set Measurements...", "area redirect=None decimal=3");
run("To ROI Manager");
roiManager("Multi Measure");
exit();
``````

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it.

Regards

Herbie

#3

In my spare time, Iâ€™m working on this question out of interest and found a similar thing when working with a fully intersecting freehand selection and a circle ROI.

To reproduce, make an image, draw a freehand closed shape, add to ROI manager, draw a circle selection inside the first ROI.
If you measure the freehand ROI area alone then after combining the two, the latter is bigger!

#4

Good day Dave,

Here is a test image with three ROIs, where the third ROI is the combination of the previous two fully overlapping ROIs.

TestImage2.zip (630 Bytes)

Unzip the above zip-archive and open the image in ImageJ. Then run the ImageJ-macro posted in my previous contribution.

Regards

Herbie

#5

HI @Herbie, thanks for the example image, but that has two rectangular selections. I know it works with geometric shapes, but my example was specifically with a freehand selection containing a circle.

#6

You are right and this may be a case for those who did the coding.
Please check the code and contact the coder.

Regards

Herbie

#7

I believe the difference that youâ€™re seeing is explainable by the difference between polygon type ROIs (such as `ij.gui.FreehandRoi` and `ij.gui.PolygonRoi`) and rastered ROIs (i.e. `ij.gui.ShapeRoi`) that are the result of combining. For polygons, the area can be calculated more â€śexactlyâ€ť by taking into account the exact edges, whereas I believe the area of rastered ROIs is essentially measured by counting the pixels inside the ROI. (Disclaimer: I didnâ€™t check the source code, so I might be wrong.)

#8

I can confirm that this (quoted bit above) is the case, but are you saying that after an OR operation, the `ij.gui.FreehandRoi` becomes an `ij.gui.ShapeRoi` object?

#9

A look at the code may help â€¦
(I had a look at it yesterday and I faintly remember that this is the case.)

Regards

Herbie

#10

Good day Jan,

in the discussed case, i.e. if one ROI is completely included by another, the problem of incorrect area measurements can be avoided if this condition (inclusion) is tested:
If total inclusion is detected, ignore the included ROI area.

In general however, I think the present approach should be chnanged in the long run to provide accurate area measurements for all possible situations.

Regards

Herbie