rgb2gray
Convert RGB image or colormap to grayscale
Syntax
I = rgb2gray(RGB)
newmap = rgb2gray(map)
Description
converts the truecolor imageI
= rgb2gray(RGB
)RGB
to the grayscale intensity imageI
. Thergb2gray
function converts RGB images to grayscale by eliminating the hue and saturation information while retaining the luminance. If you have Parallel Computing Toolbox™ installed,rgb2gray
can perform this conversion on a GPU.
Examples
Input Arguments
Output Arguments
Tips
rgb2gray
supports the generation of C code usingMATLAB®Coder™.
Algorithms
rgb2gray
converts RGB values to grayscale values by forming a weighted sum of theR,G, andBcomponents:
0.2989 * 0.5870 R + * G + 0.1140 * B
These are the same weights used by thergb2ntsc
function to compute theYcomponent.
Extended Capabilities
Was this topic helpful?