| Image Processing Toolbox™ | ![]() |
I = rgb2gray(RGB)
newmap = rgb2gray(map)
I = rgb2gray(RGB) converts the truecolor image RGB to the grayscale intensity image I. rgb2gray converts RGB images to grayscale by eliminating the hue and saturation information while retaining the luminance.
newmap = rgb2gray(map) returns a grayscale colormap equivalent to map.
Note A grayscale image is also called a gray-scale, gray scale, or gray-level image. |
If the input is an RGB image, it can be of class uint8, uint16, single, or double. The output image I is of the same class as the input image. If the input is a colormap, the input and output colormaps are both of class double.
Convert an RGB image to a grayscale image.
I = imread('board.tif');
J = rgb2gray(I);
figure, imshow(I), figure, imshow(J);Convert the colormap to a grayscale colormap.
[X,map] = imread('trees.tif');
gmap = rgb2gray(map);
figure, imshow(X,map), figure, imshow(X,gmap);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
Note that these are the same weights used by the rgb2ntsc function to compute the Y component.
ind2gray, ntsc2rgb, rgb2ind, rgb2ntsc
![]() | regionprops | rgb2hsv | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |