Complete the code to read an image using OpenCV.
import cv2 image = cv2.[1]('image.jpg', cv2.IMREAD_GRAYSCALE)
The cv2.imread function reads an image from a file. Here, we read it in grayscale mode.
Complete the code to apply the Sobel operator to find the gradient in the x direction.
sobelx = cv2.Sobel(image, cv2.CV_64F, [1], 0, ksize=3)
The third argument is dx, which is 1 to compute the gradient in the x direction.
Fix the error in the code to compute the Laplacian of the image.
laplacian = cv2.Laplacian(image, [1], ksize=3)
The depth should be cv2.CV_64F to avoid overflow and keep negative gradient values.
Fill in the blank to compute the gradient magnitude from Sobel x and y gradients.
import numpy as np magnitude = np.sqrt(np.square(sobelx) [1] np.square(sobely)) magnitude = np.uint8(magnitude)
The gradient magnitude is the square root of the sum of squares of x and y gradients.
Fill all three blanks to create a dictionary with keys as gradient types and values as their computed arrays.
gradients = {
'[1]': sobelx,
'[2]': sobely,
'[3]': laplacian
}The dictionary keys should clearly label each gradient type: 'Sobel_X', 'Sobel_Y', and 'Laplacian'.