MATLAB Function Reference
  Go to function:
    Search    Help Desk 
imwrite    Examples   See Also

Write an image to a graphics file

Synopsis

Description

imwrite(A,filename,fmt) writes the image in A to filename. filename is a string that specifies the name of the output file, and fmt is a string that specifies the format of the file. If A is a grayscale intensity image or a truecolor (RGB) image of class uint8, imwrite writes the actual values in the array to the file. If A is of class double, imwrite rescales the values in the array before writing, using uint8(round(255*A)). This operation converts the floating-point numbers in the range [0, 1] to 8-bit integers in the range [0, 255].

This table lists the possible values for fmt:

Format
File type
'bmp'
Windows Bitmap (BMP)
'hdf'
Hierarchical Data Format (HDF)
'jpg' or 'jpeg'
Joint Photographers Expert Group (JPEG)
'pcx'
Windows Paintbrush (PCX)
'tif' or 'tiff'
Tagged Image File Format (TIFF)
'xwd'
X Windows Dump (XWD)

imwrite(X,map,filename,fmt) writes the indexed image in X, and its associated colormap map, to filename. If X is of class uint8, imwrite writes the actual values in the array to the file. If X is of class double, imwrite offsets the values in the array before writing, using uint8(X-1). map must be of class double; imwrite rescales the values in map using uint8(round(255*map)).

imwrite(...,filename) writes the image to filename, inferring the format to use from the filename's extension. The extension must be one of the legal values for fmt.

imwrite(...,Parameter,Value,...) specifies parameters that control various characteristics of the output file. Parameters are currently supported for HDF, JPEG, and TIFF files.

This table describes the available parameters for HDF files:

Parameter
Values
Default
'Compression'
One of these strings: 'none', 'rle', 'jpeg'
'rle'
'Quality'
A number between 0 and 100; parameter applies only if 'Compression' is 'jpeg'; higher numbers mean quality is better (less image degradation due to compression), but the resulting file size is larger
75
'WriteMode'
One of these strings: 'overwrite', 'append'
'overwrite'

This table describes the available parameters for JPEG files:

Parameter
Values
Default
'Quality'
A number between 0 and 100; higher numbers mean quality is better (less image degradation due to compression), but the resulting file size is larger
75

This table describes the available parameters for TIFF files:

Parameter
Values
Default
'Compression'
One of these strings: 'none', 'packbits', 'ccitt'; 'ccitt' is valid for binary images only
'ccitt' for binary images; 'packbits' for all other images

'Description'
Any string; fills in the ImageDescription field returned by imfinfo
empty
'Resolution'
A scalar value that is used for the XResolution and YResolution tags in the output file
72

This table summarizes the types of images that imwrite can write:

Format
Variants
BMP
8-bit uncompressed images with associated colormap; 24-bit uncompressed images
HDF
8-bit raster image datasets, with or without associated colormap; 24-bit raster image datasets
JPEG
Baseline JPEG images (Note: indexed images are converted to RGB before writing out JPEG files, because the JPEG format does not support indexed images)
PCX
8-bit images
TIFF
Baseline TIFF images, including 1-bit, 8-bit, and 24-bit uncompressed images; 1-bit, 8-bit, and 24-bit images with packbit compression; 1-bit images with CCITT compression
XWD
8-bit ZPixmaps

Example

See Also

imfinfo     Return information about a graphics file

imread      Read image from graphics file



[ Previous | Help Desk | Next ]