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

    %% Specify Tiff object properties and describe alpha channel  

%% 
% Create an array of data, |data|, that contains colormetric channels and
% an alpha channel. 
rgb = imread('example.tif');
numrows = size(rgb,1);
numcols = size(rgb,2);
alpha = 255*ones([numrows numcols], 'uint8');
data = cat(3,rgb,alpha);  

%% 
% Create a |Tiff| object, |t|, and set the object properties. Set the value
% of the |ExtraSamples| tag because the data contains the alpha channel
% in addition to the colormetric channels. 
t = Tiff('myfile.tif','w');
t.setTag('Photometric',Tiff.Photometric.RGB);
t.setTag('Compression',Tiff.Compression.None);
t.setTag('BitsPerSample',8);
t.setTag('SamplesPerPixel',4);
t.setTag('SampleFormat',Tiff.SampleFormat.UInt);
t.setTag('ExtraSamples',Tiff.ExtraSamples.Unspecified);
t.setTag('ImageLength',numrows);
t.setTag('ImageWidth',numcols);
t.setTag('TileLength',32);
t.setTag('TileWidth',32);
t.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);  

%% 
% Write the data to the |Tiff| object. 
t.write(data);
t.close();