Tiff class -
MATLAB Gateway to LibTIFF library routines
Description
The Tiff class represents a connection to
a Tagged Image File Format (TIFF) file and provides access to many
of the capabilities of the LibTIFF library. Use the methods of the Tiff object
to call routines in the LibTIFF library. While you can use the imread and imwrite functions
to read and write TIFF files, the Tiff class offers
capabilities that these functions don't provide, such as reading subimages,
writing tiles and strips of image data, and modifying individual TIFF
tags.
In most cases, the syntax of the Tiff method
is similar to the syntax of the corresponding LibTIFF library function.
To get the most out of the Tiff object, you must
be familiar with the LibTIFF API, as well as the TIFF specification
and technical notes. View this documentation at LibTIFF - TIFF
Library and Utilities.
MATLAB supports LibTIFF version 3.9.5.
For copyright information, see the libtiffcopyright.txt file.
Construction
obj = Tiff(filename,mode) creates a Tiff object
associated with the TIFF file filename. mode specifies
the type of access to the file.
A TIFF file is made up of one or more image file directories
(IFDs). An IFD contains image data and associated metadata. IFDs can
also contain subIFDs which also contain image data and metadata. When
you open a TIFF file for reading, the Tiff object makes the first
IFD in the file the current IFD. Tiff methods
operate on the current IFD. You can use Tiff object
methods to navigate among the IFDs and the subIFDs in a TIFF file.
When you open a TIFF file for writing or appending, the Tiff object
automatically creates a IFD in the file for writing subsequent data.
This IFD has all the default values specified in TIFF Revision 6.0.
When creating a new TIFF file, before writing any image to the
file, you must create certain required fields (tags) in the file.
These tags include ImageWidth, ImageHeight, BitsPerSample, SamplesPerPixel, Compression, PlanarConfiguration,
and Photometric. If the image data has a stripped
layout, the IFD contains the RowsPerStrip tag.
If the image data has a tiled layout, the IFD contains the TileWidth and TileHeight tags.
Use the setTag method to define values for these
tags.
Input Arguments
filename |
Text string specifying name of file.
|
mode |
One of the following text strings specifying the type of access
to the TIFF file.
Supported Values
| Parameter | Description |
| 'r' | Open file for reading |
| 'w' | Open file for writing; discard existing contents |
| 'a' | Open or create file for writing; append data to end of file. |
| 'r+' | Open (do not create) file for reading and writing |
|
Properties
Compression |
Specify scheme used to compress image data
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
Supported Values
| None |
| CCITTRLE (Read-only) |
| CCITTFax3 |
| CCITTFax4 |
| LZW |
| JPEG |
| CCITTRLEW (Read-only) |
| PackBits |
| SGILog |
| SGILog24 |
| Deflate |
| AdobeDeflate (Same as deflate |
Example: Set the Compression tag to the value JPEG.
Note how you use the property to specify the value.
tiffobj.setTag('Compression', Tiff.Compression.JPEG);
|
ExtraSamples |
Describe extra components
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
Supported Values
| Unspecified |
| AssociatedAlpha |
| UnassociatedAlpha |
Example: Set the ExtraSamples tag to the
value AssociatedAlpha. Note how you use the property
to specify the value.
tiffobj.setTag('ExtraSamples', Tiff.ExtraSamples.AssociatedAlpha);
|
InkSet |
Specify set of inks used in separated image.
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
In this context, separated refers to photometric interpretation,
not the planar configuration.
Supported Values
| CMYK | Order of components: cyan, magenta, yellow, black. Usually,
a value of 0 represents 0% ink coverage and a value of 255 represents
100% ink coverage for that component, but consult the TIFF specification
for DotRange. When you specify CMYK, do not set
the InkNames tag. |
| MultiInk | Any ordering other than CMYK. Consult the TIFF specification
for InkNames field for a description of the inks
used. |
Example:
tiffobj.setTag('InkSet', Tiff.InkSet.CMYK);
|
Orientation |
Specify visual orientation of the image data.
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
The first row represents the top of the image, and the first
column represents the left side. Support for this tag is for informational
purposes only, and it does not affect how MATLAB reads or writes
the image data.
Supported Values
| TopLeft |
| TopRight |
| BottomRight |
| BottomLeft |
| LeftTop |
| RightTop |
| RightBottom |
| LeftBottom |
Example:
tiffobj.setTag('Orientation', Tiff.Orientation.TopRight);
|
Photometric |
Specify color space of image data
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
Supported Values
| MinIsWhite |
| MinIsBlack |
| RGB |
| Palette |
| Mask |
| Separated (CMYK) |
| YCbCr |
| CIELab |
| ICCLab |
| ITULab |
| LogL |
| LogLUV |
| CFA |
| LinearRaw |
Example:
tiffobj.setTag('Photometric', Tiff.Photometric.RGB);
|
PlanarConfiguration |
Specifies how image data components are stored on disk
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
Supported Values
| Chunky | Store component values for each pixel contiguously. For example,
in the case of RGB data, the first three pixels would be stored in
the file as RGBRGBRGB etc. Almost all TIFF images have contiguous
planar configurations. |
| Separate | Store component values for each pixel separately. For example,
in the case of RGB data, the red component would be stored separately
in the file from the green and blue components. |
Example:
tiffobj.setTag('PlanarConfiguration', Tiff.PlanarConfiguration.Chunky);
|
ResolutionUnit |
Specify unit of measure used to interpret the XResolution and YResolution tags.
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
Supported Values
| None (default) |
| Inch |
| Centimeter |
Example: Set ResolutionUnit tag to the value Inch.
Then, setting XResolution tag to 300 means pixels
per inch.
tiffObj.setTag('ResolutionUnit', Tiff.ResolutionUnit.Inch);
tiffObj.setTag('XResolution', 300);
tiffObj.setTag('YResolution', 300);
|
SampleFormat |
Specify how to interpret each pixel sample
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
Supported Values
| Uint |
| Int |
| IEEEFP |
| Void |
| ComplexInt |
| ComplexIEEEFP |
Example:
tiffobj.setTag('SampleFormat', Tiff.SampleFormat.IEEEFP);
|
SGILogDataFmt |
Specify control of client data for SGILog codec
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
These enumerated values should only be used when the photometric
interpretation value is LogL or LogLUV.
The BitsPerSample, SamplesPerPixel,
and SampleFormat tags should not be set if the
image type is LogL or LogLuv.
The choice of SGILogDataFmt will set these tags
automatically. The Float and Bits8 settings
imply a SamplesPerPixel value of 3 for LogLUV images,
but only 1 for LogL images.
Supported Values
| Float | Single precision samples |
| Bits8 | uint8 samples (read only) |
This tag can be set only once per instance of a LogL/LogLuv Tiff
image object instance.
Example:
tiffobj = Tiff('example.tif','r');
tiffobj.setDirectory(3); % image three is a LogLuv image
tiffobj.setTag('SGILogDataFmt', Tiff.SGILogDataFmt.Float);
imdata = tiffobj.read();
|
SubFileType |
Specify type of image
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
SubFileType is a bitmask that indicates the
type of the image.
Supported Values
| Default | Default value for single image file or first image. |
| ReducedImage | The current image is a thumbnail or reduced-resolution image
that typically would be found in a sub-IFD. |
| Page | The image is a single image of a multi-image (or multipage)
file. |
| Mask | The image is a transparency mask for another image in the file.
The photometric interpretation value must be Photometric.Mask. |
Example:
tiffobj.setTag('SubFileType', Tiff.SubFileType.Mask);
|
TagID |
List of recognized TIFF tag names with their ID numbers
This property identifies all the supported TIFF tags with their
ID numbers. Use this property to specify a tag when using the setTag method.
For example, Tiff.TagID.ImageWidth returns the
ID of the ImageWidth tag. To get a list of the
names of supported tags, use the getTagNames method.
Example:
tiffobj.setTag(Tiff.TagID.ImageWidth, 300);
|
Thresholding |
Specifies technique used to convert from gray to black and white
pixels.
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
Supported Values
| BiLevel (default) |
| HalfTone |
| ErrorDiffuse |
Example:
tiffobj.setTag('Thresholding', Tiff.Thresholding.HalfTone);
|
YCbCrPositioning |
Specify relative positioning of chrominance samples
This property defines all the supported values for this tag.
You use this property to specify the value you want to assign to the
tag, using the setTag method. For more clarification,
see the example.
This property identifies all supported values for the YCbCrPositioning tag.
Supported Values
| Centered | Specify for compatibility with industry standards such as PostScript Level
2 |
| Cosited | Specify for compatibility with most digital video standards
such as CCIR Recommendation 601-1. |
Example:
tiffobj.setTag('YCbCrPositioning', Tiff.YCbCrPositioning.Centered);
|
Methods
Examples
Create a new TIFF file using the Tiff object.
To run this example, your directory must be writable.
t = Tiff('myfile.tif', 'w');
%
% Close the Tiff object
t.close();See Also
imread | imwrite
Tutorials