# How to calculate the area of only white part in the image

28 views (last 30 days)
kanika bhalla on 22 Apr 2021
Commented: kanika bhalla on 23 Apr 2021
I want to calculate the area of only white part as shown in the figure. I had used - bwarea(image). But I am not sure whether its calculating correct area or not. As I just need the white portion area.
Any help is much appreciated.
##### 2 CommentsShowHide 1 older comment
kanika bhalla on 22 Apr 2021
Hi Jonas,
Thank you for your answer. But I need some automatic way to calculate the area of white portion. Any help related to this is much appreciated.
Thank you!!

Image Analyst on 23 Apr 2021
You simply use nnz on your binary image to get the area in pixels
or you could use bwarea() - it uses a somewhat different algorithm for determining area (it's not just counting pixels).
kanika bhalla on 23 Apr 2021
Hi Image Analyst,
Thank you for introducing me to new function- nnz
As i have checked doc nnz. n = nnz(MASK). It returns the number of nonzero elements in matrix X. I have confusion then how it will calculate the area.
Now I have used bwarea() to calculate the area of white portion.

Stephan on 22 Apr 2021
Edited: Stephan on 22 Apr 2021
Same as in your question yesterday: regionprops will solve both problems in 1 line of code.
kanika bhalla on 23 Apr 2021
Hi Stephan,
I tried what you guided me as shown below.
cc = bwconncomp(M);
stats = regionprops(cc,'Area');
But this is not giving me teh one desired output. Could you please guide me further why the output looks like this. I should get one area of only white portion.
Thank you!!

### Categories

Find more on Region and Image Properties in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by