MATLAB Function Reference Previous page   Next Page
image

Display image object

Syntax

Description

image creates an image graphics object by interpreting each element in a matrix as an index into the figure's colormap or directly as RGB values, depending on the data specified.

The image function has two forms:

You can specify properties as property name/property value pairs, structure arrays, and cell arrays (see set and get for examples of how to specify these data types).

image(C) displays matrix C as an image. Each element of C specifies the color of a rectangular segment in the image.

image(x,y,C), where x and y are two-element vectors, specifies the range of the x- and y-axis labels, but produces the same image as image(C). This can be useful, for example, if you want the axis tick labels to correspond to real physical dimensions represented by the image.

image(x,y,C,'PropertyName',PropertyValue,...) is a high-level function that also specifies property name/property value pairs. This syntax calls newplot before drawing the image.

image('PropertyName',PropertyValue,...) is the low-level syntax of the image function. It specifies only property name/property value pairs as input arguments.

handle = image(...) returns the handle of the image object it creates. You can obtain the handle with all forms of the image function.

Remarks

Image data can be either indexed or true color. An indexed image stores colors as an array of indices into the figure colormap. A true color image does not use a colormap; instead, the color values for each pixel are stored directly as RGB triplets. In MATLAB, the CData property of a true color image object is a three-dimensional (m-by-n-by-3) array. This array consists of three m-by-n matrices (representing the red, green, and blue color planes) concatenated along the third dimension.

The imread function reads image data into MATLAB arrays from graphics files in various standard formats, such as TIFF. You can write MATLAB image data to graphics files using the imwrite function. imread and imwrite both support a variety of graphics file formats and compression schemes.

When you read image data into MATLAB using imread, the data is usually stored as an array of 8-bit integers. However, imread also supports reading 16-bit-per-pixel data from TIFF and PNG files. These are more efficient storage methods than the double-precision (64-bit) floating-point numbers that MATLAB typically uses. However, it is necessary for MATLAB to interpret 8-bit and 16-bit image data differently from 64-bit data. This table summarizes these differences.

Image Type
Double-Precision Data
(double Array)

8-Bit Data (uint8 Array)
16-Bit Data (uint16 Array)

Indexed (colormap)
Image is stored as a two-dimensional (m-by-n) array of integers in the range [1, length(colormap)]; colormap is an m-by-3 array of floating-point values in the range [0, 1].
Image is stored as a two-dimensional (m-by-n) array of integers in the range [0, 255] (uint8) or [0, 65535] (uint16); colormap is an m-by-3 array of floating-point values in the range [0, 1].
True color (RGB)
Image is stored as a three-dimensional (m-by-n-by-3) array of floating-point values in the range [0, 1].
Image is stored as a three-dimensional (m-by-n-by-3) array of integers in the range [0, 255] (uint8) or [0, 65535] (uint16).

Indexed Images

In an indexed image of class double, the value 1 points to the first row in the colormap, the value 2 points to the second row, and so on. In a uint8 or uint16 indexed image, there is an offset; the value 0 points to the first row in the colormap, the value 1 points to the second row, and so on.

If you want to convert a uint8 or uint16 indexed image to double, you need to add 1 to the result. For example,

or

To convert from double to uint8 or uint16, you need to first subtract 1, and then use round to ensure all the values are integers.

or

When you write an indexed image using imwrite, MATLAB automatically converts the values if necessary.

Colormaps

Colormaps in MATLAB are always m-by-3 arrays of double-precision floating-point numbers in the range [0, 1]. In most graphics file formats, colormaps are stored as integers, but MATLAB does not support colormaps with integer values. imread and imwrite automatically convert colormap values when reading and writing files.

True Color Images

In a true color image of class double, the data values are floating-point numbers in the range [0, 1]. In a true color image of class uint8, the data values are integers in the range [0, 255], and for true color images of class uint16 the data values are integers in the range [0, 65535].

If you want to convert a true color image from one data type to the other, you must rescale the data. For example, this statement converts a uint8 true color image to double.

or for uint16 images,

This statement converts a double true color image to uint8:

or to obtain uint16 images, type

When you write a true color image using imwrite, MATLAB automatically converts the values if necessary.

Object Hierarchy

Setting Default Properties

You can set default image properties on the axes, figure, and root levels:

where Property is the name of the image property and PropertyValue is the value you are specifying. Use set and get to access image properties.

See Also

colormap, imfinfo, imread, imwrite, pcolor, newplot, surface

Displaying Bit-Mapped Images

Bit-Mapped Images for related functions

Image Properties for property descriptions


Previous page  imag Image Properties Next page

© 1994-2005 The MathWorks, Inc.