Skip to content

Conversation

@neptunes5thmoon
Copy link
Contributor

When a segmentation contains only background (label 0), get_lsds crashes because the label_descriptors list is empty. With empty label_descriptors:
np.sum(np.array([])) returns a scalar 0.0
np.clip(descriptors, 0.0, 1.0, out=descriptors) then fails with TypeError: return arrays must be of ArrayType.

This PR adds a check for empty label_descriptors and returns zeros with the correct shape (channels, *segmentation.shape) instead.

Changes:
src/lsd_lite/lsds.py: Handle empty label case before np.sum/np.clip
tests/conftest.py: Add empty_labels fixture
tests/test_lsds.py: Add test_empty_labels
tests/test_affs.py: Add test_empty_labels for both distance functions

@pattonw pattonw merged commit 78a00dc into funkelab:main Dec 10, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants