cmap2gray
Converts a colormap to grayscale.
Category: Graphics > Images
Syntax
g = cmap2gray(map)
Returns a colormap in which each color is replaced by its luminance.
Description
Each row is replaced by the weighted sum 0.2989*R + 0.5870*G + 0.1140*B, which approximates perceived brightness, repeated in all three channels. Pure green therefore ends up much lighter than pure blue.
Input arguments
map- m-by-3 matrix of RGB values in the range [0, 1].
Output arguments
g- m-by-3 colormap whose three columns are equal.
Example
Primaries to gray
map = [1 0 0; 0 1 0; 0 0 1];
g = cmap2gray(map)
Output
g = 3×3
0.2989 0.2989 0.2989
0.5870 0.5870 0.5870
0.1140 0.1140 0.1140