This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Class: Tiff

Set value of tag




setTag(tiffobj,tagId,tagValue) sets the value of the TIFF tag specified by tagId to the value specified by tagValue. You can specify tagId as a character string ('ImageWidth') or using the numeric tag identifier defined by the TIFF specification (256). To see a list of all the tags with their numeric identifiers, view the value of the Tiff object TagID property. Use the TagID property to specify the value of a tag. For example, Tiff.TagID.ImageWidth is equivalent to the tag's numeric identifier.

setTag(tiffobj,tagStruct) sets the values of all of the tags with name/value fields in tagStruct. The names of fields in tagstruct must be the name of TIFF tags.

    Note:   If you are modifying a tag rather than creating it, you must use the Tiff.rewriteDirectory method after using the Tiff.setTag method.


expand all

Write TIFF tags and image data to a new TIFF file.

Read sample data into an array, imdata. Create a Tiff object associated with a new file, myfile.tif, and open the file for writing.

imdata = imread('example.tif');
t = Tiff('myfile.tif','w');

Set tag values by specifying the numeric tag identifier. Use the TagID property to obtain the tag identifier.


Set tag values by specifying the tag name.

setTag(t,'Photometric', Tiff.Photometric.RGB)
setTag(t,'PlanarConfiguration', Tiff.PlanarConfiguration.Chunky)

Create a structure with fields named after TIFF tags and assign values to the fields. Pass this structure to the setTag method to set the values of these tags.

tagStruct.BitsPerSample = 8;
tagStruct.SamplesPerPixel = 3;
tagStruct.TileWidth = 128;
tagStruct.TileLength = 128;
tagStruct.Compression = Tiff.Compression.JPEG;
tagStruct.Software = 'MATLAB';

Write the image data to the TIFF file.



This method corresponds to the TIFFSetField function in the LibTIFF C API. To use this method, you must be familiar with the TIFF specification and technical notes. View this documentation at LibTIFF - TIFF Library and Utilities.

Was this topic helpful?