Measuring black area in ROI

Hello,

I am trying to measure the black area within this selection. I tried using the ‘area fraction’ in the set measurements window, but the measurement this gives me (around 44,000) is different from when I select the black area with the wand tool and measure it manually (around 56,000). The reason I want to measure the black area within the selection is because I am trying to create a macro. What am I doing wrong?

Thanks,
Robyn

Do you mean the area? By definition the area fraction is:

Area fraction For thresholded images is the percentage of pixels in the image or selection that have been highlighted in red using Image▷Adjust▷Threshold… [T]↑. For non-thresholded images is the percentage of non-zero pixels. Uses the heading %Area .

Do you use the Particle Analyzer as the other measurement method (is the include holes option deselected)?

The wand tool can also be in different modes. Please read the following threads:

http://imagej.1557.x6.nabble.com/Analyze-particles-what-is-the-wand-tool-mode-setting-td5002540.html

http://imagej.1557.x6.nabble.com/Why-is-Particle-Analyzer-8-connected-td5012756.html

There could be also minor differences which algorithm is used, see:

http://imagejdocu.tudor.lu/doku.php?id=faq:technical:what_are_the_algorithms_used_to_calculate_particle_area_and_perimeter

https://imagej.nih.gov/ij/docs/guide/146-30.html

Thanks for your reply.

The area measurement just comes out to the area of the selected polygon- I’m trying to measure the area of the black within the selection. When I repeated the same steps to analyze the image using red instead of black, I got the same mismatching result.


I also get the wrong result from the particle analyzer.

When I change the mode of the wand, (ie to 8 connected, 4 connected, legacy) I get more or less the same result. Is there any other macro-friendly way to analyze the black area within my ROI without using the wand tool??

Thank you so much!!

Edit: Oh, also, the value of ~44,000 was obtained from multiplying the area fraction with the total area of the ROI.

Threshold the area you want to measure and use the particle analyzer which will only measure the thresholded area within a selection (your polygon).

Create outlines as a visual control to see what you have measured (It should be the thresholded area in your selection).

See:

https://imagej.nih.gov/ij/docs/guide/146-30.html

I was teaching something similar last week so here is the code that counts pixels with value=255. Since your image LUT is inverted, this code counts the black area in your image.

c255 = 0;
for (j = 0; j < getHeight(); j++){
    for (i = 0; i < getWidth(); i++){
        if (Roi.contains( i, j)){
            val = getPixel( i,  j);
            if (val == 255){
                c255 += 1;
            }
        }
    }
}
print("255 counts:", c255);

Hello robynkw,
Since it is a binary image, simply use the area (your polygon) then Analyze > Histogram > List data and the black area will be everything that is not white.
Bob

1 Like

The easiest way to do this is to threshold the Image, enable “Limit to threshold” in Analyze>Set Measurements and use the Measure command.

Hello everyone,

thank you all so much for your helpful replies. I realized I was doing something completely dumb and you guys are all correct (the reason why the wand tool selection area was different from the area fraction/histogram/etc method was because the wand tool selection was including the white pixels within the black selection, which was what I wanted LOL!!) totally blonde moment there hahaha I’m so sorry and thanks again :slight_smile: