Image Processing Toolbox | ![]() ![]() |
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, RGB (truecolor) images can display up to 16,777,216 (i.e., 224) colors. On systems with lower screen bit depths, RGB images still displays reasonably well, because MATLAB automatically uses color approximation and dithering if needed.
Indexed images, however, may 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 | Using rgb2ind | ![]() |