Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

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. 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.

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.

Inputs

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

Properties

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.

 Supported Values

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.

Unspecified
AssociatedAlpha
UnassociatedAlpha

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.

 Supported Values

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.

 Supported Values

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.

 Supported Values

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.

 Supported Values

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.

 Supported Values

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.

 Supported Values

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.

 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 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.

 Supported Values

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.

 Supported Values

Example:

tiffobj.setTag('YCbCrPositioning', Tiff.YCbCrPositioning.Centered);

Methods

closeClose Tiff object
computeStripIndex number of strip containing specified coordinate
computeTileIndex number of tile containing specified coordinates
currentDirectoryIndex of current IFD
getTagValue of specified tag
getTagNamesList of recognized TIFF tags
getVersionLibTIFF library version
isTiledDetermine if tiled image
lastDirectoryDetermine if current IFD is last in file
nextDirectoryMake next IFD current IFD
numberOfStripsTotal number of strips in image
numberOfTilesTotal number of tiles in image
readRead entire image
readEncodedStripRead data from specified strip
readEncodedTile Read data from specified tile
rewriteDirectoryWrite modified metadata to existing IFD
setDirectoryMake specified IFD current IFD
setSubDirectoryMake subIFD specified by byte offset current IFD
setTagSet value of tag
write Write entire image
writeDirectoryCreate new IFD and make it current IFD
writeEncodedStripWrite data to specified strip
writeTileWrite data to specified tile

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

  


Recommended Products

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