imwrite(A,filename) writes image data A to the file specified by filename, inferring the file format from the extension. imwrite creates the new file in your current folder. The bit depth of the output image depends on the data type of A and the file format. For most formats:
If A is of data type uint8, then imwrite outputs 8-bit values.
If A is of data type uint16 and the output file format supports 16-bit data (JPEG, PNG, and TIFF), then imwrite outputs 16-bit values. If the output file format does not support 16-bit data, then imwrite returns an error.
If A is a grayscale or RGB color image of data type double or single, then imwrite assumes that the dynamic range is [0,1] and automatically scales the data by 255 before writing it to the file as 8-bit values. If the data in A is single, convert A to double before writing to a GIF or TIFF file.
If A is of data type logical, then imwrite assumes that the data is a binary image and writes it to the file with a bit depth of 1, if the format allows it. BMP, PNG, or TIFF formats accept binary images as input arrays.
If A contains indexed image data, you should additionally specify the map input argument.
imwrite(A,filename) imwrite(A,map,filename) imwrite(___,fmt) imwrite(___,Name,Value)
%Write a 50-by-50 array of grayscale values to a PNG file in the current folder.% A = rand(50); imwrite(A,'myGray.png')