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

2 ビュー (過去 30 日間)
bay rem
bay rem 2016 年 2 月 5 日
コメント済み: Image Analyst 2016 年 2 月 6 日
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 件のコメント
bay rem
bay rem 2016 年 2 月 5 日
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 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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by