| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
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. In most cases, the syntax of the Tiff method is similar to the syntax of the corresponding LibTIFF library function.
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.
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.
filename |
Text string specifying name of file. |
mode |
One of the following text strings specifying the type of access to the TIFF file. |
Compression |
Specify scheme used to compress image data This property identifies all supported values for the Compression tag. You can use this property to specify the value of this tag when using the setTag method. Example: tiffobj.setTag('Compression', Tiff.Compression.JPEG);
| |||
ExtraSamples |
Describe extra components This property identifies all supported values for the ExtraSamples tag. Use this property to specify the value of this tag when using the setTag method.
Example: tiffobj.setTag('ExtraSamples', Tiff.ExtraSamples.AssociatedAlpha);
| |||
InkSet |
Specify set of inks used in separated image This property identifies all supported values for the InkSet tag. Use this property to specify the value of this tag when using the setTag method. In this context, separated refers to photometric interpretation, not the planar configuration. Example: tiffobj.setTag('InkSet', Tiff.InkSet.CMYK);
| |||
Orientation |
Specify visual orientation of the image data. This property identifies all supported values for the Orientation tag. The first row represents the top of the image, and the first column represents the left side. Use this property to specify the value of this tag when using the setTag method. Support for this tag is for informational purposes only, and it does not affect how MATLAB reads or writes the image data. Example: tiffobj.setTag('Orientation', Tiff.Orientation.TopRight);
| |||
Photometric |
Specify color space of image data This property identifies all supported values for the Photometric tag. Use this property to specify the value of this tag when using the setTag method. Example: tiffobj.setTag('Photometric', Tiff.Photometric.RGB);
| |||
PlanarConfiguration |
Specifies how image data components are stored on disk This property identifies all supported values for the PlanarConfiguration tag. Use this property to specify the value of this tag when using the setTag method. Example: tiffobj.setTag('PlanarConfiguration', Tiff.PlanarConfiguration.Chunky);
| |||
ResolutionUnit |
Specify unit of measurement used for XResolution and YResolution tags This property identifies all supported values for the XResolution and YResolution tags. Use this property to specify the value of this tag when using the setTag method. Example: tiffobj.setTag('YResolution', Tiff.ResolutionUnit.Inch);
| |||
SampleFormat |
Specify how to interpret each pixel sample This property identifies all supported values for the SampleFormat tag. Use this property to specify the value of this tag when using the setTag method. Example: tiffobj.setTag('SampleFormat', Tiff.SampleFormat.IEEEFP);
| |||
SubFileType |
Specify type of image This property identifies all supported values for the SubFileType tag. SubFileType is a bitmask that indicates the type of the image. Use this property to specify the value of this tag when using the setTag method. 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 identifies all supported values for the Thresholding tag. Use this property to specify the value of this tag when using the setTag method. Example: tiffobj.setTag('Thresholding', Tiff.Thresholding.HalfTone);
| |||
YCbCrPositioning |
Specify relative positioning of chrominance samples This property identifies all supported values for the YCbCrPositioning tag. This property specifies the positioning of chrominance components relative to luminance samples. Use this property to specify the value of this tag when using the setTag method. 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 |
| 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 |
| writeTile | Write data to specified tile |
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();![]() | tic, toc | timer | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |