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

 Akzeptierte Antwort

Matt J
Matt J am 21 Sep. 2018
Bearbeitet: Matt J am 21 Sep. 2018

0 Stimmen

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

7 Kommentare

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 am 21 Sep. 2018
Bearbeitet: Matt J am 21 Sep. 2018
No, it should be
notwhite = ~( Red==255&Green==255&Blue==255);
rt=sum( Red(notwhite) ,'double') ;
test test
test test am 21 Sep. 2018
this is for the whole image?
Matt J
Matt J am 21 Sep. 2018
Bearbeitet: Matt J am 21 Sep. 2018
It is the sum of all red channel values in pixels that are not completely white.
test test
test test am 21 Sep. 2018
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 am 21 Sep. 2018
That's what we did.
test test
test test am 21 Sep. 2018
thank you very much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 21 Sep. 2018

Kommentiert:

am 21 Sep. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by