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

4 vues (au cours des 30 derniers jours)
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 commentaire
Image Analyst
Image Analyst le 6 Fév 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?

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 5 Fév 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 commentaires
bay rem
bay rem le 5 Fév 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 le 6 Fév 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by