issues with im2frame and getframe

조회 수: 6 (최근 30일)
Fabrizio Marangio
Fabrizio Marangio 2016년 6월 9일
편집: Fabrizio Marangio 2016년 6월 10일
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)

답변 (1개)

Image Analyst
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);
  댓글 수: 1
Fabrizio Marangio
Fabrizio Marangio 2016년 6월 10일
편집: Fabrizio Marangio 2016년 6월 10일
I have another question, if i use this code:
s=size(handles.img);
res_img=imresize(handles.img,[128 128]);
for i=1:s(3)
handles.frame(i)=im2frame(res_img(:,:,i),handles.map);
end
axes(handles.video_axes)
movie(handles.frame,3,3)
i see the video in my axes at 128x128 but if i open another image i see the new video plus the old video. Basically i can't reset the first video i saw

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

카테고리

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