Image Processing Toolbox User's Guide |
Converting Between Image Types
You might need to convert an image from one type to another. For example, if you want to filter a color image that is stored as an indexed image, you should first convert it to truecolor format. When you apply the filter to the truecolor 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 might not be meaningful.
The following table lists all the image type conversion functions in the Image Processing Toolbox.
Function |
Description |
|
Create a binary image from a grayscale image by dithering or create an indexed image from a truecolor image by dithering |
gray2ind |
Create an indexed image from a grayscale image |
grayslice |
Create an indexed image from a grayscale image by thresholding |
im2bw |
Create a binary image from a grayscale image, indexed image, or truecolor image, based on a luminance threshold |
ind2gray |
Create a grayscale image from an indexed image |
ind2rgb |
Create a truecolor image from an indexed image |
mat2gray |
Create a grayscale image from data in a matrix, by scaling the data |
rgb2gray |
Create a grayscale image from a truecolor image |
rgb2ind |
Create an indexed image from a truecolor image |
You can also perform certain conversions just using MATLAB syntax. For example, you can convert a grayscale image to truecolor format by concatenating three copies of the original matrix along the third dimension.
The resulting truecolor 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 grayscale image for filtering or for other operations.
Truecolor Images | Color Space Conversions |
© 1994-2005 The MathWorks, Inc.