Skip to content
DeepForgeby svx
All problems
EasyComputer Visioncv-001

RGB to Grayscale

Problem

Convert an RGB image to grayscale using the luminance formula gray = 0.299 * r + 0.587 * g + 0.114 * b.

The input is a 2D list of [r, g, b] pixels with channels in [0, 255]. Return a 2D list of luminance values rounded to 2 decimal places; an empty image returns [].

Hint

Weight the green channel most and the blue channel least, then round.

Test cases

case 1
in: [[[[255,0,0],[0,255,0]],[[0,0,255],[255,255,255]]]]
expected: [[76.24,149.69],[29.07,255]]
case 2
in: [[[[0,0,0]]]]
expected: [[0]]
case 3
in: [[[[100,150,200]]]]
expected: [[140.75]]
case 4
in: [[]]
expected: []
Starter codePython
def rgb_to_grayscale(image):
    # Your code here
    pass

4 test cases · run your code against them in the editor