简体   繁体   中英

Adding to MATLAB gif images using imwrite() (white images beyond certain point)

I've tried finding the answer to this all over the place, but I've had no luck so far. You see, I've ran into a problem where I'm generating gif files by appending images into a single gif using a for loop. But after a while, imwrite seems to stop actually adding the images into the gif file - it just adds white spaces instead.

So, the file itself is large enough (250MB) to feasibly have the right number of images in, but when I open it and play it, once it gets past a certain point I just have white images. I'm pretty damn sure it's nothing to do with the for loop itself - I've had it print out the image file it's working on for each loop iteration and that's correct. The filenames are all correct.

It just seems to give up after a certain number of images, so my thought is that maybe there's a maximum number? I have over 50 frames that I want to stitch together.

The code snippet I'm working on:

delay_time = 0; 

% for each frequency, read in the iso-contour and stitch to the plots
% together to make a gif
for counter_frequency = freq_min:freq_inc:freq_max
    im_in = imread(['2D FFT, ' num2str(counter_frequency, '%3.2f') ' GHz.png'], 'png');
    [imind,cm] = rgb2ind(im_in,256);
    disp([num2str(counter_frequency)]);
    if counter_frequency == freq_min
        imwrite(imind,cm,[directory.plot.iso_plots '\Iso-frequency Animation.gif'],'gif','DelayTime',delay_time,'LoopCount',inf);
    else
        imwrite(imind,cm,[directory.plot.iso_plots '\Iso-frequency Animation.gif'],'gif','DelayTime',delay_time,'WriteMode','append');
    end;
end;

Solved it! There was nothing wrong with my code after all - it was the program I was using to view the gif! Internet explorer is a bad idea guys. Always. Can't believe I forgot that! Found out the computer I was using for the coding had Chrome, opened it in Chrome out of curiosity - and it was fine.

Damn you, IE!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM