FUNCTION REFERENCE
rgb2gray
Convert an RGB image or colormap to grayscale.
Convert an RGB image or colormap to grayscale.
Syntax
I = rgb2gray(RGB)Syntax
newmap = rgb2gray(map)I = 0.298936021293775 R + 0.587043074451121 G + 0.114020904255103 B (the weights of the reference page, Rec. ITU-R BT.601-7 rounded to three decimals). An M-by-N-by-3 image of class double, single, uint8 or uint16 gives an M-by-N image of the same class (integers rounded half away from zero). A c-by-3 double colormap in [0, 1] gives a c-by-3 colormap with three equal columns.
Example
rgb2gray(uint8(cat(3, [255 0], [0 255], [0 0]))) % uint8 [76 150]Example
rgb2gray([1 0 0; 1 1 1]) % [0.2989 0.2989 0.2989; 1 1 1]Differences from MATLAB: gpuArray input is not supported.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.