Complete the code to load images from a folder using OpenCV.
import cv2 image = cv2.imread([1]) print(image.shape)
We need to provide the image filename as a string to cv2.imread. So, the correct answer is a string with quotes.
Complete the code to resize an image to 100x100 pixels.
resized_image = cv2.resize(image, [1]) print(resized_image.shape)
The cv2.resize function expects the new size as a tuple (width, height). So, (100, 100) is correct.
Fix the error in the code to convert an image to grayscale.
gray_image = cv2.cvtColor(image, [1]) print(gray_image.shape)
To convert a color image to grayscale, use cv2.COLOR_BGR2GRAY because OpenCV loads images in BGR format.
Fill both blanks to create a dictionary of image filenames and their sizes (width, height).
image_sizes = {filename: (image.shape[[1]], image.shape[[2]]) for filename, image in images.items()}In OpenCV images, shape[0] is height and shape[1] is width. The dictionary stores (width, height), so width is shape[1] and height is shape[0].
Fill all three blanks to filter images with width greater than 200 and create a new dictionary with filename and width.
filtered_images = {filename: image.shape[[1]] for filename, image in images.items() if image.shape[[2]] [3] 200}Width is shape[1]. We want images where width is greater than 200, so the condition is image.shape[1] > 200. The dictionary stores filename and width.