cmpermute

Reorders the colors of a colormap and updates the indexed image to match.

Category: Graphics > Images

Syntax

[Y, newmap] = cmpermute(X, map, order)

Rearranges map according to order and renumbers X so it looks the same.

Description

Since an indexed image only refers to colors by position, simply shuffling the colormap would change the picture. cmpermute shuffles both consistently, so ind2rgb(Y, newmap) equals ind2rgb(X, map).

Input arguments

X
Indexed image (integer indices into the colormap).
map
Colormap, m-by-3.
order
Vector with the new order of the colormap rows; newmap(k,:) is map(order(k),:).

Output arguments

Y
Image with indices adjusted to the new order.
newmap
The reordered colormap.

Example

Swap two colors

X = [1 2; 2 1];
map = [1 0 0; 0 0 1];
[Y, newmap] = cmpermute(X, map, [2 1])
Output
Y = 2×2

     2     1
     1     2
newmap = 2×3

     0     0     1
     1     0     0

See also

cmunique ind2rgb colormap rgb2ind