The toolbox includes many functions that you can use to convert an image from one type to another, listed in the following table. For example, if you want to filter a color image that is stored as an indexed image, you must 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.
You can 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.
RGB = cat(3,I,I,I);
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 image type conversion functions, there are other functions that return a different image type as part of the operation they perform. For example, the region of interest functions return a binary image that you can use to mask an image for filtering or for other operations.
When you convert an image from one format to another, the resulting image might look different from the original. For example, if you convert a color indexed image to a grayscale image, the resulting image displays as shades of grays, not color.
|Convert Bayer pattern encoded image to truecolor (RGB) image.|
Use dithering to convert a grayscale image to a binary image or to convert a truecolor image to an indexed image.
Convert a grayscale image to an indexed image.
Convert a grayscale image to an indexed image by using multilevel thresholding.
Convert an indexed image to a grayscale image.
Convert an indexed image to a truecolor image.
Convert a data matrix to a grayscale image, by scaling the data.
Convert a truecolor image to a grayscale image.
Note: To work with images that use other color spaces, such as HSV, first convert the image to RGB, process the image, and then convert it back to the original color space. For more information about color space conversion routines, see Understanding Color Spaces and Color Space Conversion.
Convert a truecolor image to an indexed image.