TiffPage

final class tifffile.TiffPage(parent, /, index, *, keyframe=None)

TIFF image file directory (IFD).

TiffPage instances are not thread-safe. All attributes are read-only.

Parameters:
  • parent (TiffFile) – TiffFile instance to read page from. The file handle position must be at an offset to an IFD structure.

  • index (int | Sequence[int]) – Index of page in IFD tree.

  • keyframe (TiffPage | None) – Not used.

Raises:

TiffFileError – Invalid TIFF structure.

tags: TiffTags

Tags belonging to page.

parent: TiffFile

TiffFile instance page belongs to.

offset: int

Position of page in file.

shape: tuple[int, ...]

Shape of image array in page.

dtype: numpy.dtype[Any] | None

Data type of image array in page.

shaped: tuple[int, int, int, int, int]

Normalized 5-dimensional shape of image array in page:

  1. separate samplesperpixel or 1.

  2. imagedepth or 1.

  3. imagelength.

  4. imagewidth.

  5. contig samplesperpixel or 1.

axes: str

Character codes for dimensions in image array: ‘S’ sample, ‘X’ width, ‘Y’ length, ‘Z’ depth.

dataoffsets: tuple[int, ...]

Positions of strips or tiles in file.

databytecounts: tuple[int, ...]

Size of strips or tiles in file.

subfiletype: int = 0

FILETYPE kind of image.

imagewidth: int = 0

Number of columns (pixels per row) in image.

imagelength: int = 0

Number of rows in image.

imagedepth: int = 1

Number of Z slices in image.

tilewidth: int = 0

Number of columns in each tile.

tilelength: int = 0

Number of rows in each tile.

tiledepth: int = 1

Number of Z slices in each tile.

samplesperpixel: int = 1

Number of components per pixel.

bitspersample: int = 1

Number of bits per pixel component.

sampleformat: int = 1

SAMPLEFORMAT type of pixel components.

rowsperstrip: int = 4294967295

Number of rows per strip.

compression: int = 1

COMPRESSION scheme used on image data.

planarconfig: int = 1

PLANARCONFIG type of storage of components in pixel.

fillorder: int = 1

Logical order of bits within byte of image data.

photometric: int = 0

PHOTOMETRIC color space of image.

predictor: int = 1

PREDICTOR applied to image data before compression.

extrasamples: tuple[int, ...] = ()

EXTRASAMPLE interpretation of extra components in pixel.

subsampling: tuple[int, int] | None = None

Subsampling factors used for chrominance components.

subifds: tuple[int, ...] | None = None

Positions of SubIFDs in file.

jpegtables: bytes | None = None

JPEG quantization and Huffman tables.

jpegheader: bytes | None = None

JPEG header for NDPI.

software: str = ''

Software used to create image.

description: str = ''

Subject of image.

description1: str = ''

Value of second ImageDescription tag.

nodata: int | float = 0

Value used for missing data. The value of the GDAL_NODATA tag or 0.

property decode: Callable[..., tuple[NDArray[Any] | None, tuple[int, int, int, int, int], tuple[int, int, int, int]]]

Return decoded segment, its shape, and indices in image.

The decode function is implemented as a closure and has the following signature:

Parameters:
  • data (Union[bytes, None]) – Encoded bytes of segment (strip or tile) or None for empty segments.

  • index (int) – Index of segment in Offsets and Bytecount tag values.

  • jpegtables (Optional[bytes]) – For JPEG compressed segments only, value of JPEGTables tag if any.

Returns:

  • Decoded segment or None for empty segments.

  • Position of segment in image array of normalized shape (separate sample, depth, length, width, contig sample).

  • Shape of segment (depth, length, width, contig samples). The shape of strips depends on their linear index.

Raises:
  • ValueError or NotImplementedError – Decoding is not supported.

  • TiffFileError – Invalid TIFF structure.

segments(*, lock=None, maxworkers=None, func=None, sort=False, buffersize=None, _fullsize=None)

Return iterator over decoded tiles or strips.

Parameters:
  • lock (threading.RLock | NullContext | None) – Reentrant lock to synchronize file seeks and reads.

  • maxworkers (int | None) – Maximum number of threads to concurrently decode segments.

  • func (Callable[..., Any] | None) – Function to process decoded segment.

  • sort (bool) – Read segments from file in order of their offsets.

  • buffersize (int | None) – Approximate number of bytes to read from file in one pass. The default is _TIFF.BUFFERSIZE.

  • _fullsize (bool | None) – Internal use.

