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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/refactoring-task-at-19.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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')


def calculate_gray_cell(row, column):
mosaic = pixels_matrix[row:min(row + cell_size, rows_count), column:min(column + cell_size, columns_count)]
return int((np.sum(mosaic) // 3) // (cell_size ** 2))


def set_gray_in_cell(row, column):
mosaic = pixels_matrix[row:min(row + cell_size, rows_count), column:min(column + cell_size, columns_count)]
np.place(mosaic[:, ], mosaic >= 0, int(gray // gradation) * gradation)


input_data = input("Enter cell size and gradation\n").split()
image = Image.open(input("Enter source file name\n"))
result = input("Enter result file name\n")
cell_size = int(input_data[0])
gradation = 255 // int(input_data[1])
pixels_matrix = np.array(image)
rows_count = len(pixels_matrix)
columns_count = len(pixels_matrix[1])

current_row = 0
while current_row < rows_count:
current_column = 0
while current_column < columns_count:
gray = calculate_gray_cell(current_row, current_column)
set_gray_in_cell(current_row, current_column)
current_column = current_column + cell_size
current_row = current_row + cell_size

Image.fromarray(pixels_matrix).save(f"{result}")
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.