Display Images

Image Data

You can display a 2-D numeric arrays as an image. In images, the array elements determine brightness or color of the images. For example, load an image array and its colormap:

load durer
Name          Size         Bytes  Class

  X           648x509      2638656  double array
  caption     2x28             112  char array
  map         128x3           3072  double array

load the file durer.mat, adding three variables to the workspace. The array X is a 648-by-509 matrix and map is a 128-by-3 array that is the colormap for this image.

MAT-files, such as durer.mat, are binary files that provide a way to save MATLAB® variables.

The elements of X are integers between 1 and 128, which serve as indices into the colormap, map. To display the image, use the imshow function:


reproduces Albrecht Dürer's etching.

Reading and Writing Images

You can read standard image files (TIFF, JPEG, PNG, and so on, using the imread function. The type of data returned by imread depends on the type of image you are reading.

You can write MATLAB data to a variety of standard image formats using the imwrite function.

Was this topic helpful?