Navigation

Operators and Keywords

Function List:

C++ API

: [Y, newmap] = cmunique (X, map)
: [Y, newmap] = cmunique (RGB)
: [Y, newmap] = cmunique (I)

Convert an input image X to an ouput indexed image Y which uses the smallest colormap possible newmap.

When the input is an indexed image (X with colormap map) the output is a colormap newmap from which any repeated rows have been eliminated. The output image, Y, is the original input image with the indices adjusted to match the new, possibly smaller, colormap.

When the input is an RGB image (an MxNx3 array), the output colormap will contain one entry for every unique color in the original image. In the worst case the new map could have as many rows as the number of pixels in the original image.

When the input is a grayscale image I, the output colormap will contain one entry for every unique intensity value in the original image. In the worst case the new map could have as many rows as the number of pixels in the original image.

Implementation Details:

newmap is always an Mx3 matrix, even if the input image is an intensity grayscale image I (all three RGB planes are assigned the same value).

The output image is of class uint8 if the size of the new colormap is less than or equal to 256. Otherwise, the output image is of class double.

See also: rgb2ind, gray2ind.

Demonstration 1

The following code

 [Y, newmap] = cmunique ([1:4;5:8], [hot(4);hot(4)])
 ## Both rows are equal since map maps colors to the same value
 ## cmunique will give the same indices to both

Produces the following output

Y =

  0  1  2  3
  0  1  2  3

newmap =

   1.00000   0.00000   0.00000
   1.00000   1.00000   0.00000
   1.00000   1.00000   0.50000
   1.00000   1.00000   1.00000

Package: octave