Tiff.read

Reads the whole current image into an array.

Category: Data Import and Analysis > Data Import and Export

Syntax

A = read(t)

Returns the image pixels, decoded and assembled.

Description

The method acts on a Tiff object created with Tiff(filename, mode). Strips or tiles are decoded and put back in order, so you get the image as one array whatever the layout in the file. For a multi-image file, read returns the current directory; move with setDirectory or nextDirectory.

Input arguments

t
Tiff object opened for reading.

Output arguments

A
Image array: m-by-n for grayscale, m-by-n-by-k for several samples per pixel. The class follows BitsPerSample.

Example

Round trip

tag.ImageLength = 8; tag.ImageWidth = 8;
tag.Photometric = Tiff.Photometric.MinIsBlack;
tag.BitsPerSample = 8; tag.SamplesPerPixel = 1; tag.RowsPerStrip = 4;
tag.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
I = uint8(magic(8) * 3);
w = Tiff('t.tif', 'w'); w.setTag(tag); w.write(I); w.close();
r = Tiff('t.tif', 'r');
A = r.read();
size(A), class(A)
isequal(A, I)
r.close();
Output
ans = 1×2

     8     8
ans = 'uint8'
ans = logical
   1

See also

Tiff.readEncodedStrip Tiff.setTag imread Tiff.setDirectory