cv.imwrite - MATLAB File Help
cv.imwrite

Saves an image to a specified file

cv.imwrite(filename, img)
cv.imwrite(filename, imgs)
cv.imwrite(filename, img, 'OptionName', optionValue, ...)
success = cv.imwrite(...)

Input

Output

Options

The following format-specific save parameters are currently supported:

For advanced uses, you can directly pass a vector of parameters:

The function cv.imwrite saves the image to the specified file. The image format is chosen based on the filename extension (see cv.imread for the list of extensions). Only 8-bit (or 16-bit unsigned uint16 in case of PNG, JPEG 2000, and TIFF) single-channel or 3-channel (with RGB channel order) images can be saved using this function. If the format, depth or channel order is different, use cv.cvtColor to convert it before saving. Or, use the universal cv.FileStorage I/O functions to save the image to XML or YAML format.

(If the chosen encoder does not support the depth of the input image, the image will be implicitly cast to 8-bit).

If the image cannot be saved (because of IO errors, improper permissions, unsupported or invalid format), the function throws an error.

It is possible to store PNG images with an alpha channel using this function. To do this, create 8-bit (or 16-bit) 4-channel image RGBA, where the alpha channel goes last. Fully transparent pixels should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535. Note: WEBP format can also store images with alpha channel. See rgba_png_demo.m sample for an example.

See also