Challenge - 5 Problems
Image Reading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the shape of the image read by cv2.imread?
Given the code below, what will be the shape of the variable
img if the image is a 640x480 pixel color image?Computer Vision
import cv2 img = cv2.imread('sample.jpg') print(img.shape)
Attempts:
2 left
💡 Hint
Remember that OpenCV reads images as height x width x channels.
✗ Incorrect
OpenCV loads images as arrays with shape (height, width, channels). For a 640x480 image, height is 480 and width is 640. Color images have 3 channels (BGR).
🧠 Conceptual
intermediate1:00remaining
What does cv2.imread return if the image file does not exist?
If you try to read an image file that does not exist using
cv2.imread('missing.jpg'), what will be the value of the returned variable?Attempts:
2 left
💡 Hint
Check what OpenCV returns when it cannot find the file.
✗ Incorrect
cv2.imread returns None if the image file cannot be found or read.
❓ Model Choice
advanced1:30remaining
Which flag reads an image in grayscale using cv2.imread?
You want to read an image as grayscale using cv2.imread. Which flag should you use?
Attempts:
2 left
💡 Hint
Grayscale means one channel, black and white image.
✗ Incorrect
cv2.IMREAD_GRAYSCALE reads the image as a single channel grayscale image.
🔧 Debug
advanced1:30remaining
Why does this code raise an AttributeError?
Consider the code below:
import cv2
img = cv2.imread('image.jpg')
print(img.size())
Why does this code raise an AttributeError?Computer Vision
import cv2 img = cv2.imread('image.jpg') print(img.size())
Attempts:
2 left
💡 Hint
Check if size is a method or attribute of numpy arrays.
✗ Incorrect
The 'size' property of numpy arrays is an attribute, not a function. Calling img.size() tries to call a method that does not exist.
❓ Metrics
expert2:00remaining
What is the number of channels in an image read with cv2.IMREAD_UNCHANGED?
If you read a PNG image with transparency using
cv2.imread('image.png', cv2.IMREAD_UNCHANGED), how many channels will the resulting image array have?Attempts:
2 left
💡 Hint
IMREAD_UNCHANGED preserves the alpha channel if present.
✗ Incorrect
Using cv2.IMREAD_UNCHANGED reads all channels including alpha, so PNG with transparency has 4 channels.