2013-04-30 38 views
1

我正在嘗試使用VideoWriter將大量的tiff圖像轉換爲avi視頻。我在使用for循環將圖像轉換爲視頻時遇到了麻煩。這裏是我到目前爲止的代碼:在matlab中將tiff圖像轉換爲avi

function tif2avi 

clc; close all; 
[imagelist,p]=uigetfile('*.tif','MultiSelect','on',... 
    'Select LIST to plot'); pause(0.5); cd(p); 
if ~iscell(imagelist); disp('imagelist not cell'); return; end; 

outputVideo = VideoWriter('0424_rat01.avi'); 
outputVideo.FrameRate = 16; 
outputVideo.Quality = 100; 
open(outputVideo); 

for i=1:numel(imagelist) 
    img=imread(imagelist(i)); 
    writeVideo(outputVideo,img); 
end 

任何人都可以幫我嗎?我認爲問題出在我的循環中。

這是我的錯誤,當我嘗試運行代碼:

Warning: No video frames were written to this file. The file may be invalid. 
> In VideoWriter.VideoWriter>VideoWriter.close at 289 
    In VideoWriter.VideoWriter>VideoWriter.delete at 238 
Error using imread>parse_inputs (line 476) 
The filename or url argument must be a string. 

Error in imread (line 335) 
[filename, fmt_s, extraArgs] = parse_inputs(varargin{:}); 

Error in tif2avi (line 14) 
    img=imread(imagelist(i)); 
+0

你能否詳細說明「我有麻煩」? – Oleg 2013-04-30 00:26:08

+0

當我嘗試運行代碼時出現此錯誤: 警告:沒有視頻幀寫入此文件。該文件可能無效。 >在VideoWriter.VideoWriter> VideoWriter.close 289 在VideoWriter.VideoWriter> VideoWriter.delete在使用imread> parse_inputs(線476)238 錯誤 文件名或URL參數必須是字符串。 imread中的錯誤(第335行) [filename,fmt_s,extraArgs] = parse_inputs(varargin {:}); tif2avi錯誤(第14行) img = imread(imagelist(i)); – zlangley 2013-04-30 00:39:06

回答

1

imagelist是一個單元陣列,因此應使用大括號(而不是常規的括號中)進行訪問。

更換

img = imread(imagelist(i)); 

img = imread(imagelist{i}); 

,看看會發生什麼。

PS,
最好是not to use i as a variable name in Matlab

+0

謝謝。那就是訣竅。 – zlangley 2013-04-30 22:23:46