Skip to content
Snippets Groups Projects
Commit e42a6297 authored by Louis Chmielewski's avatar Louis Chmielewski
Browse files

rendu final pour évaluation

parent 0930a3b4
No related branches found
No related tags found
No related merge requests found
......@@ -33,5 +33,12 @@ author : Louis Chmielewski
- 28/03 : modification apportés sur une partie de l'ensemble des fichiers
- 29/03 : projet terminé avec quelques erreurs
-> problèmes avec la spécification du type des paramètres pour les paramètres de type Bloc
-> problèmes avec l'import de fichier/fonction
- 01/04 : dernière modification avant rendu final
- 01/01 : rendu final (12h40)
......@@ -11,18 +11,28 @@
"""
import sys
sys.path.append("src")
sys.path.append("assets")
from PIL import Image, ImageDraw
from bloc import Bloc
import manip_couleurs
image = Image.open("assets/calbuth.png")
image_rgb = im.convert('RGB')
image.size = (width, height)
image_rgb.pixel_hl = (0,0)
image_rgb.pixel_lr = (width, height)
draw = ImageDraw.Draw(image)
image = input("Entrez le chemin de votre fichier : ")
def manipulation_image(image: str)->None:
"""
Ouvre une image et la manipule pour la fonction decoupe_image
Précondition :
Exemple(s) :
$$$
"""
image = Image.open(image)
image_rgb = image.convert('RGB')
image.size = (width, height)
image_rgb.pixel_hl = (0,0)
image_rgb.pixel_lr = (width, height)
draw = ImageDraw.Draw(image)
def decoupe_image(image: Bloc, ordre: int) -> Bloc:
def decoupe_image(image: "Bloc", ordre: int) -> Bloc:
"""
Decoupe un bloc en quatre bloc "ordre" fois
Précondition : ordre >= 0
......
......@@ -27,7 +27,7 @@ def charger_image(im: str):
im = Image.open(input("Entrez le chemin du fichier : "))
im_rgb = im.convert('RGB')
if im.endswith('.png'):
return im.show()
return manipulation_image(im)
elif im.endswith('.csv'):
return csv_en_png(im)
else:
......@@ -41,8 +41,8 @@ def traitement_image(image):
$$$
"""
int(input("Veuillez entrer l'ordre à laquelle vous voulez traiter l'image"))
im_rgb = decoupe_image(image)
ordre = int(input("Veuillez entrer l'ordre à laquelle vous voulez traiter l'image"))
im_rgb = decoupe_image(image, ordre)
return im_rgb
def enregistre_image(image):
......
......@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""
:mod:`association` module : un module pour la modélisation des blocs
:mod:`association` module : un module pour la modélisation des "Bloc"s
:author: Louis Chmielewski
......@@ -15,18 +15,18 @@ from manip_couleurs import *
class Bloc:
"""
Classe d'un bloc d'une image en pixel
Classe d'un "Bloc" d'une image en pixel
Exemple(s) :
$$$ self.pixel_hl = (0, 0)
$$$ self.pixel_lr = (10, 10)
$$$ self.color = (255, 0, 0)
$$$ self.bloc = Bloc(self.pixel_hl, self.pixel_lr, self.color)
$$$ self.bloc = "Bloc"(self.pixel_hl, self.pixel_lr, self.color)
"""
def __init__(self, pixel_hl: tuple[int, int], pixel_lr: tuple[int, int], color:tuple[int, int, int]):
"""
Initialise le type bloc à la valeur de l'image
Initialise le type "Bloc" à la valeur de l'image
"""
#
self.pixel_hl = pixel_hl
......@@ -43,9 +43,9 @@ class Bloc:
"""
return self.bloc == other.bloc
def est_bloc_uniforme(liste_bloc: list[Bloc, Bloc, Bloc, Bloc])->bool:
def est_bloc_uniforme(liste_bloc: list["Bloc", "Bloc", "Bloc", "Bloc"])->bool:
"""
Renvoie True si le bloc est un bloc uniforme, c'est à dire si les 4 couleurs du bloc sont proches
Renvoie True si le "Bloc" est un "Bloc" uniforme, c'est à dire si les 4 couleurs du "Bloc" sont proches
Précondition : aucune
Exemple(s) :
$$$
......@@ -56,10 +56,10 @@ class Bloc:
# est_couleur_proche(moyenne_couleur_bloc(liste_bloc[0].color), moyenne_couleur_bloc(liste_bloc[2].color))
# est_couleur_proche(moyenne_couleur_bloc(liste_bloc[0].color), moyenne_couleur_bloc(liste_bloc[3].color))
def est_bloc_non_uniforme(liste_bloc: : list[Bloc, Bloc, Bloc, Bloc])-> bool:
def est_bloc_non_uniforme(liste_bloc: list["Bloc", "Bloc", "Bloc", "Bloc"])-> bool:
"""
Renvoie True si le bloc n'est pas uniforme, c'est à dire
si il peut être divisé en 4 blocs
Renvoie True si le "Bloc" n'est pas uniforme, c'est à dire
si il peut être divisé en 4 "Bloc"s
Précondition : aucune
Exemple(s) :
$$$
......@@ -67,69 +67,69 @@ class Bloc:
"""
return not(est_bloc_uniforme(liste_bloc))
def sont_4_blocs_uniformes_proches(liste_bloc: : list[Bloc, Bloc, Bloc, Bloc])-> bool:
def sont_4_blocs_uniformes_proches(liste_bloc: list["Bloc", "Bloc", "Bloc", "Bloc"])-> bool:
"""
Renvoie True si les 4 blocs uniformes sont proches
Renvoie True si les 4 "Bloc"s uniformes sont proches
Précondition : aucune
Exemple(s) :
$$$ sont_4_blocs_uniformes_proches(bloc1, bloc2, bloc3, bloc4)
$$$ sont_4_blocs_uniformes_proches(bloc1, "Bloc"2, "Bloc"3, "Bloc"4)
True
$$$ sont_4_blocs_uniformes_proches(bloc1, bloc2, bloc3, bloc4)
$$$ sont_4_blocs_uniformes_proches(bloc1, "Bloc"2, "Bloc"3, "Bloc"4)
False
"""
res = False
if all(est_bloc_uniforme(liste_bloc)):
for i in range(1,len(liste_bloc)-1):
if est_couleur_proche(bloc1, bloc[i]):
if est_couleur_proche(bloc1, "Bloc"[i]):
res = True
return res
def en_4_blocs(bloc: Bloc)->Bloc:
def en_4_blocs(bloc: "Bloc")->"Bloc":
"""
Divise un bloc en 4 blocs
Divise un "Bloc" en 4 "Bloc"s
Précondition : aucune
Exemple(s) :
$$$
"""
# Obtenez les coordonnées du coin supérieur gauche et du coin inférieur droit du bloc
x_hl, y_hl = bloc.pixel_hl
x_lr, y_lr = bloc.pixel_lr
# Obtenez les coordonnées du coin supérieur gauche et du coin inférieur droit du "Bloc"
x_hl, y_hl = Bloc.pixel_hl
x_lr, y_lr = Bloc.pixel_lr
# Calculez les coordonnées du milieu du bloc
# Calculez les coordonnées du milieu du "Bloc"
x_milieu = (x_hl + x_lr) // 2
y_milieu = (y_hl + y_lr) // 2
# Obtenez les couleurs des pixels pour les 4 coins du bloc
couleur_bloc1 = bloc.getpixel((x_hl, y_hl))
couleur_bloc2 = bloc.getpixel((x_milieu, y_hl))
couleur_bloc3 = bloc.getpixel((x_hl, y_milieu))
couleur_bloc4 = bloc.getpixel((x_milieu, y_milieu))
# Obtenez les couleurs des pixels pour les 4 coins du "Bloc"
couleur_bloc1 = Bloc.getpixel((x_hl, y_hl))
couleur_bloc2 = Bloc.getpixel((x_milieu, y_hl))
couleur_bloc3 = Bloc.getpixel((x_hl, y_milieu))
couleur_bloc4 = Bloc.getpixel((x_milieu, y_milieu))
# Créez les 4 nouveaux blocs à partir des pixels obtenus
bloc1 = Bloc((x_hl, y_hl), (x_milieu, y_milieu))
bloc1.pixel_couleur = couleur_bloc1
# Créez les 4 nouveaux "Bloc"s à partir des pixels obtenus
Bloc1 = Bloc((x_hl, y_hl), (x_milieu, y_milieu))
Bloc1.pixel_couleur = couleur_bloc1
bloc2 = Bloc((x_milieu, y_hl), (x_lr, y_milieu))
bloc2.pixel_couleur = couleur_bloc2
Bloc2 = Bloc((x_milieu, y_hl), (x_lr, y_milieu))
Bloc2.pixel_couleur = couleur_bloc2
bloc3 = Bloc((x_hl, y_milieu), (x_milieu, y_lr))
bloc3.pixel_couleur = couleur_bloc3
Bloc3 = Bloc((x_hl, y_milieu), (x_milieu, y_lr))
Bloc3.pixel_couleur = couleur_bloc3
bloc4 = Bloc((x_milieu, y_milieu), (x_lr, y_lr))
bloc4.pixel_couleur = couleur_bloc4
Bloc4 = Bloc((x_milieu, y_milieu), (x_lr, y_lr))
Bloc4.pixel_couleur = couleur_bloc4
# Retourner une liste contenant les 4 nouveaux blocs
return [bloc1, bloc2, bloc3, bloc4]
# Retourner une liste contenant les 4 nouveaux "Bloc"s
return [bloc1, Bloc2, Bloc3, Bloc4]
# bloc1 = pixel_hl = image.getpixel((0, 0)) and pixel_lr = image.getpixel((largeur/2, hauteur/2))
# bloc2 = pixel_hl = image.getpixel((largeur/2, 0)) and pixel_lr = image.getpixel((largeur, hauteur/2))
# bloc3 = pixel_hl = image.getpixel((0, hauteur/2)) and pixel_lr = image.getpixel((largeur/2, hauteur))
# bloc4 = pixel_hl = image.getpixel((largeur/2, hauteur/2)) and pixel_lr = image.getpixel((largeur, hauteur))
# new_bloc = [bloc1, bloc2, bloc3, bloc4]
# "Bloc"1 = pixel_hl = image.getpixel((0, 0)) and pixel_lr = image.getpixel((largeur/2, hauteur/2))
# "Bloc"2 = pixel_hl = image.getpixel((largeur/2, 0)) and pixel_lr = image.getpixel((largeur, hauteur/2))
# "Bloc"3 = pixel_hl = image.getpixel((0, hauteur/2)) and pixel_lr = image.getpixel((largeur/2, hauteur))
# "Bloc"4 = pixel_hl = image.getpixel((largeur/2, hauteur/2)) and pixel_lr = image.getpixel((largeur, hauteur))
# new_bloc = [bloc1, "Bloc"2, "Bloc"3, "Bloc"4]
# return new_bloc
......
......@@ -9,23 +9,33 @@
:date: 2024 mars
"""
import sys
sys.path.append("assets")
import csv
from PIL import Image, ImageDraw
max_y2 = 0
fichier_csv = input("Entrez le chemin du fichier : ")
# Récupère la valeur maximale compris dans la 4eme colonne pour obtenir la dimension max de l'image
with open(fichier_csv, newline='') as csvfile:
csv_reader = csv.reader(csvfile)
for ligne in csv_reader:
if len(ligne) == 7:
x1, y1, x2, y2, r, g, b = map(int, ligne)
if y2 > max_y2:
y2 = max_y2
width, height = 512, 512 #max_y2, max_y2 ne marche pas
def lit_dimensions(fichier_csv: str)->tuple[int, int]:
"""
Renvoie un tuple de 2 valueurs signifiant la taille de l'image du fichier csv
Précondition : fichier_csv un fichier csv
Exemple(s) :
$$$
"""
max_y2 = 0
with open(fichier_csv, newline='') as csvfile:
csv_reader = csv.reader(csvfile)
for ligne in csv_reader:
if len(ligne) == 7:
x1, y1, x2, y2, r, g, b = map(int, ligne)
if y2 > max_y2:
max_y2 = y2
return (max_y2, max_y2)
fichier_csv = input(" Entrez le chemin de votre fichier : ")
width, height = lit_dimensions(fichier_csv)
image = Image.new("RGB", (width, height), "black")
draw = ImageDraw.Draw(image)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment