rgb2gray

- Main Page
- Tutorials
- Functions
- Release Notes
- Examples

Functions
rgb2gray
Complete List of ArrayFire Functions ArrayFire Functions by Category » Image Processing » | Colorspace conversions

RGB to Grayscale colorspace converter. More...

## Functions
AFAPI array | rgb2gray (const array &in, const float rPercent=0.2126f, const float gPercent=0.7152f, const float bPercent=0.0722f)
| C++ Interface for RGB to gray conversion. More...
AFAPI af_err | af_rgb2gray (af_array *out, const af_array in, const float rPercent, const float gPercent, const float bPercent)
| C Interface for converting RGB to gray. More...

## Detailed Description

RGB to Grayscale colorspace converter.

RGB (Red, Green, Blue) is the most common format used in computer imaging. RGB stores individual values for red, green and blue, and hence the 3 values per pixel. A combination of these three values produces the gamut of unique colors.

Grayscale is a single channel color space where pixel value ranges from 0 to 1. Zero represents black, one represent white and any value between zero & one is a gray value

The grayscale internsity of a pixel is calculated using the following formula:

\(gray = R*rPercent + G*gPercent + B*bPercent\)

## Function Documentation

AFAPI af_err af_rgb2gray | ( | af_array * | out,
|  | const af_array | in,
|  | const float | rPercent,
|  | const float | gPercent,
|  | const float | bPercent
| ) |  |

C Interface for converting RGB to gray.

Parameters

  [out] | out | is an array in target color space
  [in] | in | is an array in the RGB color space
  [in] | rPercent | is percentage of red channel value contributing to grayscale intensity
  [in] | gPercent | is percentage of green channel value contributing to grayscale intensity
  [in] | bPercent | is percentage of blue channel value contributing to grayscale intensity

Returns
  AF_SUCCESS if the color transformation is successful, otherwise an appropriate error code is returned.

Note
  `in` must be three dimensional for RGB to Grayscale conversion.

AFAPI array af::rgb2gray | ( | const array & | in,
|  | const float | rPercent = `0.2126f`,
|  | const float | gPercent = `0.7152f`,
|  | const float | bPercent = `0.0722f`
| ) |  |

C++ Interface for RGB to gray conversion.

Parameters

  [in] | in | is an array in the RGB colorspace
  [in] | rPercent | is percentage of red channel value contributing to grayscale intensity
  [in] | gPercent | is percentage of green channel value contributing to grayscale intensity
  [in] | bPercent | is percentage of blue channel value contributing to grayscale intensity

Returns
  array in Grayscale colorspace

Note
  `in` must be three dimensional for RGB to Grayscale conversion.