-
Kinadinova Dariya authoredKinadinova Dariya authored
Decouper_Image.py 1.73 KiB
from PIL import Image, ImageDraw
def decouper(file: str) -> list[Image]:
"""splits image into four blocks
Précondition :
Exemple(s) :
$$$
"""
im = Image.open(file)
im_rgb = im.convert('RGB')
size = im_rgb.size
w = size[0]
h = size[1]
crop1 = (0, 0, (w//2), (h//2))
block_1 = im.crop(crop1)
crop2 = ((w//2), 0, w, (h//2))
block_2 = im.crop(crop2)
crop3 = (0, (h//2), (w//2), h)
block_3 = im.crop(crop3)
crop4 = ((h//2), (w//2), h, w)
block_4 = im.crop(crop4)
l = [block_1, block_2, block_3, block_4]
return l
def avg_col(l:list) -> tuple():
"""renvoie la couleur moyenne d'une liste de couleurs
Précondition :
Exemple(s) :
$$$ avg_col([(236, 210, 111), (236, 210, 111), (236, 210, 111), (236, 210, 111)])
(236, 210, 111)
"""
c1 = 0
c2 = 0
c3 = 0
for col in l:
c1 += col[0]
c2 += col[1]
c3 += col[2]
avg1 = c1 // len(l)
avg2 = c2 // len(l)
avg3 = c3 // len(l)
return (avg1, avg2, avg3)
def list_col(im: Image, left_top: tuple(), right_bottom: tuple()) -> list[int]:
"""à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$ list_col(Image.open('calbuth.png'), (0,0), (1, 1))
[(236, 210, 111), (236, 210, 111), (236, 210, 111), (236, 210, 111)]
"""
x_min, y_min = left_top
x_max, y_max = right_bottom
return [im.getpixel((x, y)) for x in range(x_max+1) for y in range(y_max+1)]
def is_col_close(color1: tuple(), color2: tuple()) -> bool:
"""returns True if the distance between two colors is not more than 30,
returns False if the distance is more than 30
Précondition :
Exemple(s) :
$$$
"""