Convert Image Sequence to Video

12 vues (au cours des 30 derniers jours)
CX
CX le 10 Nov 2013
Modifié(e) : Youssef Khmou le 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 commentaires
Walter Roberson
Walter Roberson le 10 Nov 2013
Are you using Simulink, or is it just Very Confused ?
How about if you
figure();
before you implay() ?
CX
CX le 10 Nov 2013
Modifié(e) : CX le 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.

Connectez-vous pour commenter.

Réponse acceptée

Youssef  Khmou
Youssef Khmou le 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 commentaires
CX
CX le 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 le 14 Nov 2013
Modifié(e) : Youssef Khmou le 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 .

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 10 Nov 2013
Modifié(e) : Image Analyst le 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 commentaires
Image Analyst
Image Analyst le 10 Nov 2013
I don't have Simulink and I run it and get no such error. See attached MATLAB-only demo.
CX
CX le 10 Nov 2013
Thanks!!!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by