Image Processing Toolbox | ![]() ![]() |
Dithering
When you use rgb2ind
or imapprox
to reduce the number of colors in an image, the resulting image may look inferior to the original, because some of the colors are lost. rgb2ind
and imapprox
both perform dithering to increase the apparent number of colors in the output image. Dithering changes the colors of pixels in a neighborhood so that the average color in each neighborhood approximates the original RGB color.
For an example of how dithering works, consider an image that contains a number of dark pink pixels for which there is no exact match in the colormap. To create the appearance of this shade of pink, the Image Processing Toolbox selects a combination of colors from the colormap, that, taken together as a six-pixel group, approximate the desired shade of pink. From a distance, the pixels appear to be correct shade, but if you look up close at the image, you can see a blend of other shades, perhaps red and pale pink pixels. The commands below load a 24-bit image, and then use rgb2ind
to create two indexed images with just eight colors each.
rgb=imread('lily.tif
');
imshow(rgb);
[X_no_dither,map]=rgb2ind(rgb,8,'nodither');
[X_dither,map]=rgb2ind(rgb,8,'dither');
figure, imshow(X_no_dither,map);
figure, imshow(X_dither,map);
Figure 13-4: Examples of Color Reduction with and Without Dithering
Notice that the dithered image has a larger number of apparent colors but is somewhat fuzzy-looking. The image produced without dithering has fewer apparent colors, but an improved spatial resolution when compared to the dithered image. One risk in doing color reduction without dithering is that the new image my contain false contours (see the rose in the upper-right corner).
![]() | Reducing Colors in an Indexed Image | Converting to Other Color Spaces | ![]() |