Working with Images in MATLAB Graphics
What Is Image Data?
The basic MATLAB® data structure is the array, an ordered set of real or complex elements. An array is naturally suited to the representation of images, real-valued, ordered sets of color or intensity data. (An array is suited for complex-valued images.)
In the MATLAB workspace, most images are represented as two-dimensional arrays (matrices), in which each element of the matrix corresponds to a single pixel in the displayed image. For example, an image composed of 200 rows and 300 columns of different colored dots stored as a 200-by-300 matrix. Some images, such as RGB, require a three-dimensional array, where the first plane in the third dimension represents the red pixel intensities, the second plane represents the green pixel intensities, and the third plane represents the blue pixel intensities.
This convention makes working with graphics file format images similar to working with any other type of matrix data. For example, you can select a single pixel from an image matrix using normal matrix subscripting:
This command returns the value of the pixel at row 2, column
15 of the image
The following sections describe the different data and image types, and give details about how to read, write, work with, and display graphics images; how to alter the display properties and aspect ratio of an image during display; how to print an image; and how to convert the data type or graphics format of an image.
MATLAB math supports three different numeric classes for image display:
double-precision floating-point (
16-bit unsigned integer (
8-bit unsigned integer (
The image display commands interpret data values differently depending on the numeric class the data is stored in. 8-Bit and 16-Bit Images includes details on the inner workings of the storage for 8- and 16-bit images.
By default, most data occupy arrays of class
The data in these arrays is stored as double-precision (64-bit) floating-point
numbers. All MATLAB functions and capabilities work with these
For images stored in one of the graphics file formats supported
by MATLAB functions, however, this data representation is not
always ideal. The number of pixels in such an image can be very large;
for example, a 1000-by-1000 image has a million pixels. Since at least
one array element represents each pixel , this image requires about
8 megabytes of memory if it is stored as class
To reduce memory requirements, you can store image data in arrays
data in these arrays is stored as 8-bit or 16-bit unsigned integers.
These arrays require one-eighth or one-fourth as much memory as data
MATLAB input functions read the most commonly used bit
depths (bits per pixel) of any of the supported graphics file formats.
When the data is in memory, it can be stored as
double. For details on which bit depths are
appropriate for each supported format, see
Supported Image Formats
MATLAB commands read, write, and display several types of graphics file formats for images. As with MATLAB generated images, once a graphics file format image is displayed, it becomes an image object. MATLAB supports the following graphics file formats, along with others:
For more information about the bit depths and image types supported
for these formats, see