Skip to content

MorphologyOps.foreground_component() ignores connectivity parameter, always uses 1-connectivity #56

Description

@herryliq

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 specified

When scipy.ndimage.label() is called without the structure parameter, it defaults to:

structure = _morphology.generate_binary_structure(input.ndim, 1)  # 1-connectivity

Expected 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

  1. Class initialization accepts connectivity: 1

  2. Other methods use connectivity: Other methods in the codebase properly use the connectivity parameter, as seen in 3

  3. Real usage expects different connectivity: In practice, the class is instantiated with different connectivity values, such as neigh=6 in 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions