我正在尝试使用VideoWriter将大量tiff图像转换为avi视频。我在使用for循环将图像转换为视频时遇到问题。这是我到目前为止的代码:
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
任何人都可以帮助我吗?我认为问题出在我的for循环中。
这是我尝试运行代码时遇到的错误:
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 :(得分:1)
您的imagelist
是一个单元格数组,因此应该使用大括号(而不是常规括号)来访问。
替换
img = imread( imagelist(i) );
与
img = imread( imagelist{i} );
看看会发生什么。