imfinfo - Information about graphics file - MATLAB (original) (raw)
Information about graphics file
Syntax
Description
[info](#btm5gek-1-info) = imfinfo([filename](#btm5gek-1%5Fsep%5Fmw%5F3c509488-6925-4904-a5a7-4b420a010c3e))
returns a structure whose fields contain information about the image in the specified graphics file. The format of the file is inferred from its contents.
If filename
is a CUR, GIF, HDF4, ICO, PBM, PGM, PPM, SVS, or TIFF file containing more than one image, then info
is a structure array with one element for each image in the file. For example,info(3)
would contain information about the third image in the file.
If filename
is a HEIF or HEIC file containing more than one image, then info
returns a structure whose fields contain information about the primary image in the graphics file. (since R2025a)
[info](#btm5gek-1-info) = imfinfo([filename](#btm5gek-1%5Fsep%5Fmw%5F3c509488-6925-4904-a5a7-4b420a010c3e),[fmt](#btm5gek-1%5Fsep%5Fmw%5Ffadddc0e-e6d8-4592-b3d2-2de376dd7bcd))
additionally looks for a file named_`filename`_._`fmt`_
, if the function cannot find a file named_`filename`_
.
Examples
Find information about a sample image.
info = imfinfo("ngc6543a.jpg");
The info
structure includes these fields: Filename
, FileModDate
, FileSize
, Format
, FormatVersion
, Width
, Height
, BitDepth
, ColorType
, FormatSignature
, NumberOfSamples
, CodingMethod
, CodingProcess
, Comment
, AutoOrientedWidth
, and AutoOrientedHeight
.
To display specific information from the structure, refer to its fields. For example, display the coding method information from the structure.
Input Arguments
Name of the graphics file, specified as a string scalar or character vector.
Depending on the location of your file, filename
can take one of these forms.
Location | Form |
---|---|
Current folder or folder on the MATLAB® path | Specify the name of the file infilename.Example: "myImage.jpg" |
File in a folder | If the file is not in the current folder or in a folder on the MATLAB path, then specify the full or relative path name.Example: "C:\myFolder\myImage.png"Example: "\imgDir\myImage.bmp" |
Uniform resource locator (URL) | If the file is located by an internet URL, thenfilename must contain the protocol type, such as http://.Example: "http://my\_hostname/my\_path/my\_image.jpg" |
Remote location | If the file is stored at a remote location, thenfilename must contain the full path of the file specified as a URL of the form:scheme_name://path_to_file/_my_file.ext_Based on the remote location,scheme_name can be one of the values in this table. Remote Location_scheme_name_Amazon S3™s3Windows Azure® Blob Storagewasb, wasbsHDFS™hdfsFor more information, see Work with Remote Data.Example: "s3://my_bucket/my_path/my_image.heif" |
Image format, specified as a string scalar or character vector indicating the standard file extension. Call imformats to see a list of supported formats and their file extensions.
Example: "png"
Output Arguments
Information about the graphics file, returned as a structure array. The set of fields ininfo
depends on the file and the format of the file. This table describes the fields in the structure.
Field Name | Description | Value |
---|---|---|
Filename | Name of the file. If the file is not in the current folder or is in a remote location,Filename contains the full path or address of the file. | character vector |
FileModDate | Date when the file was last modified. | character vector |
FileSize | Size of the file, in bytes. | integer |
Format | File format, in the form of a file extension. For formats with more than one possible extension (for example, JPEG and TIFF), theimfinfo function returns the first variant in the file format registry. (For more information, see imformats.) | character vector |
FormatVersion | File format version. | character vector or number |
Width | Image width, in pixels. | integer |
Height | Image height, in pixels. (For additional details about BMP files, see Tips.) | integer |
BitDepth | Number of bits per pixel. | integer |
ColorType | Image type. Possible values for ColorType include, but are not limited to, 'truecolor' for a truecolor (RGB) image, 'grayscale' for a grayscale intensity image, and'indexed' for an indexed image. | character vector |
AutoOrientedWidth (since R2024b) | Width of the image after applying the exchangeable image file format (Exif) Orientation tag, in pixels. If the file does not have an ExifOrientation tag, then this field has the same value as the Width field does. | integer |
AutoOrientedHeight (since R2024b) | Height of the image after applying the ExifOrientation tag, in pixels. If the file does not have an Exif Orientation tag, then this field has the same value as theHeight field does. | integer |
Note
When you specify a HEIF or HEIC image file, the structure array includes all fields in the table except the BitDepth
and ColorType
fields.
The info
structure array includes additional fields for some file formats:
- DNG only — The
imfinfo
function returns tags belonging to Adobe® DNG file versions up to and including 1.5 as individual named fields in the output structure. For a complete list of DNG file tags, see chapter 4 of the Adobe Digital Negative (DNG) Specification. - DNG, JPEG, and TIFF only — If filename contains Exif tags, then
info
might includeDigitalCamera
orGPSInfo
(global positioning system information) fields. - GIF only — The
info
structure includes aDelayTime
field that contains a value in hundredths of seconds. - JPEG only
- If
filename
contains embedded Extensible Metadata Platform (XMP) metadata, theninfo
includes anXMPData
field. If the XMP metadata offilename
contains International Press Telecommunications Council (IPTC) data, this data is located in theIptc4xmpCore
(core metadata) andIptc4xmpExt
(extension metadata) subfields of theXMPData
field. - If
filename
contains an ExifOrientation
tag, theninfo
includes anOrientation
field that contains the value of the ExifOrientation
tag.
- If
- JPEG 2000 only — The
info
structure includes aChannelDefinition
field that contains an_m
-by-3 cell array, wherem
_ is the number of rows of image data.- The first column of
ChannelDefinition
reports a channel position as it exists in the file. - The second column of
ChannelDefinition
reports the type of channel. - The third column of
ChannelDefinition
reports the channel mapping.
- The first column of
- TIFF only — The
info
structure includes anOrientation
field that contains the value of the ExifOrientation
tag (or contains the value1
if there is no ExifOrientation
tag).
Tips
- For JPEG, TIFF, HEIF, and HEIC (since R2025a) files, theinfo structure can include an
Orientation
field that contains the value of the ExifOrientation
tag from the image file.
This table shows how the imread function uses the value of the ExifOrientation
tag to transform the image data when theAutoOrient
name-value argument istrue
.Value of Orientation Field Description of Transformation 1 No transformation 2 Reflect about vertical axis 3 Rotate 180° 4 Reflect about vertical axis and then rotate 180° 5 Reflect about vertical axis and then rotate 90° counterclockwise 6 Rotate 90° clockwise 7 Reflect about vertical axis and then rotate 90° clockwise 8 Rotate 90° counterclockwise (since R2024b) - For Adobe DNG files, the
imfinfo
function returns the image dimensions of the preview image in theHeight
andWidth
fields of theinfo
structure. - For BMP files, the
info
structure can contain a negativeHeight
value. The negative value indicates that the origin of the image is in its upper-left corner. In such cases, the actual height of the image in pixels is the absolute value of theHeight
value.
Version History
Introduced before R2006a
You can now use imfinfo to get information about HEIF and HEIC image files.
This functionality requires MATLAB Support for HEIF/HEIC Image Format, which is available only on MATLAB desktop environment. However, you cannot use HEIF and HEIC image files in a standalone application workflow.
To install the support package:
- On the MATLAB Home tab, in theEnvironment section, selectAdd-Ons > Explore Add-Ons.
- In the Add-On Explorer search bar, search for MATLAB Support for HEIF/HEIC Image Format and then click the MATLAB Support for HEIF/HEIC Image Format add-on.
The info
structure includesAutoOrientedWidth
and AutoOrientedHeight
fields.
The imfinfo
function returns XMP metadata embedded in JPEG files in the XMPData
field of the output structure. The function also returns International Press Telecommunications Council (IPTC) metadata embedded in the XMP namespace. The IPTC data is stored in the Iptc4xmpCore
(core metadata) and Iptc4xmpExt
(extension metadata) subfields ofXMPData
.
The imfinfo
function returns information on DNG file tags belonging to versions up to and including 1.5 as individual named fields in the output structure. Previously, information on DNG file tags belonging to versions 1.2 through 1.5 was stored in the UnknownTags
field of the output structure.
If a PGM, PBM, or PPM file has multiple images, then imfinfo
now returns a structure array containing information on those multiple images. Previously, imfinfo
returned a 1-by-1 structure containing information about only the first image.