2011-03-17 109 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訪問幀:)