How to count the number of white pixels

조회 수: 52 (최근 30일)
윤주 황
윤주 황 2022년 5월 13일
댓글: Chunru 2022년 5월 13일
filename = 'untitled.jpg';
I = imread(filename);
figure, imshow(I);
sum(I(:) == 255)
ans = 592185
and
filename = 'untitled2.jpg';
I = imread(filename);
figure, imshow(I);
sum(I(:) == 255)
ans = 626229
....
This is strange that figure1 has much lower white pixels, because i'm agricultural student, so i do not know well about matlab, coding,,,
What is wrong about my script??

채택된 답변

Chunru
Chunru 2022년 5월 13일
First, you should use gray scale image.
Second you have a large white margin in your data (which is not seen from imshow). You can see the margin if you use imagesc instead.
If you need to count the white pixels inside. You can clip the image to remove the white margin first.
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/996375/image.jpeg';
I = imread(filename);
I = rgb2gray(I);
figure, imagesc(I); colorbar; %imshow(I);
sum(I(:) >= 250)
ans = 199547
sum(I(200:600, 200:600)>250, 'all')
ans = 583
figure; histogram(I(:))
%whos
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/996380/image.jpeg';
I = imread(filename);
I = rgb2gray(I);
figure, imagesc(I); colorbar; %imshow(I);
figure; histogram(I(:))
sum(I(:) >= 250)
ans = 211979
sum(I(200:600, 200:600)>250, 'all')
ans = 12900
  댓글 수: 2
윤주 황
윤주 황 2022년 5월 13일
Thank you for your answer, and i will try this script.
I'v got one more question.
I have to calculate <stained(fig1) pixels /flesh pixels(fig2)>.
According to your answers, <stained(fig1) pixels /flesh pixels(fig2) = 583/12900 >,, is that right??
Chunru
Chunru 2022년 5월 13일
You are right.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by