Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect edge discovery when having two small loops #225

Open
jni opened this issue Apr 19, 2024 · 1 comment
Open

Incorrect edge discovery when having two small loops #225

jni opened this issue Apr 19, 2024 · 1 comment
Labels

Comments

@jni
Copy link
Owner

jni commented Apr 19, 2024

... 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).

@jni jni added the bug label Apr 19, 2024
ns-rse added a commit to ns-rse/skan that referenced this issue Apr 19, 2024
Discovered that single skeleton > networkx failing under Python 3.8 is due to spurious edge detection . See jni#225 for
further details.
@jni
Copy link
Owner Author

jni commented Apr 20, 2024

SciPy changes to investigate re the change in behaviour, based on the 1.11 release notes: scipy/scipy#16936 / scipy/scipy#16929

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant