what's the problem in this code, while i'm trying to extract the 3 channels of an RGB image?

1 view (last 30 days)
while i'm reading an rgb video, i wanted to extract for each frame its 3 channels(R,G and B) but the results looks weird, here there is the code i uused:
videoReader = vision.VideoFileReader('video.avi');
J=0;
while ~isDone(videoReader);
J=J+1
frameRGB = step(videoReader);
figure;imshow(frameRGB);
imwrite(frameRGB,'frame.jpg');
a=imread('frame.jpg');
figure,imshow(a(:,:,1));
figure,imshow(a(:,:,2));
figure,imshow(a(:,:,3));
end
ps: i used writing frame , to make sure about results
  1 Comment
Image Analyst
Image Analyst on 6 Feb 2016
What's weird? It looks like you should get the 3 color channels in separate figures. Each one will be grayscale, of course, because they are not true color images anymore, and you have not applied a colormap to the gray scale images either. What were you expecting?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 5 Feb 2016
R = frameRGB;
R(:, :, 2:3) = 0;
imshow(R) ;
and likewise for the other two panes, setting the channels except for the one of interest to 0
  2 Comments
bay rem
bay rem on 5 Feb 2016
can i know you you really did in here? i don't understand and how can i extract the 2 other channels
Meghana Dinesh
Meghana Dinesh on 6 Feb 2016
Well, do you know how an RGB image is stored in MATLAB? It has three channels, R, G and B.
To view only the R channel, make G and B channels zero. (As shown above)
To view only the G channel, make R and B channels zero.
G = frameRGB;
G(:, :, 1) = 0;
G(:, :, 3) = 0;
imshow(G) ;
To view only the B channel, make R and G channels zero.
B = frameRGB;
B(:, :, 1:2) = 0;
imshow(B) ;
It is very trivial, and has already been discussed in several questions on this forum. Perhaps you would like to do a simple google search.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!