Tifffile: Read and Write TIFF Files
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
- breaking The `TiffPages.pages` and `FileSequence.files` attributes, as well as `stripnull`, `stripascii`, and `bytestr` functions, have been removed. Command-line interfaces were rewritten.
- breaking The `TiffWriter.save` method is deprecated; use `TiffWriter.write` instead. Various other `TiffWriter` parameters like `compress` have been replaced by a `compression` parameter.
- breaking The `multifile` parameter for `TiffFile` was removed. Support for Python 3.7 and earlier has been dropped, and Python 32-bit versions are deprecated.
- gotcha For very large TIFF files, loading the entire image into memory with `imread` can lead to `MemoryError`. Also, `TiffFile` objects should be properly closed.
- gotcha Some TIFF-like formats do not strictly adhere to the TIFF6 specification, which might lead to unexpected behavior or incomplete data reading if not handled correctly.
- breaking Decoding EER super-resolution sub-pixels and parsing EER metadata to dict changed significantly, introducing breaking changes.
Install
-
pip install tifffile -
pip install -U tifffile[all] -
conda install tifffile -c conda-forge
Imports
- imread
import tifffile; image_data = tifffile.imread('image.tif') - imwrite
import tifffile; tifffile.imwrite('output.tif', image_data) - TiffFile
from tifffile import TiffFile; with TiffFile('image.tif') as tif: ...
Quickstart
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}'.")