# Image processing: Calculate the area of the region of interest

I am trying to compute the area of a particular region of interest from images which are obtained from an experiment. The original data looks like this:

I have to calculate the area of the region which has a darker shade compared to the rest of the image. Then using the scale bar, I have to convert the measurement into real life values. I have trimmed and binarized the images to obtain the portion of the image where I want to calculate the area.

After trimming and binarization, the image looks like this:

To get to this black and white image, I found the threshold of the image and then binarized the image such that all the pixel values < threshold value are replaced by 0 and all above threshold value are replaced by 1.

However, I cannot calculate the area of the black portion and then use the scale bar to compute the results.

Any suggestions ?

• ComponentMeasurements[AreaOfInterest, "Area"] – Sektor Jan 15 '15 at 10:12
• As you said, you are new to SE, I want to add that it makes sense to credit the answers by accepting the best answer, when your problem is solved. – Philipp Jan 15 '15 at 15:39

You only need one more line for evaluation of the coverage of the colors:

coverage = DominantColors[yourImageBlackWhite, 2, "Coverage"]
{0.762952, 0.213876}


-

You can show the number of covered pixels as well as the coverage. Using the command:

DominantColors[yourImageBlackWhite, 2, {"Color", "Count", "Coverage"}]


you obtain:

• Thanks for the help. So, we use Component Measurements to find out the area. Just want to confirm that the component measurements gives the area of each non zero pixels, which in our case for the binary image is 1. Is it true? – Sam DG Jan 15 '15 at 11:40
• It sorts all pixels into dominant colors and counts the pixels of each group. – Philipp Jan 15 '15 at 13:56
• Just wanted to mention that, in any analysis language, once you've got a rasterlike image and have identified the pixel values of interest, you can just count how many pixels meet the criteria, as this answer does. – Carl Witthoft Jan 15 '15 at 15:36

For an alternative approach to counting the number of black pixels in the binarised image you could try getting the image data and counting how many zeroes it has:

Count[Flatten@ImageData@yourBinaryImage,0]

• Does not work, as it is not perfectly 0. But you can use Count[#, u_ /; u < treshold] to find pixels lower than treshold. But the result of Count[#, u_ /; u < 0.01]/Length[#] &@Flatten@ImageData@bildsw is different from the DominantColors approach. – Philipp Jan 15 '15 at 13:59
• @Philipp If I understood the OP correctly, they have a binarised image ? – image_doctor Jan 15 '15 at 14:07
• But if you download the image, it isn't. The OP does not say how he created that BW-image – Philipp Jan 15 '15 at 14:08
• @Philipp Don't they say they thresholded it and then binarised it ? – image_doctor Jan 15 '15 at 14:11
• They do. I just downloaded the image – Philipp Jan 15 '15 at 14:16