A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
colorSpace
ArrayFire Functions | ArrayFire Functions by Category » Image Processing » Colorspace conversions

## Functions
AFAPI array | colorspace (const array &image, const CSpace to, const CSpace from)
| C++ Interface wrapper for colorspace conversion.
AFAPI array | colorSpace (const array &image, const CSpace to, const CSpace from)
| C++ Interface wrapper for colorspace conversion.
AFAPI af_err | af_color_space (af_array *out, const af_array image, const af_cspace_t to, const af_cspace_t from)
| C Interface wrapper for color space conversion.

## Detailed Description

Colorspace conversion function

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.

HSV (Hue, Saturation, Value), also known as HSB (hue, saturation, brightness), is often used by artists because it is more natural to think about a color in terms of hue and saturation than in terms of additive or subtractive color components (as in RGB). HSV is a transformation of RGB colorspace; its components and colorimetry are relative to the RGB colorspace from which it was derived. Like RGB, HSV also uses 3 values per pixel.

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

Supported conversions

From | To
--- | ---
AF_RGB | AF_GRAY
AF_GRAY | AF_RGB
AF_RGB | AF_HSV
AF_HSV | AF_RGB

## Function Documentation

## ◆ af_color_space()

AFAPI af_err af_color_space | ( | af_array * | out,
|  | const af_array | image,
|  | const af_cspace_t | to,
|  | const af_cspace_t | from )

C Interface wrapper for color space conversion.

Parameters

  [out] | out | is an array in target color space
  [in] | image | is the input array
  [in] | to | is the target array color space
  [in] | from | is the input array color space

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

Note
  `image` must be 3 dimensional for AF_HSV to AF_RGB, AF_RGB to AF_HSV, & AF_RGB to AF_GRAY transformations. For AF_GRAY to AF_RGB transformation, 2D array is expected.

## ◆ colorSpace()

AFAPI array colorSpace | ( | const array & | image,
|  | const CSpace | to,
|  | const CSpace | from )

C++ Interface wrapper for colorspace conversion.

Parameters

  [in] | image | is the input array
  [in] | to | is the target array colorspace
  [in] | from | is the input array colorspace

Returns
  array in target colorspace

Note
  `image` must be 3 dimensional for AF_HSV to AF_RGB, AF_RGB to AF_HSV, & AF_RGB to AF_GRAY transformations. For AF_GRAY to AF_RGB transformation, 2D array is expected.

## ◆ colorspace()

AFAPI array colorspace | ( | const array & | image,
|  | const CSpace | to,
|  | const CSpace | from )

C++ Interface wrapper for colorspace conversion.

Parameters

  [in] | image | is the input array
  [in] | to | is the target array colorspace
  [in] | from | is the input array colorspace

Returns
  array in target colorspace

Note
  `image` must be 3 dimensional for AF_HSV to AF_RGB, AF_RGB to AF_HSV, & AF_RGB to AF_GRAY transformations. For AF_GRAY to AF_RGB transformation, 2D array is expected.

Deprecated
  Use colorSpace instead