Challenge - 5 Problems
Image Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output shape after flipping the image array?
Given a 3D NumPy array representing an RGB image with shape (100, 200, 3), what will be the shape of the array after applying
np.flipud(image)?NumPy
import numpy as np image = np.zeros((100, 200, 3)) flipped = np.flipud(image) print(flipped.shape)
Attempts:
2 left
💡 Hint
Flipping up-down reverses rows but does not change the shape.
✗ Incorrect
The
np.flipud function flips the array vertically (up-down) but keeps the shape the same. So the output shape remains (100, 200, 3).❓ data_output
intermediate1:30remaining
What is the pixel value after increasing brightness?
Given a grayscale image array with pixel value 120, what will be the new pixel value after adding 50 and clipping to 255?
NumPy
import numpy as np pixel = np.array([120]) bright_pixel = np.clip(pixel + 50, 0, 255) print(bright_pixel[0])
Attempts:
2 left
💡 Hint
Adding 50 to 120 gives 170, which is less than 255, so clipping does not change it.
✗ Incorrect
120 + 50 = 170, which is within the allowed range 0-255, so the pixel value becomes 170.
❓ visualization
advanced2:30remaining
Which option shows the correct code to convert an RGB image to grayscale?
You have an RGB image array with shape (height, width, 3). Which code correctly converts it to a grayscale image using the luminosity method?
NumPy
import numpy as np # image is a numpy array with shape (height, width, 3)
Attempts:
2 left
💡 Hint
The luminosity method uses weighted sums of RGB channels.
✗ Incorrect
Option A uses the correct weights for red, green, and blue channels to compute grayscale using the luminosity method.
🔧 Debug
advanced2:00remaining
What error does this code raise when trying to invert a binary image?
Consider this code snippet to invert a binary image (0s and 1s):
inverted = 1 - imageIf
image is a NumPy array of dtype bool, what error occurs?NumPy
import numpy as np image = np.array([[True, False], [False, True]], dtype=bool) inverted = 1 - image
Attempts:
2 left
💡 Hint
Subtracting a boolean array from an integer can cause type errors.
✗ Incorrect
Subtracting a boolean array from an integer raises a TypeError because NumPy does not support subtraction between int and bool directly.
🚀 Application
expert3:00remaining
How many pixels change after thresholding an image?
Given a grayscale image array of shape (50, 50) with pixel values from 0 to 255, you apply thresholding:
thresholded = (image > 128).astype(int)If exactly 1200 pixels have values greater than 128, how many pixels in
thresholded are 1?NumPy
import numpy as np np.random.seed(0) image = np.random.randint(0, 256, (50, 50)) thresholded = (image > 128).astype(int) count_ones = np.sum(thresholded) print(count_ones)
Attempts:
2 left
💡 Hint
Thresholding sets pixels > 128 to 1, so count of 1s equals count of pixels > 128.
✗ Incorrect
The thresholded array has 1s exactly where the original image pixels are greater than 128, so the count is 1200.