Adjust the intensity of the Red (R), Green (G), and Blue (B) channels to observe how each component contributes with weight to the final luminance value in gray levels.
1.18.9 EP01_06 🎨 RGB → Grayscale Conversion (ITU-R BT.601)
In this activity, you must write a program that converts colored pixels (RGB) to grayscale using the physiological weighting of the ITU-R BT.601 standard.
- Read two integers L and C, representing the number of rows and columns.
- Read L × C triples of integers, where each triple represents the R (Red), G (Green), and B (Blue) channels of a pixel.
- For each pixel, compute the grayscale value (\(g\)) using the formula:
\[g = \text{round}(0.299 \times R + 0.587 \times G + 0.114 \times B)\]
- Print the resulting matrix (L rows and C columns) containing the converted integer values.
📌 Important:
- Use the
round()function from your language to ensure correct rounding to the nearest integer. - The output should contain only the grayscale values, preserving the matrix structure (separated by spaces within each row).
- See an interactive simulator for this problem at Figure 1.16 (adjust the sliders to see how each color contributes to the final brightness).
1.18.9.1 🧠 Why not just use the average?
The human eye does not perceive all colors with the same intensity. We are much more sensitive to Green than to Blue due to our biological evolution. The ITU-R BT.601 standard uses specific weights to create a grayscale image that appears naturally correct to our vision:
| Channel | Weight | Human Perception |
|---|---|---|
| 🟢 Green | 58.7% | Maximum sensitivity (distinguishing foliage). |
| 🔴 Red | 29.9% | Medium sensitivity. |
| 🔵 Blue | 11.4% | Low sensitivity (darker shades). |
1.18.9.2 📋 Task (VPL specification)
Input:
The first line contains the integer L.
The second line contains the integer C.
The following lines contain triples of integers R G B for each pixel.
Output:
The grayscale matrix with L rows and C columns.
1.18.9.3 📌 Examples
| Input | Output | Observation |
|---|---|---|
| 1 3 255 0 0 0 255 0 0 0 255 |
76 150 29 | Note how Green (150) is brighter than Blue (29) |
🎨 Simulator EP01_06: Color Perception & ITU-R BT.601 weights
RGB → Grayscale
COLOR CHANNEL ADJUSTMENT
80
180
30
Original RGB
Gray Tones
💡
The Green (G) channel has the highest weight (0.587) due to the greater spectral sensitivity of the human visual system to green wavelengths.
# your solutionTestSuite("EP01_06.py").run()✔️ EP01_06.cases already exists in casos/ 📋 7 case(s) loaded from casos/EP01_06.cases 💥 File EP01_06.py not found.