Tiff.setSubDirectory

Moves to a sub-image whose file offset is given by a SubIFD tag.

Category: Data Import and Analysis > Data Import and Export

Syntax

setSubDirectory(t, offset)

Makes the sub-image at byte offset current.

Description

The method acts on a Tiff object created with Tiff(filename, mode). Some files attach reduced-resolution copies or other related images to a main image as sub-directories. The offsets come from the parent's SubIFD tag. A file without sub-images has nothing to move to, and an invalid offset is an error.

Input arguments

t
Tiff object opened for reading.
offset
Byte offset of the sub-directory, as listed in the SubIFD tag of the parent image.

Example

An invalid offset is rejected

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');
try
    r.setSubDirectory(0);
catch
    disp('no sub-directory at that offset')
end
r.close();
Output
no sub-directory at that offset

Notes

MatLivre cannot write SubIFD tags, so files with sub-images can only come from other programs.

See also

Tiff.setDirectory Tiff.getTag Tiff.nextDirectory Tiff.currentDirectory