www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/WriteImageDataExample.m

    %% Write Image Data  
% Write 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. 
setTag(t,'ImageLength',size(imdata,1))
setTag(t,'ImageWidth',size(imdata,2))
setTag(t,'Photometric',Tiff.Photometric.RGB)
setTag(t,'BitsPerSample',8)
setTag(t,'SamplesPerPixel',size(imdata,3))
setTag(t,'TileWidth',128)
setTag(t,'TileLength',128)
setTag(t,'Compression',Tiff.Compression.JPEG)
setTag(t,'PlanarConfiguration',Tiff.PlanarConfiguration.Chunky)
setTag(t,'Software','MATLAB')  

%% 
% Write the image data to the TIFF file. 
write(t,imdata)
close(t)