Graphics |
Converting an 8-Bit RGB Image to Grayscale
MATLAB can perform arithmetic operations on integer data, which enables you to convert image types without first converting the numeric class of the image data.
This example reads an 8-bit RGB image into MATLAB and converts it to a grayscale image.
Now calculate the monochrome luminance by combining the RGB values according to the NTSC standard, which applies coefficients related to the eye's sensitivity to RGB colors.
I
is an intensity image with integer values ranging from a minimum of zero,
To display the image, use a grayscale colormap with 256 values. This avoids the need to scale the data-to-color mapping, which would be required if you used a colormap of a different size. You can use the imagesc
function in cases where the colormap does not contain one entry for each data value.
Now display the image in a new figure using the gray colormap.
Related Information
Other colormaps with a range of colors that vary continuously from dark to light can produce usable images. For example, try colormap(summer(256))
for a classic oscilloscope look. See colormap
for more choices.
The brighten
function enables you to increase or decrease the color intensities in a colormap to compensate for computer display differences or to enhance the visibility of faint or bright regions of the image (at the expense of the opposite end of the range).
Other 8-Bit and 16-Bit Array Support | Summary of Image Types and Numeric Classes |
© 1994-2005 The MathWorks, Inc.