Image Processing Toolbox    

Converting Image Types

For certain operations, it is helpful to convert an image to a different image type. For example, if you want to filter a color image that is stored as an indexed image, you should first convert it to RGB format. When you apply the filter to the RGB image, MATLAB filters the intensity values in the image, as is appropriate. If you attempt to filter the indexed image, MATLAB simply applies the filter to the indices in the indexed image matrix, and the results may not be meaningful.

The following table lists all the image conversion functions in the Image Processing Toolbox.

Function
Description
dither
Create a binary image from a grayscale intensity image by dithering; create an indexed image from an RGB image by dithering
gray2ind
Create an indexed image from a grayscale intensity image
grayslice
Create an indexed image from a grayscale intensity image by thresholding
im2bw
Create a binary image from an intensity image, indexed image, or RGB image, based on a luminance threshold
ind2gray
Create a grayscale intensity image from an indexed image
ind2rgb
Create an RGB image from an indexed image
mat2gray
Create a grayscale intensity image from data in a matrix, by scaling the data
rgb2gray
Create a grayscale intensity image from an RGB image
rgb2ind
Create an indexed image from an RGB image

You can also perform certain conversions just using MATLAB syntax. For example, you can convert an intensity image to RGB format by concatenating three copies of the original matrix along the third dimension.

The resulting RGB image has identical matrices for the red, green, and blue planes, so the image displays as shades of gray.

In addition to these standard conversion tools, there are some functions that return a different image type as part of the operation they perform. For example, the region-of-interest routines each return a binary image that you can use to mask an indexed or intensity image for filtering or for other operations.

Color Space Conversions

The Image Processing Toolbox represents colors as RGB values, either directly (in an RGB image) or indirectly (in an indexed image). However, there are other methods for representing colors. For example, a color can be represented by its hue, saturation, and value components (HSV). Different methods for representing colors are called color spaces.

The toolbox provides a set of routines for converting between RGB and other color spaces. The image processing functions themselves assume all color data is RGB, but you can process an image that uses a different color space by first converting it to RGB, and then converting the processed image back to the original color space. For more information about color space conversion routines, see Color.


  Summary of Image Types and Numeric Classes Working with Image Data