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

12 ビュー (過去 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 Center および File ExchangeConvert Image Type についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by