FUNCTION REFERENCE

imread

Read a PNG, JPEG, BMP or TIFF image.

Read a PNG, JPEG, BMP or TIFF image.

Syntax

A = imread(filename)

Syntax

[X, map, alpha] = imread(filename, fmt)

Grayscale images return M-by-N uint8 or uint16 (1-bit PNG logical, 2- and 4-bit PNG scaled to uint8); truecolor images (8 or 16 bits per sample) return M-by-N-by-3 uint8 or uint16; indexed PNG and BMP images return zero-based uint8 indices and the colormap. The third output is the alpha channel of a PNG with alpha (gray or RGB) or of a TIFF with an extra sample, otherwise []. The format comes from the file contents; fmt only checks it. Images larger than the 16777216-element array limit are refused before decoding.

Example

f=[tempname(pwd) '.png']; imwrite(uint8([1 2; 3 4]), f); A=imread(f); delete(f); A   % [1 2; 3 4] uint8

Example

f=[tempname(pwd) '.png']; imwrite(uint8(cat(3, [255 0], [0 255], [0 0])), f); A=imread(f); delete(f); size(A)   % [1 2 3]

Example

f=[tempname(pwd) '.tif']; imwrite(uint16(magic(3)), f); A=imread(f); delete(f); class(A)   % uint16

Differences from MATLAB: GIF and the other formats are not supported yet, nor interlaced PNG, multi-page TIFF, CMYK or 12-bit JPEG, or the 'Index', 'Frames' and 'PixelRegion' options. JPEG, BMP and TIFF need the desktop build. A 1-bit BMP or TIFF is read as uint8 (MATLAB returns logical).

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.