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: enter image description here

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:

enter image description here

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 ?

  • 1
    $\begingroup$ ComponentMeasurements[AreaOfInterest, "Area"] $\endgroup$ – Sektor Jan 15 '15 at 10:12
  • $\begingroup$ 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. $\endgroup$ – 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}


Edit: To answer your comment (posted as an answer), I want to add this:

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

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

you obtain:

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

  • $\begingroup$ 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? $\endgroup$ – Sam DG Jan 15 '15 at 11:40
  • 1
    $\begingroup$ It sorts all pixels into dominant colors and counts the pixels of each group. $\endgroup$ – Philipp Jan 15 '15 at 13:56
  • $\begingroup$ 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. $\endgroup$ – 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:

  • $\begingroup$ 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. $\endgroup$ – Philipp Jan 15 '15 at 13:59
  • $\begingroup$ @Philipp If I understood the OP correctly, they have a binarised image ? $\endgroup$ – image_doctor Jan 15 '15 at 14:07
  • $\begingroup$ But if you download the image, it isn't. The OP does not say how he created that BW-image $\endgroup$ – Philipp Jan 15 '15 at 14:08
  • $\begingroup$ @Philipp Don't they say they thresholded it and then binarised it ? $\endgroup$ – image_doctor Jan 15 '15 at 14:11
  • $\begingroup$ They do. I just downloaded the image $\endgroup$ – Philipp Jan 15 '15 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.