Tifffile: Read and Write TIFF Files

2026.3.3 · active · verified Sun Mar 29

Tifffile is a Python library designed for reading and writing TIFF files, particularly those prevalent in scientific imaging. It offers extensive support for various TIFF formats, including BigTIFF, OME-TIFF, and multi-page TIFF stacks. Actively maintained, it receives frequent updates, with the current version being 2026.3.3, reflecting continuous development and improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to write a NumPy array to a TIFF file, read it back, verify its content, and access basic metadata using `tifffile.imwrite`, `tifffile.imread`, and the `tifffile.TiffFile` context manager. It also includes cleanup of the created file.

import numpy as np
import tifffile
import os

# Create some dummy image data
dummy_image = np.random.rand(100, 100).astype(np.float32)

# Define a filename
filename = 'example.tif'

# Write the image data to a TIFF file
tifffile.imwrite(filename, dummy_image, description='Generated by tifffile quickstart')
print(f"Successfully wrote '{filename}'")

# Read the image data back from the TIFF file
read_image = tifffile.imread(filename)
print(f"Successfully read '{filename}' with shape: {read_image.shape}")

# Verify data
assert np.array_equal(dummy_image, read_image)
print("Original and read image data are identical.")

# Access metadata using TiffFile context manager
with tifffile.TiffFile(filename) as tif:
    if tif.pages:
        first_page_description = tif.pages[0].tags.get('ImageDescription')
        if first_page_description:
            print(f"ImageDescription from file: {first_page_description.value}")
        else:
            print("No ImageDescription found for the first page.")
    else:
        print("No pages found in the TIFF file.")

# Clean up the created file
os.remove(filename)
print(f"Cleaned up '{filename}'.")

view raw JSON →