diff --git a/Projet/README.md b/Projet/README.md index 619961ec5d4de467e4dc9003b0f089084f1bd50b..4bd9e2fe673f592ee6e180973b3114114c50b813 100644 --- a/Projet/README.md +++ b/Projet/README.md @@ -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) + diff --git a/Projet/decoupe_image.py b/Projet/decoupe_image.py index fee122be38a42e65a887baa196cc909d5a7663f8..5ad8fb71a6acc86fcec3701ae767d45f175df496 100755 --- a/Projet/decoupe_image.py +++ b/Projet/decoupe_image.py @@ -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 diff --git a/Projet/logiciel_lcom.py b/Projet/logiciel_lcom.py index f4031070344684b3981e5c4071790323dead71dc..f59618f0c8f292e37284f0f13332a004027a42ca 100755 --- a/Projet/logiciel_lcom.py +++ b/Projet/logiciel_lcom.py @@ -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): diff --git a/Projet/src/bloc.py b/Projet/src/bloc.py index ca0e04ac51e91953b96312119f02b31f42dd2a4a..82e844a973ac5e7db36ace759af570a087de44c6 100755 --- a/Projet/src/bloc.py +++ b/Projet/src/bloc.py @@ -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 diff --git a/Projet/src/csv_en_png.py b/Projet/src/csv_en_png.py index 00071a3e13731ecac404d1a7d94593f62b648e8d..3c73fad84b18a2ed5b4e1e65f98a8ad2fca252d9 100755 --- a/Projet/src/csv_en_png.py +++ b/Projet/src/csv_en_png.py @@ -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)