필터 지우기
필터 지우기

Create a .gif from series of images created in a for loop

조회 수: 11 (최근 30일)
David
David 2014년 8월 15일
답변: Image Analyst 2014년 8월 15일
Hi,
So I have some working code that reads in some data files, does some manipulation on said data and creates an image file based up the results. I can save each image generated into a specified output file, yet I also wish to create a .gif, where each frame is the image that just got generated. The code I currently have seems to just not work, and only uses the 1st image created. My code is below.
Any help would be greately appriciated!
cd('........')
output_file='.......';
gif_name = 'test.gif';
for count = 0:50;
%DATA MANIPULATION
..................
%CREATE AND SAVE IMAGE
data_figure = figure('Visible','off');
axes1 = axes('Parent', data_figure, 'ZGrid', 'on', 'YGrid', 'on');
view(axes1,[0.5 90]);
xlim(axes1,[-0.01 0.25]);
hold(axes1, 'all');
surf(data_A,data_B,data_C, 'Edgecolor', 'none');
colorbar;
xlabel('........');
ylabel('.........');
set(gca, 'XGrid', 'off');
ylabel(colorbar, '.......');
saveas(gcf, fullfile(output_file, [num2str(count),'.png']));
%PART THAT DOESNT WORK....CREATING GIF
frame = getframe(1);
im = frame2im(frame);
[AA,map] = rgb2ind(im,256);
if count == 0,
imwrite(AA,map,gif_name,'gif','LoopCount',Inf,'DelayTime',1);
else
imwrite(AA,map,gif_name,'gif','WriteMode','append','DelayTime',1);
end
end
  댓글 수: 1
David
David 2014년 8월 15일
Ok I have gotten it to work by changing frame = getframe(1); to frame=getframe(data_figure);
yet it diplays each frame on screen as it is creating the file, how do I stop this?

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

답변 (1개)

Image Analyst
Image Analyst 2014년 8월 15일
getframe() pulls the image out of the axes. If you don't want it to be displayed, then you can't use getframe(). You'll have to create the image yourself somehow.

카테고리

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