Image Processing Toolbox User's Guide |
Writing a Graphics Image
The function imwrite
writes an image to a graphics file in one of the supported formats. The most basic syntax for imwrite
takes the image variable name and a filename. If you include an extension in the filename, MATLAB infers the desired file format from it. (For more information, see the reference entry for the imwrite
function.)
This example loads the indexed image X
from a MAT-file, clown.mat
, that contains the data matrix and the associated colormap and then writes the image to a BMP file.
load clown whos Name Size Bytes Class X 200x320 512000 double array caption 2x1 4 char array map 81x3 1944 double array Grand total is 64245 elements using 513948 bytes imwrite(X,map,'clown.bmp')
Specifying Additional Format-Specific Parameters
When using imwrite
with some graphics formats, you can specify additional parameters. For example, with PNG files, you can specify the bit depth as an additional parameter. This example writes an grayscale image I
to a 4-bit PNG file.
This example writes an image A
to a JPEG file, using an additional parameter to specify the compression quality parameter.
For more information about the additional parameters associated with certain graphics formats, see the reference pages for imwrite
.
Reading and Writing Binary Images in 1-Bit Format
In certain file formats, a binary image can be stored in a 1-bit format. If the file format supports it, MATLAB writes binary images as 1-bit images by default. When you read in a binary image in 1-bit format, MATLAB represents it in the workspace as a logical
array.
This example reads in a binary image and writes it as a TIFF file. Because the TIFF format supports 1-bit images, the file is written to disk in 1-bit format.
To verify the bit depth of test.tif
, call imfinfo
and check the BitDepth
field.
Determining the Storage Class of the Output File
imwrite
uses the following rules to determine the storage class used in the output image.
Reading a Graphics Image | Querying a Graphics File |
© 1994-2005 The MathWorks, Inc.