Complete the code to load an image using OpenCV.
import cv2 image = cv2.[1]('image.jpg')
The cv2.imread function reads an image from a file into a matrix that the computer can process.
Complete the code to convert the image to grayscale.
gray_image = cv2.cvtColor(image, [1])cv2.COLOR_BGR2GRAY converts a color image to grayscale, which simplifies the image for many computer vision tasks.
Fix the error in the code to detect edges using Canny.
edges = cv2.Canny(image, [1], 150)
The first threshold for the Canny edge detector should be a number, like 50, not a string or None.
Fill both blanks to create a dictionary of pixel intensities for pixels greater than 100.
pixel_dict = { (x, y): image[x, y] for x in range(image.shape[[1]]) for y in range(image.shape[[2]]) if image[x, y] > 100 }In an image array, shape[0] is height (rows) and shape[1] is width (columns).
Fill all three blanks to create a dictionary of pixel intensities for pixels with intensity above 120 in grayscale image.
bright_pixels = { ([1], [2]): gray_image[[1], [2]] for [1] in range(gray_image.shape[0]) for [2] in range(gray_image.shape[1]) if gray_image[[1], [2]] > 120 }We use variables x and y to loop over rows and columns. The first blank is x, second is y, and the third repeats x to index the image.