Bird
0
0

The following code is intended to perform erosion on a binary image, but it raises an error. What is the problem?

medium📝 Debug Q14 of 15
SciPy - Image Processing (scipy.ndimage)
The following code is intended to perform erosion on a binary image, but it raises an error. What is the problem?
import numpy as np
from scipy.ndimage import erosion

image = np.array([[1, 1, 0],
                  [1, 0, 0],
                  [0, 0, 1]])

result = erosion(image)
print(result)
AThe function 'erosion' does not exist in scipy.ndimage; use 'binary_erosion' instead.
BThe input image must be float type, not int.
CThe image array shape is invalid for erosion.
DThe print statement syntax is incorrect.
Step-by-Step Solution
Solution:
  1. Step 1: Check function availability

    Scipy.ndimage does not have a function named 'erosion'; the correct function is 'binary_erosion'.
  2. Step 2: Correct the import and usage

    Replace 'from scipy.ndimage import erosion' with 'from scipy.ndimage import binary_erosion' and call 'binary_erosion(image)'.
  3. Final Answer:

    The function 'erosion' does not exist in scipy.ndimage; use 'binary_erosion' instead. -> Option A
  4. Quick Check:

    Use binary_erosion, not erosion [OK]
Quick Trick: Use binary_erosion, not erosion function [OK]
Common Mistakes:
  • Trying to import non-existent 'erosion'
  • Ignoring error messages
  • Assuming all morphological functions have simple names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes