| MATLAB Function Reference | Search  Help Desk |
| imwrite | Examples See Also |
Write an image to a graphics file
Synopsis
imwrite(A,filename,fmt) imwrite(X,map,filename,fmt) imwrite(...,filename) imwrite(...,Param1,Val1,Param2,Val2...)
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].
imwrite(X,map,filename,fmt) writes the indexed image in X and its associated colormap map to filename. If X is of class uint8 or uint16, 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). (See note below for an exception.) map must be a valid MATLAB colormap of class double; imwrite rescales the values in map using uint8(round(255*map)). Note that most image file formats do not support colormaps with more than 256 entries.
Note:
double, and you specify PNG as the output format and a bit depth of 16 bpp, the values in the array will be offset using uint16(X-1).
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(...,Param1,Val1,Param2,Val2...) specifies parameters that control various characteristics of the output file. Parameter settings can currently be made for HDF, JPEG, and TIFF files. For example, if you are writing a JPEG file, you can set the "quality" of the JPEG compression. For the full list of parameters available per format, see the tables of parameters.
filename is a string that specifies the name of the output file, and fmt is a string that specifies the format of the file.
This table lists the possible values for fmt:
This table describes the available parameters for HDF 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 |
imwrite can write:Class Support
Most of the supported image file formats storeuint8 data. PNG and TIFF additionally support uint16 data. For grayscale and RGB images, if the data array is double, the assumed dynamic range is [0,1]. The data array is automatically scaled by 255 before being written out as uint8. If the data array is uint8 or uint16 (PNG and TIFF only), then it is written out without scaling as uint8 or uint16, respectively.
Example
imwrite(X,map,'flowers.hdf','Compression','none',... 'WriteMode','append')
See Also
fwrite, imfinfo, imread