-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
33 lines (25 loc) · 853 Bytes
/
main.py
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 cv2 as cv
def pixelation_pictures(img, pix):
"""
function takes an image or part
of it and turns it into a pixelated image
pix - single pixel size
:param img, pix:
:return new pixelated image:
"""
x = 0 # start for pixelation x
y = 0 # start for pixelation y
py, px, _ = img.shape # photo size
px -= (px % pix) # preparation for processing x
py -= (py % pix) # preparation for processing y
img = cv.resize(img, (px, py)) # photo resizing for correct processing
while y < img.shape[0]: # photo pixelation
while x < img.shape[1]:
b = img[y + pix // 2, x + pix // 2]
img[y: y + pix, x: x + pix] = b
x += pix
x = 0
y += pix
# cv.imshow('res', img) # show img
# cv.waitKey(0)
return img # return new image