MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / rgb_to_luminance

Function rgb_to_luminance

tests/AssetsLibrary.cpp:55–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53{
54template <typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
55void rgb_to_luminance(const RawTensor &src, RawTensor &dst)
56{
57 // Ensure in/out tensors have same image dimensions (independent of element size and number of channels)
58 ARM_COMPUTE_ERROR_ON_MSG(src.num_elements() != dst.num_elements(),
59 "Input and output images must have equal dimensions");
60
61 const size_t num_elements = dst.num_elements();
62
63 // Currently, input is always RGB888 (3 U8 channels per element). Output can be U8, U16/S16 or U32
64 // Note that src.data()[i] returns pointer to first channel of element[i], so RGB values have [0,1,2] offsets
65 for (size_t i = 0, j = 0; j < num_elements; i += 3, ++j)
66 {
67 reinterpret_cast<T *>(dst.data())[j] =
68 0.2126f * src.data()[i] + 0.7152f * src.data()[i + 1] + 0.0722f * src.data()[i + 2];
69 }
70}
71
72void extract_r_from_rgb(const RawTensor &src, RawTensor &dst)
73{

Callers

nothing calls this directly

Calls 2

num_elementsMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected