|On this page…|
The Image Processing Toolbox™ software defines four basic types of images, summarized in the following table. These image types determine the way MATLAB® interprets data matrix elements as pixel intensity values. For information about converting between image types, see Converting Between Image Types.
Logical array containing only 0s and 1s, interpreted as black and white, respectively. See Binary Images for more information.
Array of class logical, uint8, uint16, single, or double whose pixel values are direct indices into a colormap. The colormap is an m-by-3 array of class double.
For single or double arrays, integer values range from [1, p]. For logical, uint8, or uint16 arrays, values range from [0, p-1]. See Indexed Images for more information.
Array of class uint8, uint16, int16, single, or double whose pixel values specify intensity values.
For single or double arrays, values range from [0, 1]. For uint8, values range from [0,255]. For uint16, values range from [0, 65535]. For int16, values range from [-32768, 32767]. See Grayscale Images for more information.
m-by-n-by-3 array of class uint8, uint16, single, or double whose pixel values specify intensity values.
For single or double arrays, values range from [0, 1]. For uint8, values range from [0, 255]. For uint16, values range from [0, 65535]. See Truecolor Images for more information.
In a binary image, each pixel assumes one of only two discrete values: 1 or 0. A binary image is stored as a logical array. By convention, this documentation uses the variable name BW to refer to binary images.
The following figure shows a binary image with a close-up view of some of the pixel values.
Pixel Values in a Binary Image
An indexed image consists of an array and a colormap matrix. The pixel values in the array are direct indices into a colormap. By convention, this documentation uses the variable name X to refer to the array and map to refer to the colormap.
The colormap matrix is an m-by-3 array of class double containing floating-point values in the range [0,1]. Each row of map specifies the red, green, and blue components of a single color. An indexed image uses direct mapping of pixel values to colormap values. The color of each image pixel is determined by using the corresponding value of X as an index into map.
A colormap is often stored with an indexed image and is automatically loaded with the image when you use the imread function. After you read the image and the colormap into the MATLAB workspace as separate variables, you must keep track of the association between the image and colormap. However, you are not limited to using the default colormap--you can use any colormap that you choose.
The relationship between the values in the image matrix and the colormap depends on the class of the image matrix. If the image matrix is of class single or double, it normally contains integer values 1 through p, where p is the length of the colormap. the value 1 points to the first row in the colormap, the value 2 points to the second row, and so on. If the image matrix is of class logical, uint8 or uint16, the value 0 points to the first row in the colormap, the value 1 points to the second row, and so on.
The following figure illustrates the structure of an indexed image. In the figure, the image matrix is of class double, so the value 5 points to the fifth row of the colormap.
Pixel Values Index to Colormap Entries in Indexed Images
A grayscale image (also called gray-scale, gray scale, or gray-level) is a data matrix whose values represent intensities within some range. MATLAB stores a grayscale image as an individual matrix, with each element of the matrix corresponding to one image pixel. By convention, this documentation uses the variable name I to refer to grayscale images.
The matrix can be of class uint8, uint16, int16, single, or double. While grayscale images are rarely saved with a colormap, MATLAB uses a colormap to display them.
For a matrix of class single or double, using the default grayscale colormap, the intensity 0 represents black and the intensity 1 represents white. For a matrix of type uint8, uint16, or int16, the intensity intmin(class(I)) represents black and the intensity intmax(class(I)) represents white.
The figure below depicts a grayscale image of class double.
Pixel Values in a Grayscale Image Define Gray Levels
A truecolor image is an image in which each pixel is specified by three values — one each for the red, blue, and green components of the pixel's color. MATLAB store truecolor images as an m-by-n-by-3 data array that defines red, green, and blue color components for each individual pixel. Truecolor images do not use a colormap. The color of each pixel is determined by the combination of the red, green, and blue intensities stored in each color plane at the pixel's location.
Graphics file formats store truecolor images as 24-bit images, where the red, green, and blue components are 8 bits each. This yields a potential of 16 million colors. The precision with which a real-life image can be replicated has led to the commonly used term truecolor image.
A truecolor array can be of class uint8, uint16, single, or double. In a truecolor array of class single or double, each color component is a value between 0 and 1. A pixel whose color components are (0,0,0) is displayed as black, and a pixel whose color components are (1,1,1) is displayed as white. The three color components for each pixel are stored along the third dimension of the data array. For example, the red, green, and blue color components of the pixel (10,5) are stored in RGB(10,5,1), RGB(10,5,2), and RGB(10,5,3), respectively.
The following figure depicts a truecolor image of class double.
The Color Planes of a Truecolor Image
To determine the color of the pixel at (2,3), you would look at the RGB triplet stored in (2,3,1:3). Suppose (2,3,1) contains the value 0.5176, (2,3,2) contains 0.1608, and (2,3,3) contains 0.0627. The color for the pixel at (2,3) is
0.5176 0.1608 0.0627
To further illustrate the concept of the three separate color planes used in a truecolor image, the code sample below creates a simple image containing uninterrupted areas of red, green, and blue, and then creates one image for each of its separate color planes (red, green, and blue). The example displays each color plane image separately, and also displays the original image.
RGB=reshape(ones(64,1)*reshape(jet(64),1,192),[64,64,3]); R=RGB(:,:,1); G=RGB(:,:,2); B=RGB(:,:,3); imshow(R) figure, imshow(G) figure, imshow(B) figure, imshow(RGB)
The Separated Color Planes of an RGB Image
Notice that each separated color plane in the figure contains an area of white. The white corresponds to the highest values (purest shades) of each separate color. For example, in the Red Plane image, the white represents the highest concentration of pure red values. As red becomes mixed with green or blue, gray pixels appear. The black region in the image shows pixel values that contain no red values, i.e., R == 0.