I have an avi-video-file. I would like to represent a frame from this video as 3 matrices (because colors are parameterized by 3 number ([red,green,blue] or [hue,saturation,value] or something else).
At the moment I have this code:
videoObject = mmreader(fname);
imageData = read(videoObject, [1 5])
So, as far as I understand I extract the first 5 frames from the video. But I do not understand in what format the imageData
is given. For example, how can I get the green component of the color of the pixel from the th开发者_Python百科ird frame located at the row number 17 and column number 32?
Can anybody, please, help me with that?
As far as I understand it can be done in the following way. A particular frame can be reached in this way:
% Take frame number 7:
imageData = read(videoObject, 7);
Now if we want to know the read, green, blue component of the pixel in the column 1 and row 2 we need to do that:
impixel(imageData,1,2)
It will return 3 numbers (RGB component of the color of the pixel).
The format for imageData
returned from the function read
is a 4-D array where your dimensions are (in order) frame height, frame width, image depth (3 for RGB images), and number of frames. So, to get the green component of the pixel in row 17 and column 32 of the third frame, you would simply do this:
greenValue = imageData(17,32,2,3);
One side note: mmreader
will be removed in a future MATLAB release in favor of VideoReader
.
vidObj1 = mmreader('testballroom_0.avi'); %# Create a video file object
nFrames = vidObj1.NumberOfFrames; %# Get the number of frames
vidHeight1 = vidObj1.Height; %# Get the image height
vidWidth1 = vidObj1.Width; %# Get the image width
%# Preallocate the structure array of movie frames:
mov1(1:nFrames) = struct('cdata',zeros(vidHeight1,vidWidth1,3,'uint8'),...
'colormap',[]); %# Note that colormap is empty!
You can access the frames from mov1 :)
精彩评论