what's the problem in this code, while i'm trying to extract the 3 channels of an RGB image?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Image Analyst
el 6 de Feb. de 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?
Respuestas (1)
Walter Roberson
el 5 de Feb. de 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 comentarios
Meghana Dinesh
el 6 de Feb. de 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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!