Convert Image Sequence to Video

15 views (last 30 days)
CX
CX on 10 Nov 2013
Edited: Youssef Khmou on 14 Nov 2013
I have a set of binary images saved in a Cell Array. I would like to convert them to a video. Any suggestions?
So far I have done;
fileNames = dir(fullfile('C:\...\Cell Images','*.jpg'));
N = length(fileNames);
for k = 1:N
filename = fileNames(k).name;
C{k} = imread(filename);
[C{k} map{k}] = gray2ind(C{k}, 256);
frame{k} = im2frame (C{k}, map{k});
end
At this point when I try to use implay function I get the following error.
implay(frame) % Error using uiscopes.ScopeCLI/checkSource (line 74)
Input Simulink handle is invalid.
  2 Comments
Walter Roberson
Walter Roberson on 10 Nov 2013
Are you using Simulink, or is it just Very Confused ?
How about if you
figure();
before you implay() ?
CX
CX on 10 Nov 2013
Edited: CX on 10 Nov 2013
No this is on MATLAB not on SIMULINK. Sorry about the confusion. I just get that specific error. Using figure() before implay doesn't work. I just tried it.

Sign in to comment.

Accepted Answer

Youssef  Khmou
Youssef Khmou on 10 Nov 2013
you can simply try :
fileNames = dir(fullfile('C:\...\Cell Images','*.jpg'));
N = length(fileNames);
for k = 1:N
filename = fileNames(k).name;
C(:,:,k) = imread(filename);
end
mplay(C)
  2 Comments
CX
CX on 10 Nov 2013
Thank you so much. That worked. If you don't mind could you please explain to me why you used C(:, :, k) and why C{k} doesn't work?
Youssef  Khmou
Youssef Khmou on 14 Nov 2013
Edited: Youssef Khmou on 14 Nov 2013
the brakets {} are used for cells indexing, while the parenthesis are used for matrices, in this case your data is of the same nature, then its better to use a matrix for storage .
cordially .

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 10 Nov 2013
Edited: Image Analyst on 10 Nov 2013
See this snippet from one of my demos.
% Read the frames back in from disk, and convert them to a movie.
% Preallocate recalledMovie, which will be an array of structures.
% First get a cell array with all the frames.
allTheFrames = cell(numberOfFrames,1);
allTheFrames(:) = {zeros(vidHeight, vidWidth, 3, 'uint8')};
% Next get a cell array with all the colormaps.
allTheColorMaps = cell(numberOfFrames,1);
allTheColorMaps(:) = {zeros(256, 3)};
% Now combine these to make the array of structures.
recalledMovie = struct('cdata', allTheFrames, 'colormap', allTheColorMaps)
for frame = 1 : numberOfFrames
% Construct an output image file name.
outputBaseFileName = sprintf('Frame %4.4d.png', frame);
outputFullFileName = fullfile(outputFolder, outputBaseFileName);
% Read the image in from disk.
thisFrame = imread(outputFullFileName);
% Convert the image into a "movie frame" structure.
recalledMovie(frame) = im2frame(thisFrame);
% Write this frame out to a new video file.
writeVideo(writerObj, thisFrame);
end
close(writerObj);
% Get rid of old image and plot.
delete(hImage);
delete(hPlot);
% Create new axes for our movie.
subplot(1, 3, 2);
axis off; % Turn off axes numbers.
title('Movie recalled from disk', 'FontSize', fontSize);
% Play the movie in the axes.
movie(recalledMovie);
% Note: if you want to display graphics or text in the overlay
% as the movie plays back then you need to do it like I did at first
% (at the top of this file where you extract and imshow a frame at a time.)
msgbox('Done with this demo!');
  3 Comments
Image Analyst
Image Analyst on 10 Nov 2013
I don't have Simulink and I run it and get no such error. See attached MATLAB-only demo.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!