image_rgb_to_gray


image_rgb_to_gray, an Octave code which creates a grayscale version of an RGB image.

An RGB image is an (M,N,3) array.

A grayscale image is an (M,N) array.

A grayscale version of an RGB image can be made by averaging the RGB components of each pixel.

A more sophisticated approach uses the luminance function:

        GRAY = 0.2126 * R + 0.7152 * G + 0.0722 * B
      
which attempts to better model the contributions to brightness of the different colors.

Usage:

function gray = rgb_to_gray ( rgb, equal )
where

Licensing:

The information on this web page is distributed under the MIT license.

Languages:

image_rgb_to_gray is available in a MATLAB version and an Octave version.

Related Data and Programs:

image_rgb_to_gray_test

image_threshold, an Octave code which creates a black and white version of a grayscale image by specifying a single threshold value; pixels below this value become black, and above this value they are white.

Reference:

Source Code:


Last revised on 03 August 2024.