issues with im2frame and getframe
4 次查看(过去 30 天)
显示 更早的评论
Hi all, i'm trying to make a video with some frames in a gui, i tried im2frame and getframe to pick the frames from my images but i have some problems. If i use im2frame and then set the video with movie i'm not able to set the size of the video so it's smaller or larger of the axes of my gui. If i use getframe the problem of the size is solved but i have also the visualization of all the images in my axes and then the video, basically i have a very fast slide of images before the start of the video. There is a way to solve these issues? Thanks
This is an example of the code i'm using:
s=size(handles.img);
for i=1:s(3)
imagesc(handles.img(:,:,i)),colormap(gray(256)),axis off;
frame(i)=getframe;
end
axes(handles.Immagine_Originale)
movie(frame,3,3)
0 个评论
回答(1 个)
Image Analyst
2016-6-9
编辑:Image Analyst
2016-6-9
Why are you even using iamgesc() and then getframe() at all? There is no need. You can make the movie directly from your 3-D image without even displaying them at all if you don't want to. Just do something like this:
% Convert the 3-D array to a movie.
% Preallocate myMovie, which will be an array of structures.
% First get a cell array with all the frames.
[vidHeight, vidWidth, numberOfFrames] = size(handles.img);
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.
myMovie = struct('cdata', allTheFrames, 'colormap', allTheColorMaps)
for frame = 1 : numberOfFrames
% Read the image in from disk.
thisFrame = handles.img(:,:, frame);
% Convert the image into a "movie frame" structure.
myMovie(frame) = im2frame(thisFrame);
% Write this frame out to a new video file.
writeVideo(writerObj, thisFrame);
end
close(writerObj);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!