0
0
Computer Visionml~10 mins

Image gradients (Sobel, Laplacian) in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read an image using OpenCV.

Computer Vision
import cv2

image = cv2.[1]('image.jpg', cv2.IMREAD_GRAYSCALE)
Drag options to blanks, or click blank then click option'
AcvtColor
Bimwrite
Cimshow
Dimread
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.imshow instead of cv2.imread
Using cv2.imwrite which saves images instead of reading
Using cv2.cvtColor which converts color spaces
2fill in blank
medium

Complete the code to apply the Sobel operator to find the gradient in the x direction.

Computer Vision
sobelx = cv2.Sobel(image, cv2.CV_64F, [1], 0, ksize=3)
Drag options to blanks, or click blank then click option'
A1
B0
C-1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Setting dx to 0 which means no derivative in x
Using negative values which are invalid here
Confusing dx and dy arguments
3fill in blank
hard

Fix the error in the code to compute the Laplacian of the image.

Computer Vision
laplacian = cv2.Laplacian(image, [1], ksize=3)
Drag options to blanks, or click blank then click option'
Acv2.CV_64F
Bcv2.COLOR_BGR2GRAY
Ccv2.CV_8U
Dcv2.IMREAD_COLOR
Attempts:
3 left
💡 Hint
Common Mistakes
Using color conversion codes instead of depth
Using 8-bit unsigned depth causing incorrect results
4fill in blank
hard

Fill in the blank to compute the gradient magnitude from Sobel x and y gradients.

Computer Vision
import numpy as np

magnitude = np.sqrt(np.square(sobelx) [1] np.square(sobely))
magnitude = np.uint8(magnitude)
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Subtracting squares which is mathematically incorrect
Multiplying or dividing squares which does not give magnitude
5fill in blank
hard

Fill all three blanks to create a dictionary with keys as gradient types and values as their computed arrays.

Computer Vision
gradients = {
    '[1]': sobelx,
    '[2]': sobely,
    '[3]': laplacian
}
Drag options to blanks, or click blank then click option'
ASobel_X
BSobel_Y
CLaplacian
DGradient
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic keys like 'Gradient' for all
Mixing up keys and values
Not using strings as keys