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.

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.

Storage Class of Image
Storage Class of Output Image File
logical
If the output image file format specified supports 1-bit images, imwrite creates a 1-bit image file.
If the output image file format specified does not support 1-bit images, such as JPEG, imwrite converts the image to a class uint8 intensity image.
uint8
If the output image file format specified supports 8-bit images, imwrite creates an 8-bit image file.
uint16
If the output image file format specified supports 16-bit images (PNG or TIFF), imwrite creates a 16-bit image file.
If the output image file format specified does not support 16-bit images, imwrite scales the image data to class uint8 and creates an 8-bit image file.
double
MATLAB scales the image data to uint8 and creates an 8-bit image file because most image file formats use 8-bits.

See the reference entry for imwrite for more information.


  Reading a Graphics Image Querying a Graphics File