Animated GIF contains offset in consecutive timestamps
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have an animated GIF that contains offsets from timestamp to timestamp, which is not desired.
The relevant code snippet is as follows:
for iter = 1 : 100
% Create an animated GIF image to illustrate the evolution of
% material distribution of optimized design
frame = getframe(axMatDist);
im = frame2im(frame);
[imind, cm] = rgb2ind(im, 256);
if (iter == 1)
imwrite(imind, cm, 'myanimation.gif', 'gif', 'Loopcount', inf);
else
imwrite(imind, cm, 'myanimation.gif', 'gif', 'WriteMode', 'append');
end
end
What could be the problem?
Respuestas (1)
DGM
el 13 de En. de 2022
Editada: DGM
el 13 de En. de 2022
To be more precise, the file does not contain any frame offsets. All the frames are positioned at [1 1]. The problem is that the frame sizes differ. This is an issue with the way the figures are drawn and captured.
h = imfinfo('https://www.mathworks.com/matlabcentral/answers/uploaded_files/860820/myanimation.gif');
unique([h.Top])
unique([h.Left])
unique([h.Height])
unique([h.Width])
Since I don't know how the figure is being drawn, I'll just suggest that it may suffice to explicitly set the axes geometry with xlim() and ylim(). If the axes position keeps changing (e.g. due to tick labels changing), or if the figure size keeps changing, that will change the output size. If so, removing extraneous objects from the figure and explicitly setting object sizes may make things more consistent.
If that's not an option, perhaps the captured images can be resized or padded to a fixed geometry using imresize(), but that's probably the less attractive option, as it's unclear whether there's a scale difference between frames or not. It's also unclear what the correct registration would be.
0 comentarios
Ver también
Categorías
Más información sobre Animation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!