Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • dariya.kinadinova.etu/ap-kinadinova-dariya
1 result
Select Git revision
Show changes
Commits on Source (3)
"""
:author: dariya kinadinova
:date: 03/2024
"""
from PIL import Image, ImageDraw
class Block:
def __init__(self, image):
def is_uniform_block(self, image):
"""à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$
"""
"""
:author: dariya kinadinova
:date: 03/2024
"""
from PIL import Image, ImageDraw
from color import *
class Block:
def __init__(self, image):
"""à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$
"""
self.image = image
self.width, self.height = image.size
def average_color(self):
"""à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$
"""
colors = liste_col(self.image, (0, 0), (self.width-1, self.height-1))
return avg_col(colors)
def is_uniform(self, coordinates: tuple()):
"""à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$
"""
x, y = coordinates
if all(self.image.getpixel((x, y)) == self.image.getpixel((x1, y1)) for x in range(self.width) for y in range(self.height)):
return True
else:
return False
from PIL import Image, ImageDraw
def decouper(im: Image) -> list[Image]:
"""splits image into four blocks
Précondition :
Exemple(s) :
$$$
"""
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
from PIL import Image, ImageDraw # KINADINOVA Dariya
# Images récursives
def decouper(file: str) -> list[Image]: from PIL import Image, ImageDraw
"""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
# Color manipulation
def avg_col(l:list) -> tuple(): def avg_col(l:list) -> tuple():
"""renvoie la couleur moyenne d'une liste de couleurs """renvoie la couleur moyenne d'une liste de couleurs
...@@ -76,11 +55,6 @@ def is_col_close(color1: tuple(), color2: tuple()) -> bool: ...@@ -76,11 +55,6 @@ def is_col_close(color1: tuple(), color2: tuple()) -> bool:
else: else:
res = False res = False
return res return res
\ No newline at end of file
File moved
# KINADINOVA Dariya
# Images récursives
from PIL import Image, ImageDraw
# Color manipulation
def avg_col(l:list[int]) -> list[int]:
"""déterminer la couleur moyenne d'une liste de couleurs
Précondition :
Exemple(s) :
$$$
"""
n_col = len(l)
if n_col == 0:
return None
else:
c1 = 0
c2 = 0
c3 = 0
for i in l:
c1 = c1 + l[0]
c2 = c2 + l[1]
c3 = c3 + l[2]
avg1 = c1 / n_col
avg2 = c2 / n_col
avg3 = c3 / n_col
return (avg1, avg2, avg3)
def liste_col(im: Image, left_top: tuple(), right_bottom: tuple()) -> list[int]:
"""à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$
"""
x_min, y_min = left_top
x_max, y_max = right_bottom
l = []
for i in range((x_max+1)*(y_max+1)):
l.append(im.getpixel((x, y) for x in range(x_max+1) for y in range(y_max+1)))
return l
\ No newline at end of file