%% Reduce Number of Colors in Indexed Image
% Load an indexed image of a mandrill's face. Display image X using its associated colormap, map, which has 220 colors.

figure
load mandrill
image(X)
colormap(map)
axis off         
axis image

%
% Reduce the number of colors in the indexed image from 220 to only 16 colors by producing a new image, Y, and its associated colormap, newmap.

figure
[Y,newmap] = imapprox(X,map,16);
image(Y)
colormap(newmap)
axis off       
axis image

% Copyright 2012 The MathWorks, Inc.