Counting black and white pixels

Hi,
I am new to image J. I am wanting to count the number of white pixels in a black and white image and the number of black pixels. Any idea what plug in i need for this and/ or how to do it?

I know I can use the pixel inspection tool, but this allows me to only look at 36 pixels at a time and relies on me not making an error. Is there an automated way to do it?
This is the image:

(I downloaded the color counter plugin however this requires RGB values to count and I only want to count B & W)

Many thanks,
Lily

Dear @LilyD,

first check if your images are binary images according to the ImageJ definition (8-bit, only 0 and 255 pixel values). If not, you can use the Image > Process > Make Binary command. Once that is done, you can go to Analyze > Set Measurements and enable the Limit to threshold option (also check that the Area box is checked while you are at it).

If you select your image again and do Analyze > Measure, the area column will contain only the number of white pixels since you have enabled the Limit to threshold option (only white pixels are taken into account for a measurement, i.e. from the complete image in your case). You can invert the image (Edit > Invert) and repeat the measurement to get the number of black pixels (that are white after inversion and are thus counted by the measurement).

Best,
Stefan

2 Likes

There are several ways to do this easily with a binary or a greyscale image.

One easy way would be to create a histogram

Analyze->Histogram

The press the List action to get the different counts of the histogram as a list.

2 Likes

thank you stefan but how can we do this using the histogram?

Mohamed,
Try something like this:

getHistogram(values, counts, 2);
Array.print(counts);

image

Best regards,
Jerome.