ismisesisko
ismisesisko

Reputation: 151

Save numpy array as TIFF sequence using PIL

I have seen an example of loading a TIFF sequence of say a 3D tiff stack or animation. However I cannot figure out how to do the opposite, taking say, a 3D+ numpy array and saving it as a TIFF sequence. Are there are any examples of encoding this? I can read a 2D array using PIL.fromarray. It would be nice if this method had some way of loading a multi-dimensional array but a naive method call will throw an unsupported-type exception.

Presumably if one did write such a sequence they might also want to add some headers to dictate channels, time and so forth. My particular bias is being able to open such images in applications like ImageJ/FIJI or converting from TIFF to other formats. Maybe there are better ways to go about this in the first place.

Upvotes: 4

Views: 4247

Answers (1)

Alex Crocker
Alex Crocker

Reputation: 35

I know this is very old, but in case anyone comes here looking for the answer, this does seem to have been solved nicely.

e.g.

im.save("filename.tiff", format="TIFF", save_all=True)

https://pillow.readthedocs.io/en/latest/releasenotes/3.4.0.html

Upvotes: 1

Related Questions