%% Write Image Data to TIFF File
% Write a RGB image and multiple tag values that characterize the image to a new TIFF file.
% Load the image data and display the image.

load('peppers_RGB.mat');
imshow(RGB);
title('Peppers Image (RGB)');

% Create a Tiff object to write the image data to a TIFF file.

t = Tiff('myfile.tif','w');  

% Use the tagstruct structure to define multiple tag values that characterize the image.

tagstruct.ImageLength = size(RGB,1); 
tagstruct.ImageWidth = size(RGB,2);
tagstruct.Photometric = Tiff.Photometric.RGB;
tagstruct.BitsPerSample = 8;
tagstruct.SamplesPerPixel = 3;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky; 
tagstruct.Software = 'MATLAB'; 

% Set the tag values for the Tiff object.

setTag(t,tagstruct)

% Write image data to the file and then close the Tiff object.

write(t,RGB);
close(t);

%
% Copyright 2012 The MathWorks, Inc.