Tiff.currentDirectory

Returns the number of the current image directory in the file.

Category: Data Import and Analysis > Data Import and Export

Syntax

n = currentDirectory(t)

Returns the 1-based index of the directory being read or written.

Description

The method acts on a Tiff object created with Tiff(filename, mode). A TIFF file can hold several images, each described by its own directory. A freshly opened file is positioned at directory 1. Use nextDirectory or setDirectory to move.

Input arguments

t
Tiff object.

Output arguments

n
Directory index, 1 for the first image.

Example

Walk through two images

tag.ImageLength = 2; tag.ImageWidth = 2;
tag.Photometric = Tiff.Photometric.MinIsBlack;
tag.BitsPerSample = 8; tag.SamplesPerPixel = 1; tag.RowsPerStrip = 2;
tag.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
w = Tiff('m.tif', 'w');
w.setTag(tag); w.write(uint8([1 2; 3 4])); w.writeDirectory();
w.setTag(tag); w.write(uint8([5 6; 7 8])); w.close();
r = Tiff('m.tif', 'r');
r.currentDirectory()
r.nextDirectory();
r.currentDirectory()
r.close();
Output
ans = 1
ans = 2

See also

Tiff.setDirectory Tiff.nextDirectory Tiff.lastDirectory Tiff.read