Bird
0
0

The following code attempts to apply the Laplace filter but raises an error. What is the mistake?

medium📝 Debug Q14 of 15
SciPy - Image Processing (scipy.ndimage)
The following code attempts to apply the Laplace filter but raises an error. What is the mistake?
from scipy import ndimage
img = [[1, 2, 3], [4, 5, 6], [7, 8]]
laplace_img = ndimage.laplace(img)
Andimage.laplace does not exist in SciPy
BLaplace filter requires axis parameter
CThe image must be grayscale
DThe input image must be a NumPy array, not a list
Step-by-Step Solution
Solution:
  1. Step 1: Check input type for ndimage filters

    ndimage functions require NumPy arrays, not Python lists, for image input.
  2. Step 2: Identify error cause

    Passing a list causes a TypeError because ndimage.laplace expects an array.
  3. Final Answer:

    The input image must be a NumPy array, not a list -> Option D
  4. Quick Check:

    ndimage needs np.array input [OK]
Quick Trick: Convert lists to np.array before filtering [OK]
Common Mistakes:
  • Passing lists instead of arrays
  • Thinking laplace needs axis parameter
  • Believing laplace function is missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes