Bird
0
0

Consider the following code:

medium📝 Debug Q7 of 15
SciPy - Image Processing (scipy.ndimage)
Consider the following code:
import numpy as np
from scipy.ndimage import label

binary_image = np.array([[1,1,0],[0,1,1],[1,0,0]])
labeled, num = label(binary_image)
print(labeled)
print(num)

What is the likely issue with this code?
AThe array contains non-binary values
BThe default connectivity may not detect all connected pixels as one component
CThe label function cannot handle 2D arrays
DThe print statements are incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check connectivity default

    By default, connectivity=1 (4-connectivity) is used.
  2. Step 2: Effect on labeling

    Some diagonally connected pixels may be treated as separate components.
  3. Final Answer:

    The default connectivity may not detect all connected pixels as one component -> Option B
  4. Quick Check:

    Default connectivity excludes diagonal neighbors [OK]
Quick Trick: Default connectivity excludes diagonals [OK]
Common Mistakes:
  • Assuming all connected pixels are grouped by default
  • Thinking label cannot process 2D arrays
  • Believing print statements cause errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes