0
0
SciPydata~20 mins

Sobel and Laplace edge detection in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Edge Detection Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Sobel filter on a simple image
What is the output array after applying the Sobel filter on the given 3x3 image using scipy.ndimage.sobel with axis=0?
SciPy
import numpy as np
from scipy import ndimage

image = np.array([[10, 10, 10],
                  [20, 20, 20],
                  [30, 30, 30]])
sobel_vertical = ndimage.sobel(image, axis=0)
print(sobel_vertical)
A
[[10 10 10]
 [0 0 0]
 [-10 -10 -10]]
B
[[10 10 10]
 [20 20 20]
 [20 20 20]]
C
[[10 10 10]
 [20 20 20]
 [0 0 0]]
D
[[10 10 10]
 [20 20 20]
 [10 10 10]]
Attempts:
2 left
💡 Hint
Think about how the Sobel filter calculates the gradient along the vertical axis.
data_output
intermediate
2:00remaining
Number of edges detected by Laplace filter
After applying the Laplace filter on the given 5x5 image, how many pixels have a non-zero value indicating edges?
SciPy
import numpy as np
from scipy import ndimage

image = np.array([
    [10, 10, 10, 10, 10],
    [10, 50, 50, 50, 10],
    [10, 50, 100, 50, 10],
    [10, 50, 50, 50, 10],
    [10, 10, 10, 10, 10]
])
laplace = ndimage.laplace(image)
non_zero_count = np.count_nonzero(laplace)
print(non_zero_count)
A8
B12
C20
D16
Attempts:
2 left
💡 Hint
Edges are where the Laplace output is not zero, usually around intensity changes.
🔧 Debug
advanced
2:00remaining
Identify the error in Sobel filter application
What error will this code raise when applying the Sobel filter incorrectly?
SciPy
import numpy as np
from scipy import ndimage

image = np.array([[1, 2], [3, 4]])
sobel = ndimage.sobel(image, axis=2)
print(sobel)
AValueError: input array must be 3D
BTypeError: unsupported operand type(s) for +: 'int' and 'str'
CIndexError: axis 2 is out of bounds for array of dimension 2
DNo error, prints the Sobel filtered array
Attempts:
2 left
💡 Hint
Check the axis parameter against the image array dimensions.
visualization
advanced
2:00remaining
Visual difference between Sobel and Laplace filters
Which option best describes the visual difference when applying Sobel and Laplace filters on the same image?
ASobel and Laplace produce identical edge maps.
BSobel produces a blurred image; Laplace produces a sharpened image.
CSobel detects color changes; Laplace detects brightness changes only.
DSobel highlights edges in one direction; Laplace highlights edges regardless of direction with zero-crossings.
Attempts:
2 left
💡 Hint
Think about directional vs. non-directional edge detection.
🚀 Application
expert
3:00remaining
Combining Sobel and Laplace for edge enhancement
Given an image, which code snippet correctly combines Sobel filters on both axes and the Laplace filter to create an enhanced edge image?
A
sobel_x = ndimage.sobel(image, axis=0)
sobel_y = ndimage.sobel(image, axis=1)
laplace = ndimage.laplace(image)
enhanced = np.sqrt(sobel_x**2 + sobel_y**2) + laplace
B
sobel_x = ndimage.sobel(image, axis=0)
sobel_y = ndimage.sobel(image, axis=1)
laplace = ndimage.laplace(image)
enhanced = sobel_x + sobel_y + laplace
C
sobel = ndimage.sobel(image)
laplace = ndimage.laplace(image)
enhanced = sobel * laplace
D
sobel_x = ndimage.sobel(image, axis=0)
laplace = ndimage.laplace(image)
enhanced = sobel_x - laplace
Attempts:
2 left
💡 Hint
Combine gradients from both directions using Pythagorean theorem before adding Laplace.