Imageio gif shape

41 views
Skip to first unread message

Simon J

unread,
May 14, 2016, 7:31:26 AM5/14/16
to imageio
Using the dev's comment here: http://stackoverflow.com/a/35943809
I used the code:
import imageio
with imageio.get_writer('/path/to/movie.gif', mode='I') as writer:
    for filename in filenames:
        image = imageio.imread(filename)
        writer.append_data(image)
To make a gif with a few images. The problem that I have is that the gif always ends up the shape of the first image, so it crops other, larger images later on in the process. How can I make it so the gif is always going to be the shape of the largest image?

Almar Klein

unread,
May 17, 2016, 4:23:44 AM5/17/16
to Simon J, imageio

Hi Simon,

 

The process assumes that the frames are of equal size. I’m even surprised that what you’re doing works :)  To do what you want, you can best get the maximum size and pad all images (or at least the first) using this size. Something like this:

 

ims = [...]

max_shape = [0, 0]

for im in ims:

    max_shape[0] = max(max_shape[0], im.shape[0])

    max_shape[1] = max(max_shape[1], im.shape[1])

 

template = np.zeros(max_shape)

for im in ims:

    better_im = template.copy()

    better_im[:im.shape[0], :im.shape[1]] = im

    ...

 

 

 

Regards,

  Almar

--
You received this message because you are subscribed to the Google Groups "imageio" group.
To unsubscribe from this group and stop receiving emails from it, send an email to imageio+u...@googlegroups.com.
To post to this group, send email to ima...@googlegroups.com.
Visit this group at https://groups.google.com/group/imageio.
For more options, visit https://groups.google.com/d/optout.

 

Reply all
Reply to author
Forward
0 new messages