forked from IritRTF/refactoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.py
More file actions
28 lines (17 loc) · 853 Bytes
/
filter.py
File metadata and controls
28 lines (17 loc) · 853 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
from PIL import Image
import numpy as np
def replace_with_gray(width, height, arr, gradation):
for x in range(0, len(arr), height):
for y in range(0, len(arr[1]), width):
grad = np.sum(arr[x: x + height, y: y + width]) // (height * width * 3)
color = int(grad // gradation) * gradation
arr[x: x + height, y: y + width] = np.full(3, color) #
img = Image.open("img2.jpg")
#img = Image.open(input("введите название файла "))
arr = np.array(img)
width = int(input('Введите ширину мозайки '))
height = int(input('Введите высоту мозайки '))
gradation = int(input('Введите градацию серого '))
replace_with_gray(width, height, arr, gradation)
res = Image.fromarray(arr)
res.save('res.jpg')