TiffPage

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.

property andor_tags: dict[str, Any] | None

Consolidated metadata from Andor tags.

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]

aspage()

Return TiffPage instance.

Return type:

TiffPage

aszarr(**kwargs)

Return image from page as Zarr 2 store.

Parameters:
Return type:

ZarrTiffStore

property attr: dict[str, Any]

Arbitrary metadata associated with image array.

property chunked: tuple[int, ...]

Shape of chunked image.

property chunks: tuple[int, ...]

Shape of images in tiles or strips.

property colormap: NDArray[numpy.uint16] | None

Value of Colormap tag.

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

Ordered map of dimension names to coordinate arrays.

property datetime: datetime | None

Date and time of image creation.

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.

property dims: tuple[str, ...]

Names of dimensions in image array.

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 flags: set[str]

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

property geotiff_tags: dict[str, Any] | None

Consolidated metadata from GeoTIFF tags.

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 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 iccprofile: bytes | None

Value of InterColorProfile tag.

property imagej_description: str | None

ImageJ description if exists, else None.

property index: int

Index of page in IFD chain.

property is_agilent: bool

Page contains Agilent Technologies tags.

property is_andor: bool

Page contains Andor Technology tags 4864-5030.

property is_astrotiff: bool

Page contains AstroTIFF FITS metadata.

property is_avs: bool

Page contains Argos AVS XML metadata.

property is_bif: bool

Page contains Ventana metadata.

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_dng: bool

Page contains DNG metadata.

property is_eer: bool

Page contains EER acquisition metadata.

property is_epics: bool

Page contains EPICS areaDetector tags.

property is_fei: bool

Page contains FEI_SFEG or FEI_HELIOS tags.

property is_final: bool

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

property is_fluoview: bool

Page contains FluoView MM_STAMP tag.

property is_frame: bool

Object is TiffFrame instance.

property is_gdal: bool

Page contains GDAL metadata.

property is_geotiff: bool

Page contains GeoTIFF metadata.

property is_imagej: bool

Page contains ImageJ description metadata.

property is_indica: bool

Page contains IndicaLabs metadata.

property is_jfif: bool

JPEG compressed segments contain JFIF metadata.

property is_lsm: bool

Page contains CZ_LSMINFO tag.

property is_mask: bool

Page is transparency mask for another image.

property is_mdgel: bool

Page contains MDFileTag tag.

property is_mediacy: bool

Page contains Media Cybernetics Id tag.

property is_memmappable: bool

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

property is_metaseries: bool

Page contains MDS MetaSeries metadata in ImageDescription tag.

property is_micromanager: bool

Page contains MicroManagerMetadata tag.

property is_mrc: bool

Page is part of Mixed Raster Content.

property is_multipage: bool

Page is part of multi-page image.

property is_ndpi: bool

Page contains NDPI metadata.

property is_nih: bool

Page contains NIHImageHeader tag.

property is_ome: bool

Page contains OME-XML in ImageDescription tag.

property is_philips: bool

Page contains Philips DP metadata.

property is_pilatus: bool

Page contains Pilatus tags.

property is_qpi: bool

Page contains PerkinElmer tissue images metadata.

property is_reduced: bool

Page is reduced image of another image.

property is_scanimage: bool

Page contains ScanImage metadata.

property is_scn: bool

Page contains Leica SCN XML in ImageDescription tag.

property is_sem: bool

Page contains CZ_SEM tag.

property is_shaped: bool

Page contains Tifffile JSON metadata.

property is_sis: bool

Page contains Olympus SIS metadata.

property is_stk: bool

Page contains UIC1Tag tag.

property is_streak: bool

Page contains Hamamatsu streak metadata.

property is_subifd: bool

Page is SubIFD of another page.

property is_subsampled: bool

Page contains chroma subsampled image.

property is_svs: bool

Page contains Aperio metadata.

property is_tiffep: bool

Page contains TIFF/EP metadata.

property is_tiled: bool

Page contains tiled image.

property is_tvips: bool

Page contains TVIPS metadata.

property is_virtual: bool

Page does not have IFD structure in file.

property is_vista: bool

Software tag is ‘ISS Vista’.

property is_volumetric: bool

Page contains SGI ImageDepth tag with value > 1.

property keyframe: TiffPage

Self.

property maxworkers: int

Maximum number of threads for decoding segments.

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

property name: str

Name of image array.

property nbytes: int

Number of bytes in image array.

property ndim: int

Number of dimensions in image array.

property ndpi_tags: dict[str, Any] | None

Consolidated metadata from Hamamatsu NDPI tags.

property pages: TiffPages | None

Sequence of sub-pages, SubIFDs.

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.

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]]]

property shaped_description: str | None

Description containing array shape if exists, else None.

property size: int

Number of elements in image array.

property sizes: dict[str, int]

Ordered map of dimension names to lengths.

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

Tile depth, length, and width.

property transferfunction: NDArray[numpy.uint16] | None

Value of TransferFunction tag.

property treeindex: tuple[int, ...]

Index of page in IFD tree.