Вопрос

I'm trying to use VideoWriter to convert large amounts of tiff images into an avi video. I'm having trouble with the for loop to convert the images into a video. Here is the code I have so far:

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

Can anyone help me out? I think the problem is in my for loop.

This is the error I get when I try to run the code:

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));
Это было полезно?

Решение

Your imagelist is a cell array and therefore should be accessed using curly braces (instead of regular parentheses).

Replace

img = imread( imagelist(i) );

with

img = imread( imagelist{i} );

and see what happens.

PS,
It is best not to use i as a variable name in Matlab.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top