Documentation Center

  • Trial Software
  • Product Updates


Class: Tiff

Set value of tag




tiffobj.setTag(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.

tiffobj.setTag(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

Set Tag Values

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.

t.setTag('Photometric', Tiff.Photometric.RGB);
t.setTag('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.

See Also

Was this topic helpful?