0
0
Computer Visionml~20 mins

Reading images (cv2.imread) in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Image Reading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1: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)
A(640, 480)
B(640, 480, 3)
C(480, 640)
D(480, 640, 3)
Attempts:
2 left
💡 Hint
Remember that OpenCV reads images as height x width x channels.
🧠 Conceptual
intermediate
1: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?
ANone
BAn empty numpy array with shape (0,0,3)
CRaises a FileNotFoundError
DAn array filled with zeros of shape (1,1,3)
Attempts:
2 left
💡 Hint
Check what OpenCV returns when it cannot find the file.
Model Choice
advanced
1: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?
Acv2.IMREAD_GRAYSCALE
Bcv2.IMREAD_COLOR
Ccv2.IMREAD_UNCHANGED
Dcv2.IMREAD_ANYDEPTH
Attempts:
2 left
💡 Hint
Grayscale means one channel, black and white image.
🔧 Debug
advanced
1: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())
Acv2 module does not have imread function
Bcv2.imread returns None, so None has no size() method
C'size' is an attribute, not a method, so calling img.size() causes AttributeError
DThe image file is corrupted, causing AttributeError
Attempts:
2 left
💡 Hint
Check if size is a method or attribute of numpy arrays.
Metrics
expert
2: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?
A3 channels (Blue, Green, Red)
B4 channels (Blue, Green, Red, Alpha)
C1 channel (Grayscale)
DDepends on the image, could be 1 or 3
Attempts:
2 left
💡 Hint
IMREAD_UNCHANGED preserves the alpha channel if present.