How do I find the percentage for the area of white colour over the area of the full image?

11 views (last 30 days)
This is an image i have eroded and dilated. How do i find the percentage of the white ?

Accepted Answer

John BG
John BG on 10 May 2018
Hi Nursyahirah
When one zooms in it turns out that KSSV answer includes a lot of grey pixels wrapping the thick white dots that shouldn't be considered aprt of the pixels.
KSSV code renders a white area of
0 0 67
0 0 67
0 0 67
0 5 63
73 73 122
iwant =
KSSV says the white dots cover 15% of the image.
Yet, when we binarize the image
px_nz =
total_px =
ans =
the image only has a 5.7% of white pixels.
Comment: Since the question clearly mentions 'full image' there's no need the crop the image.
If you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance for time and attention
John BG
  1 Comment
KSSV on 10 May 2018
Hello...when you save the image....the image has white background in all the I included the command to crop is a commonsense that the user wants the ratio from whole image ...not a small part of it...

Sign in to comment.

More Answers (2)

KSSV on 10 May 2018
I = imread('ED.png') ; % REad the image
I = imcrop(I) ; % crop the required part
I = rgb2gray(I) ; % convert to gray image
whitepixels = nnz(I) ;
totalpixels = numel(I) ;
iwant = whitepixels/totalpixels

Sign in to comment.

Nursyahirah Hafidz
Nursyahirah Hafidz on 11 May 2018
now how do i display the percentage on my gui?
Image Analyst
Image Analyst on 11 May 2018
How do you want to display it? In a static text label? In a table control? Over the image in the text overlay?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!