Public interface

Reading/Writing

TiffImages.loadFunction
load(filepath; mode, kwargs...)

Loads a TIFF image. Optional flags verbose, lazyio, and mmap are set to true, false, and false by default, respectively. Setting verbose to false will hide the loading bar, while setting either lazyio or mmap to true defer loading until the data are needed (by either of two mechanisms).

Parallelism is enabled by default, but can be disabled by setting JULIA_IMAGES_PARALLEL=false in your environment

See Lazy TIFFs for more details about memory-mapping and lazy I/O.

source
TiffImages.saveFunction
save(io, data)

Write data to io, if data is a DenseTaggedImage then any custom tags are also written to the file, otherwise a minimal set of tags are added to make the data readable by other TIFF engines.

source

Output Types

TiffImages.DenseTaggedImageType
struct DenseTaggedImage{T, N, O<:Unsigned, AA<:AbstractArray} <: TiffImages.AbstractDenseTIFF{T, N}

The most common TIFF structure that associates an Image File Directory, aka TiffImages.IFD, with each XY image slice.

julia> img = TiffImages.DenseTaggedImage(Gray.(zeros(UInt8, 10, 10)));

julia> size(img)
(10, 10)

julia> ifds(img)
IFD, with tags: 
	Tag(IMAGEWIDTH, 10)
	Tag(IMAGELENGTH, 10)
	Tag(BITSPERSAMPLE, 8)
	Tag(PHOTOMETRIC, 1)
	Tag(SAMPLESPERPIXEL, 1)
	Tag(SAMPLEFORMAT, 1)

julia> ifds(img)[TiffImages.XRESOLUTION] = 0x00000014//0x00000064 # write custom data
0x00000001//0x00000005

julia> TiffImages.save(mktemp()[2], img); # write to temp file
Note

Currently, when writing custom info to tags, play attention to the types expected by other TIFF engines. For example, XRESOLUTION above expects a rational by default, which is equivalent to the Julian Rational{UInt32}

See also TiffImages.load and TiffImages.save

source
TiffImages.LazyBufferedTIFFType
mutable struct LazyBufferedTIFF{T<:Colorant, O<:Unsigned, AA<:AbstractArray} <: TiffImages.AbstractDenseTIFF{T<:Colorant, 3}

A type to represent lazily-loaded TIFF data, returned by TiffImages.load(filepath; lazyio=true). Useful for opening and operating on images too large to store in memory, and for incrementally writing new TIFF files.

This works by buffering individual slices. This allows broad format support, including compressed TIFFs, but with mixed performance depending on your specific access (indexing) patterns. See discussion in the package documentation, and MmappedTIFF for an alternative with different strengths and weaknesses.

julia> using TiffImages, ColorTypes

julia> img = empty(LazyBufferedTIFF, Gray{Float32}, joinpath(mktempdir(), "test.tif"))
32-bit LazyBufferedTIFF{Gray{Float32}} 0×0×0 (writable)
    Current file size on disk:   8 bytes
    Addressable space remaining: 4.000 GiB

julia> close(img) # when you're done, close the stream
  • file: Pointer to keep track of the backing file
  • ifds: The associated tags for each slice in this array
  • dims

  • cache: An internal cache to fill reading from disk

  • cache_index: The index of the currently loaded slice
  • last_ifd_offset: Position of last loaded IFD, updated whenever a slice is appended
  • readonly: A flag tracking whether this file is editable
source
TiffImages.MmappedTIFFType
struct MmappedTIFF{T<:Colorant, N, O<:Unsigned, A<:AbstractArray{T<:Colorant, 2}} <: TiffImages.AbstractTIFF{T<:Colorant, N}

A type to represent memory-mapped TIFF data, returned by TiffImages.load(filepath; mmap=true). Useful for opening and operating on images too large to store in memory.

This works by exploiting the operating system's memory-mapping capabilities. This is not compatible with certain TIFF options, including compression, but when applicable it gives good performance for most access (indexing) patterns. See discussion in the package documentation, and LazyBufferedTIFF for an alternative with different strengths and weaknesses.

julia> using TiffImages

julia> img = TiffImages.load(filepath; mmap=true);

julia> print(summary(img))
200×541 TiffImages.MmappedTIFF{RGBA{N0f8}, 2}

Fields:

  • chunks: 2d slices in the file
  • ifds: The associated tags for each slice in this array
  • sz2: The 2d slice size
source