Convert Image Sequence to Video

12 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2013-11-10
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.

请先登录,再进行评论。

采纳的回答

Youssef  Khmou
Youssef Khmou 2013-11-10
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 个评论
CX
CX 2013-11-10
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 2013-11-14
编辑:Youssef Khmou 2013-11-14
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 个)

Image Analyst
Image Analyst 2013-11-10
编辑:Image Analyst 2013-11-10
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 个评论
Image Analyst
Image Analyst 2013-11-10
I don't have Simulink and I run it and get no such error. See attached MATLAB-only demo.

请先登录,再进行评论。

类别

Help CenterFile 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