MATLAB Answers

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

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

  댓글 수: 0

로그인 to comment.

채택된 답변

John BG
John BG 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 =
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.
.
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

KSSV
KSSV 10 May 2018
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...

로그인 to comment.

추가 답변(2개)

KSSV
KSSV 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

  댓글 수: 2

John BG
John BG 10 May 2018
Hi KSSV
this is John BG jgb2012@sky.com
I just tried your code cropping the entire image and it returns
..
0 0 67
0 0 67
0 0 67
0 5 63
73 73 122
iwant =
0.155080657527910
does it look to you that the white thick dots are anywhere close to a 15% of the whole image?

로그인 to comment.


Nursyahirah Hafidz
Nursyahirah Hafidz 11 May 2018
now how do i display the percentage on my gui?

  댓글 수: 2

John BG
John BG 11 May 2018
what do you mean by the percentage of your gui?
the percentage is already
amount_white_px/total_amount
use the amount directly, or x100.
Convert it to string with num2str() to use it in any command like: title xlabel ylabel or text, to add as comment directly on the screen?
Or has your gui a specific field? then plug the result to the gui field variable.
If you post another question asking how to key in this found percentage into your gui, and you attach your gui or a sample of it, I will show you how to use this result in your gui.
Regards
John BG
Image Analyst
Image Analyst 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?

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by