Skip to content

BUG: ValueError for input [1, 1] in morphology.local_maxima when [0, 0] is expected #3261

@lagru

Description

@lagru

The error can be reproduced with all development versions of scikit-image that include 912d9d2 and the following snippet:

>>> from skimage.morphology import local_maxima
>>> local_maxima([1, 1], allow_borders=False)

This raises

----> 1 local_maxima([1, 1], allow_borders=False)

~/Projects/skimage/skimage/morphology/extrema.py in local_maxima(image, selem, connectivity, indices, allow_borders)
    441     selem = _resolve_neighborhood(selem, connectivity, image.ndim)
    442     neighbor_offsets = _offsets_to_raveled_neighbors(
--> 443         image.shape, selem, center=((1,) * image.ndim))
    444 
    445     # Array of flags used to store the state of each pixel during evaluation.

~/Projects/skimage/skimage/morphology/watershed.py in _offsets_to_raveled_neighbors(image_shape, structure, center)
    148     structure[tuple(center)] = 0  # Ignore the center; it's not a neighbor
    149     connection_indices = np.transpose(np.nonzero(structure))
--> 150     offsets = (np.ravel_multi_index(connection_indices.T, image_shape) -
    151                np.ravel_multi_index(center, image_shape))
    152     squared_distances = np.sum((connection_indices - center) ** 2, axis=1)

ValueError: invalid entry in coordinates array

but should return array([0, 0]).

Until me or someone else finds the time to implement a fix and regression test this issue acts as a reminder.

Discovered in #3255.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions