Here a few tips that should help you get started using MATLAB programs for image processing. This list of tips assumes that you are knowledgeable about using Matlab for DSP. If not, click here. For even more basic information about Matlab, refer to the Matlab Primer.


The Image Processing Toolbox extends the basic capabilities of Matlab by providing a number of specialized I/O, display, and processing functions for images and image processing. Type "help images" at the Matlab prompt to get a listing of the functions available.


An image is stored as a matrix using standard Matlab matrix conventions. There are five basic types of images supported by Matlab:

  1. Indexed images
  2. Intensity images
  3. Binary images
  4. RGB images
  5. 8-bit images
To learn the specifics of each of these, see the Image Processing Toolbox manual. These image types are primarily for the purpose of display. They do not constrain the values of an image that can be processed using general image processing techniques in Matlab. An exception is uint8, the data type for 8-bit images. See "help uint8" for more details. Ordinarily, image coordinates use the same conventions as matrix coordinates, with the first argument referring to row # and the second to column #. The origin is the upper left corner of the image. In Matlab, the origin is (1,1). When Matlab asks for x and y coordinates, x is considered to be to the right and y is considered to be down.


The Image Processing Toolbox provides functions imread and imwrite that will read and write several standard image types. Type "help imread" and "help imwrite" to get more information.


To set the default colormap, use colormap. Ordinarily, you should use the colormap gray(256) for 8-bit grayscale images. Use imshow(X) to display images after setting a default colormap. See the help on imshow for other usages. To force the window to make one screen pixel the same size as one image pixel, use truesize. You can display multiple images by either creating multiple figures with the figure command or by putting multiple images in the same figure with the subplot command.



Image reshaping

Sometimes it is convenient to represent an image as a vector rather than as a matrix. If I is an image in matrix form,
Iv = I(:);
will create a vector Iv whose entries are the stacked columns of I. To stack rows, type
It = I'; Iv = It(:);
To return a vector to matrix form, use reshape.

Block processing

If you want to divide an image into blocks and process each block individually, you can use the function blkproc. This function will allow you to process distinct blocks as well as overlapping blocks. With a little creativity, this function can be used to eliminate many loops that would otherwise be necessary. Some related functions are im2col, col2iml, and colfilt.

Function functions

There are a number of functions that take other functions as arguments and apply them in a specific way to an image. See blkproc, nlfilter, colfilt, and mfilter2 for details.

N-dimensional arrays

Matlab 5.0 allows you to create and manipulate N-dimensional arrays. In most cases, the syntax is a straightforward extension of matrix syntax. For example, to create a 3x3x2 array of ones, use
x = ones(3,3,2);

Stanley J. Reeves
Last modified: Wed Dec 31 12:58:52 CST 1997