Image Processing Toolbox | ![]() ![]() |
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. This example loads an image of a clown from a MAT-file, and then creates a BMP file containing the clown image.
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')
For some graphics formats, you can specify additional parameters. One of the additional parameters for PNG files sets the bit depth. This example writes an intensity image I
to a 4-bit PNG file.
The bit depths and image types supported for each format are shown in the reference pages for imwrite
.
This example writes an image A
to a JPEG file with a compression quality setting of 100 (the default is 75).
Output File Storage Classes
imwrite
uses the following rules to determine the storage class used in the output image.
See the reference entry for imwrite
for more information.
![]() | Reading a Graphics Image | Querying a Graphics File | ![]() |