Complete the code to load an image using OpenCV.
import cv2 image = cv2.[1]('photo.jpg')
The cv2.imread function reads an image from a file, which is the first step in computer vision tasks.
Complete the code to convert the image to grayscale.
gray_image = cv2.cvtColor(image, [1])To convert a color image to grayscale, use cv2.COLOR_BGR2GRAY as the color conversion code.
Fix the error in the code to display the image correctly.
cv2.[1]('Image Window', gray_image) cv2.waitKey(0) cv2.destroyAllWindows()
The cv2.imshow function displays an image in a window. Using imread or imwrite here would cause errors.
Fill both blanks to create a dictionary comprehension that maps image names to their sizes if width is greater than 100.
image_sizes = {name: image.shape[[1]] for name, image in images.items() if image.shape[[2]] > 100}In OpenCV images, shape[1] is width and shape[0] is height. We want width > 100, so use shape[1] for size and shape[0] for height if needed.
Fill all three blanks to filter images with more than 3 channels and create a new dictionary with their names and channel counts.
filtered = {name: image.shape[[1]] for name, image in images.items() if image.shape[[2]] > [3]The third dimension (index 2) in image shape is the number of channels. We check if channels > 3 to filter images.