how to compute number of pixels in images

조회 수: 34 (최근 30일)
Medical Imaging
Medical Imaging 2017년 7월 28일
댓글: Image Analyst 2017년 7월 28일
Dear sir I have one ground truth image(image 1) and other segmented image(image 2). I want to compute the number of pixel for white area for image 1 and number of pixel for red area in image 2. and then want to compute the difference of pixels.
  댓글 수: 2
Adam
Adam 2017년 7월 28일
If the black pixels are all 0s then just use
doc nnz
If they aren't you can still just easily count, for example
nnz( myImage == 7 )
Gianfrancesco Angelini
Gianfrancesco Angelini 2017년 7월 28일
There are many ways to do it. I will suggest you a basic one, hoping to be clearer and helpful
% Define your images
img1 = x1;
img2 = x2;
% Convert them in grayscale, easier approach
img1g = rgb2gray(img1);
img2g = rgb2gray(img2);
figure(); imshow(img1g); %if you want to see the result
figure(); imshow(img2g); %if you want to see the result
% Calculate
img1g_totpx = numel( img1g ); %total number of pixel of img1
img1g_NB = length( img1g(img1g~=0) ); %number of pixel not black of img1
img2g_totpx = numel( img2g ); %total number of pixel of img2
img2g_NB = length( img2g(img2g~=0) ); %number of pixel not black of img2
diffPx = abs( img1g_NB - img2g_NB ); %difference of pixels between the 2 imgs
Cheers

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

채택된 답변

Image Analyst
Image Analyst 2017년 7월 28일
Because a different person asked this very same question with the very same image, and Walter answered it here I'm thinking it's homework. I've tagged it as such.
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 7월 28일
It was the same person, posting twice.
Image Analyst
Image Analyst 2017년 7월 28일
Oh, you're right. He posted it in someone else's discussion. I just saw the original poster's name.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by