forked from railbotan/refactoring-task-at-18
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.py
More file actions
33 lines (22 loc) · 840 Bytes
/
filter.py
File metadata and controls
33 lines (22 loc) · 840 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
26
27
28
29
30
31
32
33
import numpy as np
from PIL import Image
def get_img(path):
img = Image.open(path)
return np.array(img)
def save_img(img, name):
res = Image.fromarray(img)
res.save(name)
def get_pixel_art(img, size, grayscale):
width = len(img)
height = len(img[1])
for x in range(0, width, size):
for y in range(0, height, size):
brightness = get_brightness(img, size, x, y)
img[x: x + size, y: y + size] = brightness - brightness % grayscale
return img
def get_brightness(img, size, x, y):
return np.average(img[x: x + size, y: y + size])
img = get_img(input("Write the picture's path - "))
size = int(input("Write pixel's size - "))
grayscale = int(input("Write grayscale's count - "))
save_img(get_pixel_art(img, size, grayscale), 'res.jpg')