Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
David
David el 15 de Ag. de 2014
Respondida: Image Analyst el 15 de Ag. de 2014
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 comentario
David
David el 15 de Ag. de 2014
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?

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 15 de Ag. de 2014
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.

Categorías

Más información sobre Display Image en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by