2011-03-17 35 views
0

我有一个avi-视频文件。我想将此视频中的帧表示为3个矩阵(因为颜色参数化为3个数字([红色,绿色,蓝色]或[色调,饱和度,值]或其他)。有这样的代码:。如何在MATLAB中获取代表视频帧的矩阵?

videoObject = mmreader(fname); 
imageData = read(videoObject, [1 5]) 

所以,据我了解,我从视频中提取第5帧,但我不给出什么格式imageData理解。例如,我怎么能得到绿色像素颜色的组成第三个框架位于行号和列号?

请问有人能帮我吗?

回答

2

据我了解,可以通过以下方式完成。

% Take frame number 7: 
imageData = read(videoObject, 7); 

现在,如果我们想知道读,绿,蓝像素的成分的第1列和第2行中,我们需要做的是:特定帧可以通过这种方式来达到

impixel(imageData,1,2) 

它会返回3个数字(像素颜色的RGB分量)。

2

从函数read返回的imageData的格式是4-D array,其中尺寸是(按顺序)帧高度,帧宽度,图像深度(3为RGB图像)和帧数。因此,要获得像素的列17和第三帧的列32绿色组件,您只需做到这一点:

greenValue = imageData(17,32,2,3); 

一个侧面说明:mmreader将在未来MATLAB的版本中删除赞成VideoReader

0
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! 

您可以从MOV1访问帧:)