MATLAB: How to do summation pixel by pixel

pixel value summationrgb 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

Best Answer

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