-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
24 lines (20 loc) · 809 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import collections
import numpy
# The tokens is a list of tokens contained in a file.
# The lines is a list of strings containing the file contents.
# The boundaries is a list of ((start_row, start_col), (end_row, end_col))
# tuples for each token.
FileInfo = collections.namedtuple("FileInfo", ["tokens", "lines", "boundaries"])
def to_hsv_matrix(matrix, hues):
"""
The matrix is a 2D array of uint8's. The hues are either None or another 2D
array of the same shape.
We return a 3D array representing an HSV image of the matrix, optionally
colored by the hues.
"""
result = numpy.zeros([*matrix.shape, 3], numpy.uint8)
result[:, :, 2] = matrix * 255
if hues is not None:
result[:, :, 0] = hues
result[:, :, 1] = 255 # Saturation
return result