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

13 ビュー (過去 30 日間)
kanika bhalla
kanika bhalla 2021 年 4 月 22 日
コメント済み: kanika bhalla 2021 年 4 月 23 日
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.
Thank you in advance!!
  2 件のコメント
Jonas
Jonas 2021 年 4 月 22 日
you could count the white pixels, divide it by overall number of pixels and multiply it with the real size of the image
kanika bhalla
kanika bhalla 2021 年 4 月 22 日
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
Image Analyst 2021 年 4 月 23 日
You simply use nnz on your binary image to get the area in pixels
whiteArea = nnz(mask)
or you could use bwarea() - it uses a somewhat different algorithm for determining area (it's not just counting pixels).
whiteArea = bwarea(mask)
  1 件のコメント
kanika bhalla
kanika bhalla 2021 年 4 月 23 日
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.
Thank you for your useful answers and help!!

サインインしてコメントする。

その他の回答 (1 件)

Stephan
Stephan 2021 年 4 月 22 日
編集済み: Stephan 2021 年 4 月 22 日
Same as in your question yesterday: regionprops will solve both problems in 1 line of code.
  3 件のコメント
Stephan
Stephan 2021 年 4 月 22 日
編集済み: Stephan 2021 年 4 月 22 日
In your case 'basic' should be helpful - this gives the centroid and the area
kanika bhalla
kanika bhalla 2021 年 4 月 23 日
Hi Stephan,
Thank you for your help.
I tried what you guided me as shown below.
M=imread('C:\Users\Ucl\Desktop\test\mask_14H14\groundtruth_for_metrics\129groundtruth.jpg');
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!!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDenoising and Compression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by