imwrite
Write image to graphics file
Syntax
imwrite(A,filename,fmt)
imwrite(X,map,filename,fmt)
imwrite(...,filename)
imwrite(...,Param1,Val1,Param2,Val2...)
Description
imwrite(A,filename,fmt) writes the image A to the file specified by filename in the format specified by fmt.
A can be an M-by-N (grayscale image) or M-by-N-by-3 (truecolor image) array. A cannot be an empty array. If the format specified is TIFF, imwrite can also accept an M-by-N-by-4 array containing color data that uses the CMYK color space. For information about the class of the input array and the output image, see Class Support.
filename is a string that specifies the name of the output file.
fmt can be any of the text strings listed in the table in Supported Formats. This list of supported formats is determined by the MATLAB? image file format registry. See imformats for more information about this registry.
imwrite(X,map,filename,fmt) writes the indexed image in X and its associated colormap map to filename in the format specified by fmt. 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). map must be a valid MATLAB colormap. Note that most image file formats do not support colormaps with more than 256 entries.
When writing multiframe GIF images, X should be an 4-dimensional M-by-N-by-1-by-P array, where P is the number of frames to write.
imwrite(...,filename) writes the image to filename, inferring the format to use from the filename's extension. The extension must be one of the values for fmt, listed in Supported Formats.
imwrite(...,Param1,Val1,Param2,Val2...) specifies parameters that control various characteristics of the output file for HDF, JPEG, PBM, PGM, PNG, PPM, and TIFF files. For example, if you are writing a JPEG file, you can specify the quality of the output image. For the lists of parameters available for each format, see Format-Specific Parameters.