Function Reference
— Function File: [Y, newmap] = cmunique (X,map)
— Function File: [Y, newmap] = cmunique (RGB)
— Function File: [Y, newmap] = cmunique (I)

Finds colormap with unique colors and corresponding image.

[Y,newmap]=cmunique(X,map) returns an indexed image y along with its associated colormap newmap equivalent (which produce the same image) to supplied X and its colormap map; but eliminating any repeated rows in colormap colors and adjusting indices in the image matrix as needed.

[Y,newmap]=cmunique(RGB) returns an indexed image y along with its associated colormap newmap computed from a true-color image RGB (a m-by-n-by-3 array), where newmap is the smallest colormap possible (alhough it could be as long as number of pixels in image).

[Y,newmap]=cmunique(I) returns an indexed image y along with its associated colormap newmap computed from a intensity image I, where newmap is the smallest colormap possible (alhough it could be as long as number of pixels in image).

Notes:

newmap is always a m-by-3 matrix, even if input image is a intensity grey-scale image I (all three RGB planes are assigned the same value).

newmap is always of class double. If we use a RGB or intensity image of class uint8 or uint16, the colors in the colormap will be of class double in the range [0,1] (they are divided by intmax("uint8") and intmax("uint16") respectively.

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 =

   0.00000   0.00000  -0.00000
   0.83333   0.00000  -0.00000
   1.00000   0.66667  -0.00000
   1.00000   1.00000   1.00000