www.gusucode.com > images 案例代码 matlab源码程序 > images/WriteImageDataToFileInGraphicsFormatExample.m
%% Write Image Data to File in Graphics Format % This example shows how to write image data from the MATLAB workspace to a % file in one of the supported graphics file formats using the |imwrite| % function. %% % Load image data into the workspace. This example loads the indexed image % |X| from a MAT-file, |clown.mat|, along with the associated colormap % |map|. % Copyright 2015 The MathWorks, Inc. load clown whos %% % Export the image data as a bitmap file using |imwrite|, specifying the % name of the variable and the name of the output file you want to create. % If you include an extension in the filename, |imwrite| attempts to infer % the desired file format from it. For example, the file extension |.bmp| % specifies the Microsoft Windows Bitmap format. You can also specify the % format explicitly as an argument to |imwrite|. imwrite(X,map,'clown.bmp') %% % Use format-specific parameters with |imwrite| to control aspects of the % export process. For example, with PNG files, you can specify % the bit depth. To illustrate, read an image into the workspace in TIFF % format and note its bit depth. I = imread('cameraman.tif'); s = imfinfo('cameraman.tif'); s.BitDepth %% % Write the image to a graphics file in PNG format, specifying a bit depth % of 4. imwrite(I,'cameraman.png','Bitdepth',4) %% % Check the bit depth of the newly created file. newfile = imfinfo('cameraman.png'); newfile.BitDepth