MATLAB Gateway to LibTIFF library routines
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 imwritefunctions 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 atLibTIFF - TIFF Library and Utilities.
MATLAB supports LibTIFF version 4.0.0.
For copyright information, see the libtiffcopyright.txt file.
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 theTileWidth and TileHeight tags. Use the setTag method to define values for these tags.
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 |
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 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. This field is required if there are extra channels in addition to the usual colormetric channels. Supported Values 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); See Also Specify Tiff object properties and describe alpha channel |
Group3Options |
Options for Group 3 Fax Compression 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 is also referred to as Fax3 and T4Options. This value is a bit mask controlled by the first three bits. Supported Values Example: mask = bitor(Tiff.Group3Options.Encoding2D,Tiff.Group3Options.Uncompressed)
tiffobj.setTag('Group3Options',mask);
|
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 Example: tiffobj.setTag('InkSet', Tiff.InkSet.CMYK); |
JPEGColorMode |
Specify control of YCbCr/RGB conversion Use these values only when the photometric interpretation is YCbCr. This property should not be used for the purpose of reading YCbCr imagery as RGB. In this case, use the RGBA interface provided by the readRGBAImage, readRGBAStrip, and readRGBATile methods. Supported Values Example: tiffobj.setTag('JPEGColorMode',Tiff/JPEGColorMode.RGB); See also Create YCbCr/JPEG image from RGB data |
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 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 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 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 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 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 isLogL or LogLuv. The choice of SGILogDataFmt will set these tags automatically. The Float and Bits8settings imply a SamplesPerPixel value of 3 for LogLUV images, but only 1 for LogL images. Supported Values 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 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 ImageWidthtag. 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 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 Example: tiffobj.setTag('YCbCrPositioning', Tiff.YCbCrPositioning.Centered); |
close | Close Tiff object |
computeStrip | Index number of strip containing specified coordinate |
computeTile | Index number of tile containing specified coordinates |
currentDirectory | Index of current IFD |
getTag | Value of specified tag |
getTagNames | List of recognized TIFF tags |
getVersion | LibTIFF library version |
isTiled | Determine if tiled image |
lastDirectory | Determine if current IFD is last in file |
nextDirectory | Make next IFD current IFD |
numberOfStrips | Total number of strips in image |
numberOfTiles | Total number of tiles in image |
read | Read entire image |
readEncodedStrip | Read data from specified strip |
readEncodedTile | Read data from specified tile |
readRGBAImage | Read image using RGBA interface |
readRGBAStrip | Read strip data using RGBA interface |
readRGBATile | Read tile data using RGBA interface |
rewriteDirectory | Write modified metadata to existing IFD |
setDirectory | Make specified IFD current IFD |
setSubDirectory | Make subIFD specified by byte offset current IFD |
setTag | Set value of tag |
write | Write entire image |
writeDirectory | Create new IFD and make it current IFD |
writeEncodedStrip | Write data to specified strip |
writeEncodedTile | Write data to specified tile |
imfinfo | imread | imwrite