Main Content

TIFF

Read and write blocked 2-D image data as single TIFF file

Since R2021a

Description

The TIFF object is an adapter that reads and writes 2-D blocked image data as a single TIFF file.

When writing to disk, the TIFF format requires block sizes to be a multiple of 16. If the blocked image has any additional metadata in the UserData property, then the TIFF object writes the data to a separate MAT file with the same file name.

The object supports lossy and lossless compression. By default, the object uses Lempel-Ziv-Welch lossless compression. To use a different compression scheme, create the object and then change the compression scheme using the Compression property. You can also use this property to turn off compression. For example, to use JPEG-based lossy compression, use this code.

adapter = images.blocked.TIFF;
adapter.Compression = Tiff.Compression.JPEG;

The table lists the support that the TIFF object has for various blockedImage capabilities.

CapabilitiesSupport
Data types

This object supports 2-D images only:

  • Binary images of size m-by-n with data type logical

    Grayscale images of size m-by-n with data type uint8, int16, uint16, int32, uint32, single, or double

  • Truecolor (RGB) images of size m-by-n-by-3 with data type uint8, uint16, uint32, single, or double

Multiple resolution levelsYes
Process blocks in parallel using the apply functionNo
Resume block processing using the apply functionNo

Creation

Description

adapter = images.blocked.TIFF creates a TIFF object that reads and writes blocked image data as a single TIFF file.

example

Properties

expand all

TIFF compression scheme, specified as one of these numeric scalars.

Compression SchemeDescription
Tiff.Compression.LZW or the number 5Lempel-Ziv-Welch lossless compression
Tiff.Compression.PackBits or the number 32773PackBits lossless compression
Tiff.Compression.Deflate or the number 32946Adobe DEFLATE lossless compression
Tiff.Compression.JPEG or the number 7JPEG-based lossy compression
Tiff.Compression.None or the number 1No compression

Preferred file extension, specified as a string scalar or character vector.

Data Types: char | string

Examples

collapse all

Create a blocked image.

bim = blockedImage("tumor_091R.tif");

Create two new images by processing the blocked image using two different operations.

bim.BlockSize = [512 512 3];
bo1 = apply(bim, @(bs)im2gray(bs.Data));
bo3 = apply(bim, @(bs)im2gray(bs.Data),Level=3);

Create a single multiresolution TIFF file from the two images. Specify additional resolution levels using the LevelImages name-value argument. Change the TIFF compression scheme by creating an adapter and setting the Compression property of the adapter.

wa = images.blocked.TIFF; % Specify the TIFF adapter
wa.Compression = Tiff.Compression.JPEG; % Specify compression in the adapter
write(bo1,"tumor_091RGray.tif",LevelImages=bo3,Adapter=wa);

Tips

  • If you want to read 3-D TIFF volumes, use one of these alternative adaptors based on the file format. Before R2024b, you had to create your own adapter using the images.blocked.Adapter class for all formats of 3-D TIFF volumes.

    3-D TIFF Volume SupportAdapter

    TIFF IFDS (Image File Directories), or subimages, in which every IFD is a slice

    TIFF3D (since R2024b)
    TIFF images in the ImageJ formatTIFF3D (since R2024b)
    A set of TIFF files in a directory, with one TIFF file per sliceCreate your own adapter using the images.blocked.Adapter class

Version History

Introduced in R2021a