www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SetTagValuesExample.m
%% 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. setTag(t,Tiff.TagID.ImageLength,size(imdata,1)) setTag(t,Tiff.TagID.ImageWidth,size(imdata,2)) %% % 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'; setTag(t,tagStruct) %% % Write the image data to the TIFF file. write(t,imdata) close(t)