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
Binary file removed 632.jpg
Binary file not shown.
Binary file removed compile.png
Binary file not shown.
Binary file added example.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added filter.exe
Binary file not shown.
57 changes: 31 additions & 26 deletions filter.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
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')


class ConvertImage:

def __init__(self, image, size, gradation):
self.image = image
self.size = size
self.step = 255 // gradation

def convert_image(self):
height = len(self.image)
width = len(self.image[1])
for i in range(0, height, self.size):
for j in range(0, width, self.size):
medium_brightness = self.get_medium_brightness(i, j)
self.set_grayscale(medium_brightness, i, j)
return Image.fromarray(self.image)

def set_grayscale(self, medium_brightness, i, j):
self.image[i:i + self.size, j:j + self.size] = int(medium_brightness // self.step) * self.step / 3

def get_medium_brightness(self, i, j):
return int((self.image[i:i + self.size, j:j + self.size].sum()) // self.size ** 2)


original_image = Image.open(input("Введите имя исходного изображения:"))
pixels = np.array(original_image)
s = int(input("Введите размер блока (целое положительное число):"))
grad = int(input('Введите количество оттенков (целое положительное число):'))
result = ConvertImage(pixels, s, grad).convert_image()
result.save((input("Введите имя изображения, в которое запишется результат:")))
File renamed without changes
Binary file removed img-test.png
Binary file not shown.
Binary file removed m0oLR8Tx0zRG8s3SZQlQLnF8bhcnGu6AwzRA5aqi.png_4_1.png
Binary file not shown.
Binary file removed res.jpg
Binary file not shown.
Binary file added result.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.