MATLAB: Making a movie from images in matlab

movie from images in matlabvideo processing

Hey, I found this code from a link given by image analyst. It is perfect for want but i don't why this error is coming up………..
here is the code:
% Make an avi movie from a collection of PNG images in a folder.
% Specify the folder.
clear all; clc;
MATLAB = '/home/user/Documents/Tunde/MATLAB';
if ~isdir(MATLAB)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a directory listing.
filePattern = fullfile(MATLAB, '*.png');
pngFiles = dir(filePattern);
% Open the video writer object.
writerObj = VideoWriter('YourAVI.avi');
% Go through image by image writing it out to the AVI file.
for frameNumber = 1 : length(pngFiles)
% Construct the full filename.
baseFileName = pngFiles(frameNumber).name;
fullFileName = fullfile(MATLAB, baseFileName);
% Display image name in the command window.
fprintf(1, 'Now reading %s\n', fullFileName);
% Display image in an axes control.
thisimage = imread(fullFileName);
imshow(thisimage); % Display image.
drawnow; % Force display to update immediately.
% Write this frame out to the AVI file.
writeVideo(writerObj, thisimage);
end
% Close down the video writer object to finish the file.
close(writerObj);
and here is the comment:
Now reading /home/user/Documents/Tunde/MATLAB/Fitting (2).png
??? Error using ==> VideoWriter.VideoWriter>VideoWriter.writeVideo at 319
OBJ must be open before writing video. Call open(obj) before calling writeVideo.
Error in ==> movieeed at 28
writeVideo(writerObj, thisimage);

Best Answer

Please make sure your code is formatted correctly. It is barely readable.
Anyways, you didn't actually open the video writer object in your code. The line
writerObj = VideoWriter('YourAVI.avi');
Should be followed by:
open(writerObj);