Bird
0
0

What is wrong with this code that attempts dilation?

medium📝 Debug Q7 of 15
SciPy - Image Processing (scipy.ndimage)
What is wrong with this code that attempts dilation?
import numpy as np
from scipy.ndimage import binary_dilation
img = np.array([[1,0],[0,1]])
dilated = binary_dilation(img, structure=[1,1,1])
print(dilated)
AThe 'structure' parameter must be a 2D array, not a 1D list.
Bbinary_dilation requires the input to be float type.
CThe function binary_dilation does not accept 'structure' argument.
DThe input array must be square.
Step-by-Step Solution
Solution:
  1. Step 1: Check the 'structure' parameter format

    Structure must match input dimensions, here a 2D array is needed, not 1D list.
  2. Step 2: Validate other code parts

    Input type is fine, function accepts structure, input shape can be rectangular.
  3. Final Answer:

    The 'structure' parameter must be a 2D array, not a 1D list. -> Option A
  4. Quick Check:

    Structure shape must match input dims [OK]
Quick Trick: Structure must be 2D array for 2D images [OK]
Common Mistakes:
  • Passing 1D list as structure
  • Wrong input type assumption
  • Thinking input must be square

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes