How can I do summation pixel by pixel?

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 件のコメント

test test
test test 2018 年 9 月 21 日
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