-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_mask.py
executable file
·34 lines (27 loc) · 1.01 KB
/
make_mask.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
import matplotlib.pyplot as plt
import numpy as np
import PIL
def make_mask(rows, columns, stripe_width):
'''An example mask generator
Makes slanted stripes of width stripe_width
image
returns an ndarray of an RGBA image rows by columns
'''
img = PIL.Image.new('RGBA', (columns, rows))
image = np.array(img)
for row in range(rows):
for column in range(columns):
if (row+column)/stripe_width % 2 == 0:
#(r+c)/w says how many stripes above/below line y=x
# The % 2 says whether it is an even or odd stripe
# Even stripe
image[row][column] = [255, 127, 127, 0] # pale red, alpha=0
else:
# Odd stripe
image[row][column] = [255, 0, 255, 255] # magenta, alpha=255
return image
if __name__ == "__main__":
image = make_mask(100,100,20)
fig, ax = plt.subplots(1, 1)
ax.imshow(image)
fig.show()