Image Processing Toolbox User's Guide |
Reducing the Number of Colors in an Image
This section describes how to reduce the number of colors in an indexed or RGB image. A discussion is also included about dithering, which is used by the toolbox's color-reduction functions (see below). Dithering is used to increase the apparent number of colors in an image.
The table below summarizes the Image Processing Toolbox functions for color reduction.
Function |
Purpose |
|
Reduces the number of colors used by an indexed image, enabling you specify the number of colors in the new colormap. |
|
Converts an RGB image to an indexed image, enabling you to specify the number of colors to store in the new colormap. |
On systems with 24-bit color displays, truecolor images can display up to 16,777,216 (i.e., 224) colors. On systems with lower screen bit depths, truecolor images are still displayed reasonably well, because MATLAB automatically uses color approximation and dithering if needed. Color approximation is the process by which the software chooses replacement colors in the event that direct matches cannot be found. The methods of approximation discussed in this chapter are colormap mapping, uniform quantization, and minimum variance quantization -- see Color Approximation.
Indexed images, however, might cause problems if they have a large number of colors. In general, you should limit indexed images to 256 colors for the following reasons:
uint8
array, but generally uses an array of class double
instead, making the storage size of the image much larger (each pixel uses 64 bits).
imwrite
) to a format that does not support more than 256 colors, you will receive an error.
Working with Different Screen Bit Depths | Color Approximation |
© 1994-2005 The MathWorks, Inc.