Convert Image Sequence to Video

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 个评论

Are you using Simulink, or is it just Very Confused ?
How about if you
figure();
before you implay() ?
CX
CX 2013-11-10
编辑:CX 2013-11-10
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.

请先登录,再进行评论。

 采纳的回答

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 个评论

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?
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 .

请先登录,再进行评论。

更多回答(1 个)

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 个评论

Thanks. I don't think simulink is involved in this. I just get the following errors when I run the code on the question.
Error using uiscopes.ScopeCLI/checkSource (line 74)
Input Simulink handle is invalid.
Error in uiscopes.Framework (line 14)
checkSource(hScopeCfg.ScopeCLI);
Error in uiscopes/new (line 22)
hScope = uiscopes.Framework(hScopeCfg, varargin{:});
Error in implay (line 55)
obj = uiscopes.new(hScopeCfg);
Error in images2video (line 25)
implay (C)
I don't have Simulink and I run it and get no such error. See attached MATLAB-only demo.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by