|
1 | 1 | from btrack import btypes, utils |
2 | 2 | from btrack.constants import DEFAULT_OBJECT_KEYS, Dimensionality |
3 | 3 | from btrack.io import objects_from_array |
| 4 | +from btrack.io._localization import _is_unique |
4 | 5 |
|
5 | 6 | from ._utils import create_test_image, create_test_tracklet |
6 | 7 |
|
|
10 | 11 | import pytest |
11 | 12 |
|
12 | 13 |
|
| 14 | +def test_is_unique_boolean_array(): |
| 15 | + """Test that _is_unique returns False for boolean arrays.""" |
| 16 | + # Create a simple boolean mask |
| 17 | + mask = np.array( |
| 18 | + [[True, False, False], [False, True, False], [False, False, True]], dtype=bool |
| 19 | + ) |
| 20 | + assert _is_unique(mask) is False |
| 21 | + |
| 22 | + |
| 23 | +def test_is_unique_labeled_array(): |
| 24 | + """Test that _is_unique returns True for already-labeled arrays.""" |
| 25 | + # Create a labeled array (each object has a unique integer ID) |
| 26 | + labeled = np.array([[1, 0, 0], [0, 2, 0], [0, 0, 3]], dtype=int) |
| 27 | + assert _is_unique(labeled) is True |
| 28 | + |
| 29 | + |
| 30 | +def test_is_unique_unlabeled_array(): |
| 31 | + """Test that _is_unique returns False for unlabeled binary arrays.""" |
| 32 | + # Create a mask with multiple separate objects all having the same |
| 33 | + # non-sequential ID (5). After labeling, they should have IDs (1, 2) |
| 34 | + unlabeled = np.array( |
| 35 | + [[5, 5, 0, 0], [5, 5, 0, 0], [0, 0, 5, 5], [0, 0, 5, 5]], dtype=int |
| 36 | + ) |
| 37 | + assert _is_unique(unlabeled) is False |
| 38 | + |
| 39 | + |
13 | 40 | def _example_segmentation_generator(): |
14 | 41 | for _ in range(10): |
15 | 42 | img, _centroids = create_test_image() |
|
0 commit comments