Yields:
  • Decoded segment or None for empty segments.

  • Position of segment in image array of normalized shape (separate sample, depth, length, width, contig sample).

  • Shape of segment (depth, length, width, contig samples). The shape of strips depends on their linear index.

Return type:

Iterator[tuple[NDArray[Any] | None, tuple[int, int, int, int, int], tuple[int, int, int, int]]]

asarray(*, out=None, squeeze=True, lock=None, maxworkers=None, buffersize=None)

Return image from page as NumPy array.

Parameters:
  • out (OutputType) – Specifies how image array is returned. By default, a new NumPy array is created. If a numpy.ndarray, a writable array to which the image is copied. If ‘memmap’, directly memory-map the image data in the file if possible; else create a memory-mapped array in a temporary file. If a string or open file, the file used to create a memory-mapped array.

  • squeeze (bool) – Remove all length-1 dimensions (except X and Y) from image array. If False, return the image array with normalized 5-dimensional shape TiffPage.shaped.

  • lock (threading.RLock | NullContext | None) – Reentrant lock to synchronize seeks and reads from file. The default is the lock of the parent’s file handle.

  • maxworkers (int | None) – Maximum number of threads to concurrently decode segments. If None or 0, use up to _TIFF.MAXWORKERS threads. See remarks in TiffFile.asarray().

  • buffersize (int | None) – Approximate number of bytes to read from file in one pass. The default is _TIFF.BUFFERSIZE.

Returns:

NumPy array of decompressed, unpredicted, and unpacked image data read from Strip/Tile Offsets/ByteCounts, formatted according to shape and dtype metadata found in tags and arguments. Photometric conversion, premultiplied alpha, orientation, and colorimetry corrections are not applied. Specifically, CMYK images are not converted to RGB, MinIsWhite images are not inverted, color palettes are not applied, gamma is not corrected, and CFA images are not demosaciced. Exception are YCbCr JPEG compressed images, which are converted to RGB.

Raises:

ValueError – Format of image in file is not supported and cannot be decoded.

Return type:

NDArray[Any]

aszarr(**kwargs)

Return image from page as Zarr store.

Parameters:
Return type:

ZarrTiffStore

aspage()

Return TiffPage instance.

Return type:

TiffPage

property index: int

Index of page in IFD chain.

property treeindex: tuple[int, ...]

Index of page in IFD tree.

property keyframe: TiffPage

Self.

property name: str

Name of image array.

property ndim: int

Number of dimensions in image array.

property dims: tuple[str, ...]

Names of dimensions in image array.

property sizes: dict[str, int]

Ordered map of dimension names to lengths.

property coords: dict[str, NDArray[Any]]

Ordered map of dimension names to coordinate arrays.

property attr: dict[str, Any]

Arbitrary metadata associated with image array.

property size: int

Number of elements in image array.

property nbytes: int

Number of bytes in image array.

property colormap: NDArray[numpy.uint16] | None

Value of Colormap tag.

property iccprofile: bytes | None

Value of InterColorProfile tag.

property transferfunction: NDArray[numpy.uint16] | None

Value of TransferFunction tag.

get_resolution(unit=None, scale=None)

Return number of pixels per unit in X and Y dimensions.

By default, the XResolution and YResolution tag values are returned. Missing tag values are set to 1.

Parameters:
  • unit (RESUNIT | int | str | None) – Unit of measurement of returned values. The default is the value of the ResolutionUnit tag.

  • scale (float | int | None) – Factor to convert resolution values to meter unit. The default is determined from the ResolutionUnit tag.

Return type:

tuple[int | float, int | float]

property resolution: tuple[float, float]

Number of pixels per resolutionunit in X and Y directions.

property resolutionunit: int

Unit of measurement for X and Y resolutions.

property datetime: datetime | None

Date and time of image creation.

property tile: tuple[int, ...] | None

Tile depth, length, and width.

property chunks: tuple[int, ...]

Shape of images in tiles or strips.

property chunked: tuple[int, ...]

Shape of chunked image.

property hash: int

Checksum to identify pages in same series.

Pages with the same hash can use the same decode function. The hash is calculated from the following properties: TiffFile.tiff, TiffPage.shaped, TiffPage.rowsperstrip, TiffPage.tilewidth, TiffPage.tilelength, TiffPage.tiledepth, TiffPage.sampleformat, TiffPage.bitspersample, TiffPage.fillorder, TiffPage.predictor, TiffPage.compression, TiffPage.extrasamples, and TiffPage.photometric.

