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

    %% Create YCbCr/JPEG image from RGB data  

%% 
% Get RGB data. 
rgb = imread('example.tif');  

%% 
% Create a |Tiff| object, |t|, and set the object properties. Specify RGB
% input data using the |JPEGColorMode| property. 
t = Tiff('myfile.tif','w');
t.setTag('Photometric',Tiff.Photometric.YCbCr);
t.setTag('Compression',Tiff.Compression.JPEG);
t.setTag('YCbCrSubSampling',[2 2]);
t.setTag('BitsPerSample',8);
t.setTag('SamplesPerPixel',3);
t.setTag('SampleFormat',Tiff.SampleFormat.UInt);
t.setTag('ImageLength',size(rgb,1));
t.setTag('ImageWidth',size(rgb,2));
t.setTag('TileLength',32);
t.setTag('TileWidth',32);
t.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);
t.setTag('JPEGColorMode',Tiff.JPEGColorMode.RGB);
t.setTag('JPEGQuality',75);  

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