Gray-World White Balance
~10 mincode completion
Implement gray_world(image).
imagehas shape(H, W, 3)and every channel has a positive mean.- Return the corrected image, same shape, as floats.
Examples
Means [2, 4, 6] have gains [2, 1, 2/3]; the pixel becomes grey
- Input
- gray_world([[[2, 4, 6]]])
- Output
- [[[4, 4, 4]]]
Two pixels with the same cast get the same per-channel gains
- Input
- gray_world([[[2, 4, 6], [4, 8, 12]]])
- Output
- [[[4, 4, 4], [8, 8, 8]]]
An image whose channel means already agree is unchanged
- Input
- gray_world([[[1, 2, 3], [3, 2, 1]]])
- Output
- [[[1, 2, 3], [3, 2, 1]]]
Hints
Hint 1
Convert the input with before doing elementwise work.
Hint 2
A common slip here: scaled by the channel mean instead of its inverse.
Requirements
image: array of shape (H, W, 3), each channel mean > 0Return array of shape (H, W, 3)
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Try similar problems(4)
Where this shows up
~10 min
••••••••••••••••
8 employers weight this skill
4 autonomy companies, 1 defense company, 1 health and bio company, 1 enterprise vendor, 1 AI product company. Top match scores 81.
Python
import numpy as np
def gray_world(image):
"""
Gray-world colour constancy: scale each channel so its mean equals the
mean of the three channel means.
Args:
image: array of shape (H, W, 3), each channel mean > 0
Returns:
array of shape (H, W, 3)
"""
# YOUR CODE HERE
pass