Functions > Image Processing > Image Color Tools > Example: Grayscale and Color in Images
  
Example: Grayscale and Color in Images
Use the rgb_to_gray and gray_to_rbg functions for converting RGB images to grayscale and vice versa, and for false color imaging.
For information on using this example, refer to About Image Processing Examples.
rgb_to_gray
1. Read in an RGB image.
Click to copy this expression
2. Convert the image to grayscale.
Click to copy this expression
Click to copy this expression
The RGB values are converted to grayscale using the NTSC formula: 0.299 ∙ Red + 0.587 ∙ Green + 0.114 ∙ Blue. This formula closely represents the average person's relative perception of the brightness of red, green, and blue light.
3. Insert the two images to view the color difference.
(smallwar.gif)
(smallwar_rgb_gray.bmp)
gray_to_rgb
When converting a grayscale matrix to RGB, false colors are assigned to the intensity levels in the image.
1. Read in a grayscale image.
Click to copy this expression
(bridge.bmp)
2. Define a data set that describes a rainbow spectrum colormap.
Click to copy this expression
3. Use the spectrum colormap for converting the grayscale image to RGB.
Click to copy this expression
Click to copy this expression
(colorbridge.bmp)
gray_to_rgb does not use the built-in ORIGIN variable, which specifies the starting index of an array for other functions.