Skip to content

Incorrect edge discovery when having two small loops #225

@jni

Description

@jni

... And which side of the loop is chosen depends on whether the SciPy version used is 1.10 or earlier or 1.11 or later. 😕

Here's a reproducible example:

import napari
import numpy as np
from skimage.draw import random_shapes
from skimage.morphology import skeletonize
from skan import Skeleton, summarize

# Generate a random skeletons, first is a skeleton with a closed loop with side branches
kwargs = {"image_shape": (128, 128),
          "max_shapes": 20,
          "channel_axis": None,
          "shape": None,
          "rng": 1,
          "allow_overlap": True,
          "min_size": 20}

kwargs["rng"] = 13588686514
kwargs["min_size"] = 20
random_images, _ = random_shapes(**kwargs)
mask = np.where(random_images != 255, 1, 0)
skeleton_linear1 = skeletonize(mask)


viewer = napari.Viewer()
layer = viewer.add_labels(skeleton_linear1)

skeleton = Skeleton(skeleton_linear1)
all_paths = [skeleton.path_coordinates(i) for i in range(skeleton.n_paths)]
paths_table = summarize(skeleton, separator='_')
paths_table.reset_index(inplace=True, names='branch-id')

shp_layer = viewer.add_shapes(
        all_paths,
        shape_type='path',
        features=paths_table,
        metadata={'skeleton': skeleton},
        )

shp_layer.edge_color = 'branch-id'
shp_layer.edge_color_cycle = [
        'red', 'green', 'blue', 'cyan', 'magenta', 'yellow'
        ]

napari.run()

This is the output on SciPy 1.10:

Screenshot 2024-04-19 at 6 18 05 PM Screenshot 2024-04-19 at 6 18 22 PM

The same code with SciPy 1.11 produces:

Screenshot 2024-04-19 at 6 19 31 PM

Both are wrong (both loops should be completely closed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions