Challenge - 5 Problems
Image Saving Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output of this OpenCV image saving code?
Consider the following Python code using OpenCV to save an image. What will be the output or result after running this code?
Computer Vision
import cv2 import numpy as np img = np.zeros((100, 100, 3), dtype=np.uint8) cv2.imwrite('test_image.png', img) print(cv2.imread('test_image.png').shape)
Attempts:
2 left
💡 Hint
Remember that OpenCV reads color images as 3-channel arrays by default.
✗ Incorrect
The code creates a black image of size 100x100 with 3 color channels, saves it as 'test_image.png', then reads it back. The shape of the read image is (100, 100, 3).
❓ Model Choice
intermediate1:00remaining
Which image format is best for saving photos with lossless quality?
You want to save images without losing any quality for further machine learning processing. Which image format should you choose?
Attempts:
2 left
💡 Hint
Consider which formats compress images without losing data.
✗ Incorrect
PNG is a lossless compression format, preserving all image data, unlike JPEG which uses lossy compression.
❓ Hyperparameter
advanced1:30remaining
What does the 'quality' parameter control when saving JPEG images with OpenCV?
In OpenCV's cv2.imwrite function, you can specify parameters like cv2.IMWRITE_JPEG_QUALITY. What does this parameter control?
Attempts:
2 left
💡 Hint
Think about how JPEG compression works.
✗ Incorrect
The 'quality' parameter sets the compression level; higher values mean better quality and larger file size.
🔧 Debug
advanced1:30remaining
Why does this code fail to save the image correctly?
Look at this code snippet:
import cv2
import numpy as np
img = np.zeros((50, 50), dtype=np.uint8)
cv2.imwrite('output.jpg', img)
Why might the saved image appear as a black and white image instead of color?
Attempts:
2 left
💡 Hint
Check the shape of the numpy array representing the image.
✗ Incorrect
The image array has shape (50, 50) with no color channels, so OpenCV saves it as a grayscale image.
🧠 Conceptual
expert2:00remaining
What is the main difference between cv2.imwrite and PIL.Image.save when saving images?
Both OpenCV's cv2.imwrite and PIL's Image.save can save images. What is a key difference in how they handle image data before saving?
Attempts:
2 left
💡 Hint
Think about the color channel order each library uses.
✗ Incorrect
OpenCV uses BGR channel order by default, while PIL uses RGB, so images may appear with swapped colors if not converted.