Convert Image Sequence to Video

조회 수: 9 (최근 30일)
CX
CX 2013년 11월 10일
편집: Youssef Khmou 2013년 11월 14일
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.
CX
CX 2013년 11월 10일
Thanks!!!

댓글을 달려면 로그인하십시오.

카테고리

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