Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a multiframe .tif file

I have pixel data that I want to use to create a new .tif image that has multiple frames. How would I go about doing this? I have tried python PIL however I have only found it supports multiple frame reading not writing. See below for my attempt that didn't work.

new_Image = Image.new("I;16", (num_pixels,num_rows))

for frame in range((len(final_rows)/num_rows)):
    pixels = new_Image.load()
    for row in range(num_rows):
        row_pixel = final_rows[row].getPixels()
        for pixel in range(num_pixels):
            pixels[pixel,row] = row_pixel[pixel]
    print frame
    new_Image.seek(frame)
like image 687
Marmstrong Avatar asked Oct 23 '13 14:10

Marmstrong


People also ask

Can you have a multi-page TIFF?

You can open multi-page tiff file with Adobe Reader. Then export it in tiff format. It automatically saves a separate Tiff file for each page.

What is a multi-page TIFF file?

You can import TIFF files and PDF files that contain more than one image each. These are called multi-image (or "multi-TIFF" for TIFF format) files. A multi-image file may contain: Images from up to 999 single-page documents. The images from one or more multi-page invoices.


1 Answers

For example, using numpy and scikit-image with FreeImage plugin:

import numpy as np
from skimage.io._plugins import freeimage_plugin as fi
image = np.zeros((32, 256, 256), 'uint16')
fi.write_multipage(image, 'multipage.tif')

Or save it uncompressed using numpy and tifffile.py:

import numpy as np
from tifffile import imsave
image = np.zeros((32, 256, 256), 'uint16')
imsave('multipage.tif', image)

This assumes that all pages have the same data shape and type and no additional tags need to be written.

like image 125
cgohlke Avatar answered Oct 24 '22 17:10

cgohlke