-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_input.py
More file actions
26 lines (22 loc) · 931 Bytes
/
Copy pathuser_input.py
File metadata and controls
26 lines (22 loc) · 931 Bytes
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
from PIL import Image
import numpy as np
class UserInputParser:
def __init__(self, filename, size = 1):
self.path = filename
self.size = size
def open_image(self):
image = Image.open(self.path).convert('RGBA')
width, height = image.size
new_width, new_height = width // self.size, height // self.size
image_array = np.zeros((new_height, new_width, 3), dtype=np.uint8)
for y in range(0, height, self.size):
for x in range(0, width, self.size):
r, g, b, a = image.getpixel((x, y))
image_array[y // self.size, x // self.size] = r, g, b
breakpoins = []
for y in range(height):
for x in range(width):
r, g, b, a = image.getpixel((x, y))
if 0 < a < 255:
breakpoins.append((y // self.size, x // self.size))
return image_array, breakpoins