Challenge - 5 Problems
Color Channel Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of color channel extraction
What is the shape and data type of the red channel extracted from this RGB image array?
Matplotlib
import numpy as np image = np.array([[[255, 0, 0], [0, 255, 0]], [[0, 0, 255], [255, 255, 0]]], dtype=np.uint8) red_channel = image[:, :, 0] print(red_channel.shape, red_channel.dtype)
Attempts:
2 left
💡 Hint
Remember that extracting one color channel from an RGB image reduces the last dimension.
✗ Incorrect
The image has shape (2, 2, 3). Extracting the red channel (index 0) keeps the first two dimensions, resulting in shape (2, 2). The data type remains uint8 as the original array.
❓ data_output
intermediateResult of swapping color channels
Given an RGB image array, what is the resulting pixel value after swapping the red and blue channels for the pixel [100, 150, 200]?
Matplotlib
pixel = [100, 150, 200] swapped_pixel = [pixel[2], pixel[1], pixel[0]] print(swapped_pixel)
Attempts:
2 left
💡 Hint
Swapping red and blue means the first and last values switch places.
✗ Incorrect
The original pixel is [R=100, G=150, B=200]. Swapping red and blue channels results in [B=200, G=150, R=100].
❓ visualization
advancedVisualizing individual color channels
Which option correctly plots the green channel of an RGB image using matplotlib?
Matplotlib
import numpy as np import matplotlib.pyplot as plt image = np.random.randint(0, 256, (5, 5, 3), dtype=np.uint8) green_channel = image[:, :, 1] plt.imshow(green_channel, cmap='Greens') plt.show()
Attempts:
2 left
💡 Hint
Use the correct channel index and a matching colormap for green.
✗ Incorrect
The green channel is at index 1. Using cmap='Greens' colors the grayscale green channel appropriately.
🔧 Debug
advancedIdentify the error in color channel normalization
What error will this code raise when normalizing the blue channel of an image?
Matplotlib
import numpy as np image = np.array([[[10, 20, 30], [40, 50, 60]]], dtype=np.uint8) blue_channel = image[:, :, 2] normalized = blue_channel / 255 print(normalized.dtype)
Attempts:
2 left
💡 Hint
Dividing uint8 by int converts to float automatically.
✗ Incorrect
Dividing a uint8 numpy array by an int converts the result to float64 without error.
🚀 Application
expertCalculate average intensity of red channel in an image
Given a 3x3 RGB image array, what is the average intensity of the red channel?
Matplotlib
import numpy as np image = np.array([ [[10, 20, 30], [40, 50, 60], [70, 80, 90]], [[15, 25, 35], [45, 55, 65], [75, 85, 95]], [[20, 30, 40], [50, 60, 70], [80, 90, 100]] ], dtype=np.uint8) red_channel = image[:, :, 0] avg_red = np.mean(red_channel) print(round(avg_red, 2))
Attempts:
2 left
💡 Hint
Sum all red values and divide by 9 pixels.
✗ Incorrect
Sum of red channel values: 10+40+70+15+45+75+20+50+80=405. Average = 405/9 = 45.0.
