Hello @solub,
# Calculate the true relative luminance using scaled weights:
# Luminance = 0.2126 * Red + 0.7152 * Green + 0.0722 * Blue
# Approximation: 0.2126 * 256 = 54, 0.7152 * 256 = 183, 0.0722 * 256 = 18
lum = (54 * r + 183 * g + 18 * b) >> 8 # Bit-shift by 8 (dividing by 256)
Your code is applied to an sRGB image (assumed and these are gamma-compressed) and meets the definition of luma as per:
Grayscale - Wikipedia states:
Coding the above (formulas in the Wikipedia page) was a fun exercise and results are quite striking compared to the other methods.
References:
:)

