setTag
Set value of tag
Description
Examples
Set Tag Values
You can set tags for a TIFF file by specifying the tag name, the tag numeric identifier, or by specifying a structure of multiple tag names and values.
Create a new TIFF file, write image data, and then set tag values in different ways.
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 tag name.
setTag(t,'Photometric',Tiff.Photometric.RGB) setTag(t,'PlanarConfiguration',Tiff.PlanarConfiguration.Chunky)
Set tag values by specifying the numeric tag identifier. Use the fields of the Tiff.TagID
structure to obtain the tag IDs. For instance, the Tiff.TagID.ImageLength
contains the numeric identifier for the ImageLength
tag.
setTag(t,Tiff.TagID.ImageLength,size(imdata,1)) setTag(t,Tiff.TagID.ImageWidth,size(imdata,2))
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';
setTag(t,tagStruct)
Write the image data to the TIFF file and close the Tiff
object.
write(t,imdata); close(t);
Input Arguments
t
— Tiff object
Tiff
object
Tiff
object representing a TIFF file. Use the Tiff
function to create the object.
tagID
— Tag ID
character vector | string scalar | numeric identifier
Tag ID of a Tiff
object, specified as a character vector or string scalar,
or a numeric identifier.
For example, you can specify tagId
for the ImageWidth
tag as any of these:
Character vector or string scalar containing the tag name
'ImageWidth'
Numeric identifier
256
for theImageWidth
tag defined by the TIFF specificationField of the
Tiff.TagID
structureTiff.TagID.ImageWidth
.
The names of the fields of the Tiff.TagID
structure are valid tag
names that contain the corresponding tag numeric identifiers. For instance, the field
Tiff.TagID.ImageWidth
contains the value 256
.
To see a list of all the tags along with their numeric identifiers, type
Tiff.TagID
in the command window.
Example: 'ImageWidth'
Example: 256
Example: Tiff.TagID.ImageWidth
Data Types: double
| char
| string
tagValue
— Tag value
numeric identifier | character vector | string scalar
Tag value, specified as a valid numeric identifier, or a character vector or string scalar.
For example, you can specify tagValue
for the
PlanarConfiguration
tag in one of these ways:
Numeric identifier
2
that sets the value of thePlanarConfiguration
tag indicating a separate configurationField of the
Tiff.PlanarConfiguration
structureTiff.PlanarConfiguration.Separate
The Tiff.PlanarConfiguration
structure contains the
numeric identifiers for all the valid values for the
PlanarConfiguration
tag. To see all the valid tag
values for any given tag, type Tiff.TagName
in the
command window. For example, to see all the valid values for the
Photometric
tag, type
Tiff.Photometric
in the command window.
Data Types: double
| char
| string
tagStruct
— Multiple tags
structure
Multiple tags, specified as a structure containing tag names and their
corresponding values. The names of fields in tagstruct
must be the name of supported TIFF tags, and their corresponding values must
be valid TIFF tag values.
Data Types: struct
Tips
If you are modifying a tag rather than creating it, then you must use the
rewriteDirectory
method after using thesetTag
method.
Algorithms
References
This function corresponds to the TIFFSetField
function in the
LibTIFF C API. To use this function, you must be familiar with the TIFF
specification and technical notes. View this documentation at LibTIFF - TIFF Library and Utilities.
Version History
Introduced in R2009b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)