Below is my code
im = imread('test.png');
imshow(im);
[rows columns] = size(im);
numberOfPixels = rows*columns;
r_t = 0;
Red = im(:,:,1);
pixel = 0;
for i=1:rows
for j=1:columns
red = impixel(Red,i,j);
if red == 255
r_t = r_t + 0;
else
r_t = r_t + red;
end
end
end
when i type impixel(Red,1,1)
I think the answer should be just 255, but command window display 255 255 255

 채택된 답변

Matt J
Matt J 2018년 9월 21일
편집: Matt J 2018년 9월 21일

0 개 추천

Red=im(:,:,1);
rt=sum( Red(Red~=255) , 'double')

댓글 수: 7

thanks alot, if I want exclude white pixel value of the image, then it should be like
Red=im(:,:,1);
Green=im(:,:,2);
Blue=im(:,:,3)
rt=sum( (Red(Red~=255) && Green(Green~=255) && Blue(Blue~=255)) , 'double')
?
Matt J
Matt J 2018년 9월 21일
편집: Matt J 2018년 9월 21일
No, it should be
notwhite = ~( Red==255&Green==255&Blue==255);
rt=sum( Red(notwhite) ,'double') ;
test test
test test 2018년 9월 21일
this is for the whole image?
Matt J
Matt J 2018년 9월 21일
편집: Matt J 2018년 9월 21일
It is the sum of all red channel values in pixels that are not completely white.
test test
test test 2018년 9월 21일
is it possible i compare the pixel value of R channel, G channel and B channel at the same time and set a condition where R==255 && G==255 && B==255 then only i sum up the pixel value
Matt J
Matt J 2018년 9월 21일
That's what we did.
test test
test test 2018년 9월 21일
thank you very much

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

추가 답변 (0개)

질문:

2018년 9월 21일

댓글:

2018년 9월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by