Converting a color image to grayscale is one of the most fundamental image processing operations. The human eye perceives different colors with varying sensitivity, so a simple average of RGB channels does not produce a perceptually accurate grayscale image. Instead, a weighted sum based on human vision is used.
Given a color image represented as a 3D array (H × W × 3 with RGB channels), convert it to a grayscale image (H × W) using the luminance formula.
For each pixel, compute the grayscale intensity using the ITU-R BT.601 luminance weights:
Y=0.299⋅R+0.587⋅G+0.114⋅BThese weights reflect the human eye's greater sensitivity to green light, moderate sensitivity to red, and lower sensitivity to blue.
Return an H by W list of grayscale floats.
Input: image = [[[255, 0, 0]]]
Output: [[76.245]]
Explanation: The red channel contributes 0.299 times 255.
Input: image = [[[255, 0, 0], [0, 255, 0]], [[0, 0, 255], [255, 255, 255]]]
Output: [[76.245, 149.685], [29.07, 255.0]]
Unpack each pixel into red, green, and blue channel values.
Append the weighted channel sum to the corresponding grayscale row.
Sign in to take notes on this problem
Accepts: array
Converting a color image to grayscale is one of the most fundamental image processing operations. The human eye perceives different colors with varying sensitivity, so a simple average of RGB channels does not produce a perceptually accurate grayscale image. Instead, a weighted sum based on human vision is used.
Given a color image represented as a 3D array (H × W × 3 with RGB channels), convert it to a grayscale image (H × W) using the luminance formula.
For each pixel, compute the grayscale intensity using the ITU-R BT.601 luminance weights:
Y=0.299⋅R+0.587⋅G+0.114⋅BThese weights reflect the human eye's greater sensitivity to green light, moderate sensitivity to red, and lower sensitivity to blue.
Return an H by W list of grayscale floats.
Input: image = [[[255, 0, 0]]]
Output: [[76.245]]
Explanation: The red channel contributes 0.299 times 255.
Input: image = [[[255, 0, 0], [0, 255, 0]], [[0, 0, 255], [255, 255, 255]]]
Output: [[76.245, 149.685], [29.07, 255.0]]
Unpack each pixel into red, green, and blue channel values.
Append the weighted channel sum to the corresponding grayscale row.
Sign in to take notes on this problem
Accepts: array