Images in MATLAB
The basic data structure in MATLAB® is the matrix, a set of elements arranged by rows and columns in a grid. The matrix is naturally suited to represent an image, a set of numeric color or intensity values arranged in a grid of pixels.
MATLAB represents grayscale images as two-dimensional matrices. Each element of the matrix corresponds to a single discrete pixel in the displayed image. For example, an image composed of 200 rows and 300 columns of pixels would be stored in MATLAB as a 200-by-300 matrix.
MATLAB represents color images, or RGB images, using a three-dimensional array. The first two dimensions are the row and column index of the pixel. The third dimension stores the color information. For RGB images, 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 images in MATLAB similar to working with any other type of numeric data, and makes the full power of MATLAB available for image processing applications.
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 I
.
I(2,15)
For more information on how Image Processing Toolbox™ assigns pixel indices and how to relate pixel indices to continuous spatial coordinates, see Image Coordinate Systems.