Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 21 additions & 26 deletions filter.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
from PIL import Image
import numpy as np
img = Image.open("img2.jpg")
arr = np.array(img)
a = len(arr)
a1 = len(arr[1])
i = 0
while i < a - 11:
j = 0
while j < a1 - 11:
s = 0
for n in range(i, i + 10):
for n1 in range(j, j + 10):
n1 = arr[n][n1][0]
n2 = arr[n][n1][1]
n3 = arr[n][n1][2]
M = n1 + n2 + n3
s += M
s = int(s // 100)
for n in range(i, i + 10):
for n1 in range(j, j + 10):
arr[n][n1][0] = int(s // 50) * 50
arr[n][n1][1] = int(s // 50) * 50
arr[n][n1][2] = int(s // 50) * 50
j = j + 10
i = i + 10
res = Image.fromarray(arr)
res.save('res.jpg')

def get_image_brightness(rows, columns, img_array, mosaic_size) -> int:
return int(np.sum(img_array[rows: rows + mosaic_size, columns: columns + mosaic_size]) // 3 // (mosaic_size ** 2))

def create_img_bit(rows, columns, mosaic_size, brightness, img_array) -> list:
img_array[rows: rows + mosaic_size, columns: columns + mosaic_size] = np.full(3, brightness)
return img_array

def create_image(img_array, rows_length, columns_length, mosaic_size, grayscale):
for rows in range(0, rows_length, mosaic_size):
for columns in range(0, columns_length, mosaic_size):
create_img_bit(rows, columns, mosaic_size, get_image_brightness(rows, columns, img_array, mosaic_size) // grayscale*grayscale,
img_array)
return img_array

img_array = np.array(Image.open(input('Введите имя изображения в директории: ') + ".jpg"))
Image.fromarray(create_image(img_array,
len(img_array),
len(img_array[0]),
int(input('Введите размер мозаики: ')),
int(input('Введите шаг оттенка: ')))).save('res.jpg')
Binary file modified res.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.