property pages: TiffPages | None

Sequence of sub-pages, SubIFDs.

property maxworkers: int

Maximum number of threads for decoding segments.

A value of 0 disables multi-threading also when stacking pages.

property is_contiguous: bool

Image data is stored contiguously.

Contiguous image data can be read from offset=TiffPage.dataoffsets[0] with size=TiffPage.nbytes. Excludes prediction and fillorder.

property is_final: bool

Image data are stored in final form. Excludes byte-swapping.

property is_memmappable: bool

Image data in file can be memory-mapped to NumPy array.

property flags: set[str]

Set of is\_\* properties that are True.

property andor_tags: dict[str, Any] | None

Consolidated metadata from Andor tags.

property epics_tags: dict[str, Any] | None

Consolidated metadata from EPICS areaDetector tags.

Use the epics_datetime() function to get a datetime object from the epicsTSSec and epicsTSNsec tags.

property ndpi_tags: dict[str, Any] | None

Consolidated metadata from Hamamatsu NDPI tags.

property geotiff_tags: dict[str, Any] | None

Consolidated metadata from GeoTIFF tags.

property shaped_description: str | None

Description containing array shape if exists, else None.

property imagej_description: str | None

ImageJ description if exists, else None.

property is_jfif: bool

JPEG compressed segments contain JFIF metadata.

property is_frame: bool

Object is TiffFrame instance.

property is_virtual: bool

Page does not have IFD structure in file.

property is_subifd: bool

Page is SubIFD of another page.

property is_reduced: bool

Page is reduced image of another image.

property is_multipage: bool

Page is part of multi-page image.

property is_mask: bool

Page is transparency mask for another image.

property is_mrc: bool

Page is part of Mixed Raster Content.

property is_tiled: bool

Page contains tiled image.

property is_subsampled: bool

Page contains chroma subsampled image.

property is_imagej: bool

Page contains ImageJ description metadata.

property is_shaped: bool

Page contains Tifffile JSON metadata.

property is_mdgel: bool

Page contains MDFileTag tag.

property is_agilent: bool

Page contains Agilent Technologies tags.

property is_mediacy: bool

Page contains Media Cybernetics Id tag.

property is_stk: bool

Page contains UIC1Tag tag.

property is_lsm: bool

Page contains CZ_LSMINFO tag.

property is_fluoview: bool

Page contains FluoView MM_STAMP tag.

property is_nih: bool

Page contains NIHImageHeader tag.

property is_volumetric: bool

Page contains SGI ImageDepth tag with value > 1.

property is_vista: bool

Software tag is ‘ISS Vista’.

property is_metaseries: bool

Page contains MDS MetaSeries metadata in ImageDescription tag.

property is_ome: bool

Page contains OME-XML in ImageDescription tag.

property is_scn: bool

Page contains Leica SCN XML in ImageDescription tag.

property is_micromanager: bool

Page contains MicroManagerMetadata tag.

property is_andor: bool

Page contains Andor Technology tags 4864-5030.

property is_pilatus: bool

Page contains Pilatus tags.

property is_epics: bool

Page contains EPICS areaDetector tags.

property is_tvips: bool

Page contains TVIPS metadata.

property is_fei: bool

Page contains FEI_SFEG or FEI_HELIOS tags.

property is_sem: bool

Page contains CZ_SEM tag.

property is_svs: bool

Page contains Aperio metadata.

property is_bif: bool

Page contains Ventana metadata.

property is_scanimage: bool

Page contains ScanImage metadata.

property is_indica: bool

Page contains IndicaLabs metadata.

property is_avs: bool

Page contains Argos AVS XML metadata.

property is_qpi: bool

Page contains PerkinElmer tissue images metadata.

property is_geotiff: bool

Page contains GeoTIFF metadata.

property is_gdal: bool

Page contains GDAL metadata.

property is_astrotiff: bool

Page contains AstroTIFF FITS metadata.

property is_streak: bool

Page contains Hamamatsu streak metadata.

property is_dng: bool

Page contains DNG metadata.

property is_tiffep: bool

Page contains TIFF/EP metadata.

property is_sis: bool

Page contains Olympus SIS metadata.

property is_ndpi: bool

Page contains NDPI metadata.

property is_philips: bool

Page contains Philips DP metadata.

property is_eer: bool

Page contains EER acquisition metadata.