Documentation Center

  • Trial Software
  • Product Updates

imformats

Manage image file format registry

Syntax

  • imformats
  • formatStruct = imformats(fmt) example
  • registry = imformats
  • registry = imformats(formatStruct)
  • registry = imformats('add',formatStruct) example
  • registry = imformats('remove',fmt) example
  • registry = imformats('update',fmt,formatStruct) example
  • registry = imformats('factory')

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.

example

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.

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.

example

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.

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

Examples

expand all

Determine if File Format Exists in Registry

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

formatStruct = imformats('bmp')
formatStruct = 

            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, Update, or Remove File Format from 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 = 

            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

expand all

formatStruct — File format registry valuesstructure array

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 strings

isa

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

String or function handle

info

Name of the function that reads information about a file.

String or function handle

read

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

String or function handle

write

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

String 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.

String

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

fmt — File format extensionstring

File format extension, specified as a string.

Example: 'jpg'

Data Types: char

Output Arguments

expand all

registry — File format registrystructure array

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 strings

isa

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

String or function handle

info

Name of the function that reads information about a file.

String or function handle

read

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

String or function handle

write

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

String 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.

String

    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.

More About

expand all

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, located in $MATLAB/toolbox/local on UNIX® systems, or $MATLAB\toolbox\local on Windows® systems.

See Also

| | |

Was this topic helpful?