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

조회 수: 6(최근 30일)
Nursyahirah Hafidz 2018년 5월 10일
편집: John BG 2018년 5월 11일
This is an image i have eroded and dilated. How do i find the percentage of the white ?

댓글을 달려면 로그인하십시오.

### 채택된 답변

John BG 2018년 5월 10일
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 =
0.155080657527910
.
KSSV says the white dots cover 15% of the image.
Yet, when we binarize the image
A1=A(:,:,1);
A2=imbinarize(A1);
imshow(A1)
figure(2);imshow(A2)
px_nz=nnz(A2)
total_px=numel(A2)
px_nz/total_px
px_nz =
23093
total_px =
399582
ans =
0.057792893573785
.
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.
.
thanks in advance for time and attention
John BG
##### 댓글 수: 1표시숨기기 없음
KSSV 2018년 5월 10일
Hello...when you save the image....the image has white background in all the corners...so I included the command to crop it...it is a commonsense that the user wants the ratio from whole image ...not a small part of it...

댓글을 달려면 로그인하십시오.

### 추가 답변(2개)

KSSV 2018년 5월 10일
I = imcrop(I) ; % crop the required part
I = rgb2gray(I) ; % convert to gray image
whitepixels = nnz(I) ;
totalpixels = numel(I) ;
iwant = whitepixels/totalpixels
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
KSSV 2018년 5월 10일
Huummhh...sounds legitimate....what's the solution?

댓글을 달려면 로그인하십시오.

Nursyahirah Hafidz 2018년 5월 11일
now how do i display the percentage on my gui?
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Image Analyst 2018년 5월 11일
How do you want to display it? In a static text label? In a table control? Over the image in the text overlay?

댓글을 달려면 로그인하십시오.

### 범주

Find more on Images 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