If statement for array

7 views (last 30 days)
Abdulmaged Algomaiah
Abdulmaged Algomaiah on 9 Oct 2019
Answered: Walter Roberson on 9 Oct 2019
I wrote this code in Matlab to get the color "rgb numbers" of a apecific pixel for each frame of a video:
video=VideoReader('TS_Example_2.mp4');
vidHeight=video.Height;
vidWidth=video.Width;
c = 182;
r = 84;
k=1;
while hasFrame(video)
img = readFrame(video);
rgb(:,:,k)=impixel(img, c, r);
k = k+1;
end
out=rgb(:,:,:)
I got an answer for all 866 frames like:
out(:,:,1) =
255 255 255
out(:,:,2) =
255 255 255
out(:,:,3) =
255 255 255
.
.
.
out(:,:,864) =
210 3 16
out(:,:,865) =
210 3 16
out(:,:,866) =
210 3 16
Now, I would like to write few lines to check if the colors during any frame is within specific range. I started by trying a specific frame "866" and specific rgb "210,3,16", but it didn't work. I wrote the following:
if rgb(:,:,866) == [210 3 6]
disp('Value within specified range.')
else
disp('No')
end
And I got the answer "No", while it's supposed to give "Value within specified range"!
Can anyone tell me where I went worng?
I also appreciate helping me to write few lines to check if the colors during any frame is within specific range

Answers (1)

Walter Roberson
Walter Roberson on 9 Oct 2019
out(:,:,866) =
210 3 16
[...]
if rgb(:,:,866) == [210 3 6]
866 has B component 16. You are testing for B component 6. Not a match.

Community Treasure Hunt

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

Start Hunting!