imfinfo

Returns information about an image file.

Category: Data Import and Analysis > Data Import and Export

Syntax

info = imfinfo(filename)

Returns a struct describing the image in the file.

Description

imfinfo reads only the file header, so it can be used to check the size of an image before loading it with imread. ColorType is one of 'grayscale', 'truecolor' or 'indexed', and BitDepth counts the bits per pixel, across all channels.

Input arguments

filename
Image file name.

Output arguments

info
Struct with fields including Filename, Format, Width, Height, BitDepth and ColorType.

Example

Grayscale and color images

imwrite(uint8([0 50; 100 255]), 'g.png');
imwrite(zeros(3, 4, 3, 'uint8'), 'c.png');
a = imfinfo('g.png');
b = imfinfo('c.png');
fprintf('%s %dx%d %d-bit %s\n', a.Format, a.Width, a.Height, a.BitDepth, a.ColorType);
fprintf('%s %dx%d %d-bit %s\n', b.Format, b.Width, b.Height, b.BitDepth, b.ColorType);
Output
png 2x2 8-bit grayscale
png 4x3 24-bit truecolor

See also

imread imwrite size audioinfo