Convert RGB image or colormap to grayscale
converts the
truecolor image I
= rgb2gray(RGB
)RGB
to the grayscale image
I
. The rgb2gray
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.
rgb2gray
supports the generation
of C code using MATLAB®
Coder™.
rgb2gray
converts RGB values to grayscale
values by forming a weighted sum of the R, G,
and B components:
0.2989 * R + 0.5870 * G + 0.1140 * B
These are the same weights used by the rgb2ntsc
(Image Processing Toolbox) function to compute the Y component.
The coefficients used to calculate grayscale values in rgb2gray
are
identical to those used to calculate luminance (E'y) in Rec.ITU-R BT.601-7 after
rounding to 3 decimal places.
Rec.ITU-R BT.601-7 calculates E'y using the following formula:
0.299 * R + 0.587 * G + 0.114 * B