1
1
import numpy
2
+ import numpy .typing
2
3
from typing import Iterable , Optional , Self
3
4
4
5
@@ -71,7 +72,7 @@ def __str__(self) -> str: # Used solely for debugging
71
72
72
73
73
74
def _initialize_segments (
74
- matrix : numpy .ndarray , is_single_file : bool
75
+ matrix : numpy .typing . NDArray [ numpy . uint8 ] , is_single_file : bool
75
76
) -> tuple [list [_SegmentUnionFind ], dict [_Coordinates , _SegmentUnionFind ]]:
76
77
"""
77
78
Each _SegmentUnionFind we return has size at least 2: these have already
@@ -111,7 +112,7 @@ def _initialize_segments(
111
112
112
113
113
114
def _get_pixel_to_segment (
114
- matrix : numpy .ndarray , is_single_file : bool
115
+ matrix : numpy .typing . NDArray [ numpy . uint8 ] , is_single_file : bool
115
116
) -> dict [_Coordinates , _SegmentUnionFind ]:
116
117
"""
117
118
If is_single_file is set, we do not include pixels on the main diagonal,
@@ -158,7 +159,9 @@ def key(
158
159
return pixel_to_segment
159
160
160
161
161
- def get_lengths (matrix : numpy .ndarray , is_single_file : bool ) -> numpy .ndarray :
162
+ def get_lengths (
163
+ matrix : numpy .typing .NDArray [numpy .uint8 ], is_single_file : bool
164
+ ) -> numpy .typing .NDArray [numpy .uint32 ]:
162
165
"""
163
166
We return an image whose pixels indicate how long a chain of nonzero values
164
167
from the original matrix is. If is_single_file is set, the main diagonal
@@ -175,7 +178,7 @@ def get_lengths(matrix: numpy.ndarray, is_single_file: bool) -> numpy.ndarray:
175
178
176
179
177
180
def get_segments (
178
- matrix : numpy .ndarray , is_single_file : bool
181
+ matrix : numpy .typing . NDArray [ numpy . uint8 ] , is_single_file : bool
179
182
) -> set [_SegmentUnionFind ]:
180
183
"""
181
184
We return set of _SegmentUnionFinds describing all the segments we found in
@@ -247,7 +250,11 @@ def update_candidate(candidate: _SegmentUnionFind) -> None:
247
250
return best_candidate
248
251
249
252
250
- def get_hues (matrix : numpy .ndarray , is_single_file : bool ) -> numpy .ndarray :
253
+ def get_hues (
254
+ matrix : numpy .typing .NDArray [numpy .uint8 ], is_single_file : bool
255
+ ) -> numpy .typing .NDArray [numpy .uint8 ]:
256
+ # Scores are going to start out as uint32's, but get turned into floats.
257
+ scores : numpy .typing .NDArray
251
258
scores = get_lengths (matrix , is_single_file )
252
259
# Cut everything off at the max, then divide by the max to put all values
253
260
# between 0 and 1.
0 commit comments