-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
35 lines (31 loc) · 1.07 KB
/
generate.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
25
26
27
28
29
30
31
32
33
34
35
import numpy
import cv2 as opencv
# TODO generate diagonals for testing
# pass in array_like for colors (even if they're 1-channel)
def gradient(first, second, steps=128, direction="down"):
if direction == "down":
i, f = first, second
vert = True
elif direction == "right":
i, f = first, second
vert = False
elif direction == "up":
i, f = second, first
vert = True
elif direction == "left":
i, f = second, first
vert = False
else:
raise NotImplementedError
# gradient strip
grad = numpy.linspace(i, f, num=steps, dtype=numpy.uint8)
# squarify output image
if vert:
return numpy.tile(grad.reshape(grad.shape[0], 1, grad.shape[1]), (1, steps, 1))
else:
return numpy.tile(grad.reshape(1, grad.shape[0], grad.shape[1]), (steps, 1, 1))
if __name__ == "__main__":
black = numpy.array([0,0,0])
white = numpy.array([255,255,255])
opencv.imwrite("tests/bwdowngrad.png", gradient(black, white, steps=256))
# create and save other gradients as needed for testing