Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Implement an RGB → Grayscale color space conversion, a common preprocessing step in computer vision. Given an image of RGB pixels, convert it to a 2D grayscale image using a weighted luminance formula.
The grayscale intensity is defined as:
Implement the function
Rules:
[R, G, B] into a single grayscale value using the formula above.Output:
| Argument | Type |
|---|---|
| image | np.ndarray |
| Return Name | Type |
|---|---|
| value | np.ndarray |
Input array shape must be (H, W, 3).
Use NumPy vectorization; no OpenCV/PIL utilities.
Return NumPy array.
Ensure input image is a NumPy array of floats with shape (H, W, 3).
Use the luminance weights w = np.array([0.299, 0.587, 0.114]) and combine them with the RGB channels by taking a weighted sum across the last axis (e.g., image @ w or np.tensordot).
The result should be a NumPy array of shape (H, W).