-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Problem Description
The MorphologyOps class in 1 accepts a connectivity parameter during initialization, but the foreground_component() method 2 completely ignores this parameter and always uses scipy's default 1-connectivity (4-connectivity for 2D, 6-connectivity for 3D).
Current Behavior
def foreground_component(self):
return ndimage.label(self.binary_map) # No structure parameter specifiedWhen scipy.ndimage.label() is called without the structure parameter, it defaults to:
structure = _morphology.generate_binary_structure(input.ndim, 1) # 1-connectivityExpected Behavior
The method should respect the connectivity parameter passed during class initialization, similar to how other methods in the class use self.connectivity.
Evidence of Inconsistency
-
Class initialization accepts connectivity: 1
-
Other methods use connectivity: Other methods in the codebase properly use the connectivity parameter, as seen in 3
-
Real usage expects different connectivity: In practice, the class is instantiated with different connectivity values, such as
neigh=6in 4
Proposed Solution
Modify the foreground_component() method to use the stored connectivity parameter:
def foreground_component(self):
structure = generate_binary_structure(self.binary_map.ndim, self.connectivity)
return ndimage.label(self.binary_map, structure=structure)Impact
This inconsistency may lead to unexpected results in connected component analysis, especially for users who expect the specified connectivity to be applied consistently across all morphological operations.