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

3 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2016-2-6
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?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2016-2-5
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 个评论
Meghana Dinesh
Meghana Dinesh 2016-2-6
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.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by