Image Processing Toolbox User's Guide Previous page   Next Page
cmunique

Find unique colormap colors and the corresponding image

Syntax

Description

[Y,newmap] = cmunique(X,map) returns the indexed image Y and associated colormap newmap that produce the same image as (X,map) but with the smallest possible colormap. The cmunique function removes duplicate rows from the colormap and adjusts the indices in the image matrix accordingly.

[Y,newmap] = cmunique(RGB) converts the true-color image RGB to the indexed image Y and its associated colormap newmap. The return value newmap is the smallest possible colormap for the image, containing one entry for each unique color in RGB. (Note that newmap might be very large, because the number of entries can be as many as the number of pixels in RGB.)

[Y,newmap] = cmunique(I) converts the intensity image I to an indexed image Y and its associated colormap newmap. The return value newmap is the smallest possible colormap for the image, containing one entry for each unique intensity level in I.

Class Support

The input image can be of class uint8, uint16, or double. The class of the output image Y is uint8 if the length of newmap is less than or equal to 256. If the length of newmap is greater than 256, Y is of class double.

Example

Use the magic function to create a sample 4-by-4 image that uses every value in the range between 1 and 16.

Concatenate two 8-entry grayscale colormaps created using the gray function. The resultant colormap, map, has 16 entries. Entries 9 through 16 are duplicates of entries 1 through 8.

Use cmunique to eliminate duplicate entries in the colormap.

cmunique adjusts the values in the original image X to index the new colormap.

View both images to verify that their appearance is the same.

See Also

gray2ind, rgb2ind


Previous page  cmpermute col2im Next page

© 1994-2005 The MathWorks, Inc.