Main Content

imformats

Manage image file format registry

Description

imformats displays a table of information listing all the values in the MATLAB® file format registry. This registry determines which file formats the imfinfo, imread, and imwrite functions support.

formatStruct = imformats(fmt) searches the known formats in the MATLAB file format registry for the format associated with the file name extension specified by fmt. If found, formatStruct is a structure containing the characteristics and function names associated with the format. Otherwise, formatStruct is an empty structure.

example

registry = imformats returns a structure array, registry, containing all the values in the MATLAB file format registry.

registry = imformats(formatStruct) sets the MATLAB file format registry for the current MATLAB session to the values in formatStruct. The output structure, registry, contains the new registry settings. Use this syntax to replace image file format support.

Incorrect use of imformats to specify values in the MATLAB file format registry can result in the inability to load any image files. To return the file format registry to a working state, use imformats with the 'factory' input.

registry = imformats('add',formatStruct) adds the values in formatStruct to the file format registry. Use this syntax to add image file format support.

example

registry = imformats('remove',fmt) removes the format with the extension specified by fmt from the file format registry. Use this syntax to remove image file format support.

example

registry = imformats('update',fmt,formatStruct) changes the format registry values for the format with extension fmt to have the values specified by formatStruct.

example

registry = imformats('factory') resets the MATLAB file format registry to the default format registry values. This removes any user-specified settings.

Examples

collapse all

Determine if the file format associated with the .bmp file extension is in the image file format registry.

formatStruct = imformats('bmp')
formatStruct = struct with fields:
            ext: {'bmp'}
            isa: @isbmp
           info: @imbmpinfo
           read: @readbmp
          write: @writebmp
          alpha: 0
    description: 'Windows Bitmap'

formatStruct is a non-empty structure, so the BMP file format is in the registry.

Add a hypothetical file format, ABC, to the image file format registry. Update, and then remove the format.

Create a structure with seven fields, defining values for the new format.

formatStruct = struct('ext','abc','isa',@isabc,...
    'info',@abcinfo,'read',@readabc,'write','',...
    'alpha',0,'description','My ABC Format')
formatStruct = struct with fields:
            ext: 'abc'
            isa: @isabc
           info: @abcinfo
           read: @readabc
          write: ''
          alpha: 0
    description: 'My ABC Format'

formatStruct is a 1-by-1 structure with seven fields. In this example, the write field is empty.

Add the new format to the file format registry.

registry = imformats('add',formatStruct);

Redefine the format associated with the extension, abc, by adding a value for the write field. Then, update the registry value for the format.

formatStruct2 = struct('ext','abc','isa',@isabc,...
    'info',@abcinfo,'read',@readabc,'write',@writeabc,...
    'alpha',0,'description','My ABC Format');

registry = imformats('update','abc',formatStruct2);

Remove the format with the extension, abc, from the file format registry.

registry = imformats('remove','abc');

Input Arguments

collapse all

File format registry values, specified as a structure array with the following 7 fields.

Field

Description

Value

ext

File name extensions that are valid for this format.

Cell array of character vectors or string array

isa

Name of the function that determines if a file is of a certain format.

Character vector or string scalar, or function handle

info

Name of the function that reads information about a file.

Character vector or string scalar, or function handle

read

Name of the function that reads image data in a file.

Character vector or string scalar, or function handle

write

Name of the function that writes MATLAB data to a file.

Character vector or string scalar, or function handle

alpha

Presence or absence of an alpha channel.

1 if the format has an alpha channel; otherwise it is 0.

description

Text description of the file format.

Character vector or string scalar

The values for the isa, info, read, and write fields must be either functions on the MATLAB search path or function handles.

Data Types: struct

File format extension, specified as a character vector or string scalar.

Example: 'jpg'

Data Types: char

Output Arguments

collapse all

File format registry, returned as a structure array with the following fields.

Field

Description

Value

ext

File name extensions that are valid for this format.

Cell array of character vectors

isa

Name of the function that determines if a file is of a certain format.

Character vector or function handle

info

Name of the function that reads information about a file.

Character vector or function handle

read

Name of the function that reads image data in a file.

Character vector or function handle

write

Name of the function that writes MATLAB data to a file.

Character vector or function handle

alpha

Presence or absence of an alpha channel.

1 if the format has an alpha channel; otherwise it is 0.

description

Text description of the file format.

Character vector

Note

Use the imread, imwrite, and imfinfo functions to read, write, or get information about an image file when the file format is in the format registry. Do not directly invoke the functions returned in the fields of the registry structure array.

Tips

  • Changes to the format registry do not persist between MATLAB sessions. To have a format always available when you start MATLAB, add the appropriate imformats command to the MATLAB startup file, startup.m. For more information, see startup.

Version History

Introduced before R2006a