RGB/RGBA to Plane Grayscale Color Conversion

Converts an image from RGB or RGBA format to plane grayscale format.


This function can operate with ROI (see Image Regions of Interest).

This function performs conversion from RGB or RGBA image to plane grayscale image using following basic equation to compute luma from nonlinear gamma-corrected red, green and blue values:

Y' = 0.299 * R' + 0.587 * G' + 0.114 * B'

Note that the transform coefficients conform to the standard for the NTSC red, green, and blue CRT phosphors. In case of RGBA source image format, alpha channel is ignored and its values are lost.




template<typename ComputeT = float, formats SrcFormat, typename SrcDataT, typename SrcAllocatorT, typename DstDataT, typename DstAllocatorT>
sycl::event oneapi::ipl::convert(sycl::queue &queue, image<SrcFormat, SrcDataT, SrcAllocatorT> &src, image<formats::plane, DstDataT, DstAllocatorT> &dst, const convert_spec<DstDataT> &spec = {}, const std::vector<sycl::event> &dependencies = {})

Function for RGB or RGBA to grayscale color conversion.

Template Parameters
  • ComputeT – The type in which all calculations will be performed

  • SrcFormat – Source image color format

  • SrcDataT – Source image data type

  • SrcAllocatorT – Source image allocator type

  • DstDataT – Destination image data type

  • DstAllocatorT – Destination image allocator type

  • queue – SYCL queue object

  • src – Source image object

  • dst – Destination image object

  • spec – Specification for convert function

  • dependencies – SYCL event dependencies


SYCL event

Supported values for ComputeT:



Supported values for SrcFormat:




See Parameters of Color Conversion (spec).


compile-time format check

Indicates an error when image format is not supported.

compile-time data type check

Indicates an error when image data type is not supported.

compile-time compute data type check

Indicates an error when compute data type is not supported.

invalid_argument exception

Indicates an error when ROI sizes of the source image and the destination image are not equal.

invalid_argument exception

Indicates an error when one of the pitch values is not divisible by size of component data type in bytes.

The code example below demonstrates how to use the oneapi::ipl::convert for RGBA to plane grayscale conversion:

// Create queue
sycl::queue queue{};

shared_usm_allocator_t usm_allocator{ queue };

// Source rgba image data (image_image)
image<formats::rgba, std::uint8_t> src_image{ src_data_pointer, src_size };
// Destination gray image data (usm_image)
image<formats::plane, std::uint8_t> dst_image{ src_size, usm_allocator };

(void)convert(queue, src_image, dst_image);

return dst_image;