%Source:http://www.mathworks.com/help/images/reducing-the-number-of-colors-in-an-image.html
%Read image and display it.
rgb=imread('pepper.bmp');
imshow(rgb);
%Create an indexed image with eight colors and without dithering.
[X_no_dither,map]= rgb2ind(rgb,8,'nodither');
figure, imshow(X_no_dither,map);
%Create an indexed image using eight colors with 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 can contain false contours.
[X_dither,map]=rgb2ind(rgb,8,'dither');
figure, imshow(X_dither,map);