Function Reference
— Function File: [Y, newmap] = cmpermute (X,map)
— Function File: [Y, newmap] = cmpermute (X,map,index)

Reorders colors in a colormap.

[Y,newmap]=cmpermute(X,map) rearranges colormap map randomly returning colormap newmap and generates indexed image Y so that it mantains correspondence between indices and the colormap from original indexed image X (both image and colormap pairs produce the same result).

[Y,newmap]=cmpermute(X,map,index) behaves as described above but instead of sorting colors randomly, it uses index to define the order of the colors in the new colormap.

Note: index shouldn't have repeated elements, this function won't explicitly check this, but it will fail if it has.

Demonstration 1

The following code

 [Y,newmap]=cmpermute([1:4],hot(4),4:-1:1)
 # colormap will be arranged in reverse order (so will image)

Produces the following output

Y =

   4   3   2   1

newmap =

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