diff --git a/.DS_Store b/.DS_Store index 45aba7d6c48916c9f074ccfc5a4954eb3ec84658..c39c0cf358c78dc2125e92b8fd4e34e056c06e94 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Projet/README.md b/Projet/README.md index 496d72be9497d5d14a7b6a3938cfabc04c2c87a4..fd2b270d4e5121e4a32f92fe82eefa460c59e8b7 100644 --- a/Projet/README.md +++ b/Projet/README.md @@ -12,4 +12,15 @@ author : Louis Chmielewski - 17/03 : réalisation de la fonction est_bloc_uniforme pour la classe bloc - 17/03 : réalisation de la fonction est_bloc_non_uniforme pour la classe bloc -- 17/03 : réalisation de la fonction sont_4_blocs_uniformes_proches pour la classe bloc +- 17/03 : réalisation de la fonction sont_4_blocs_uniformes_proches pour la classe bloc (début) + +- 18/03 : réalisation de la fonction sont_4_blocs_uniformes_proches pour la classe bloc (fin) + +- 20/03 : redéfinition de la fonction est_bloc_uniforme de la class Bloc + +- 22/03 : création du fichier utilisable en ligne de commande, se nommant logiciel_lcom.py +- 22/03 : réalisation de la fonction charger image dans logiciel_lcom.py + +- 24/03 : petite modification de la méthode init pour la class bloc +- 24/03 : début réalisation de la fonction découpe_image + diff --git a/Projet/decoupe_image.py b/Projet/decoupe_image.py index d1f110174e1156d4b37b3e90ab24a2f6310577d9..410ceaf885a663e15fc9b916a997fcb1a8d54327 100755 --- a/Projet/decoupe_image.py +++ b/Projet/decoupe_image.py @@ -10,9 +10,17 @@ """ from PIL import Image, ImageDraw -from bloc import * +from bloc import Bloc -def decoupe_image(bloc: Bloc, ordre: int) -> Bloc: +#importer image et recuperer sa taille + +im = Image.open(input("Entrez le chemin du fichier : ")) +im_rgb = im.convert('RGB') + + + + +def decoupe_image(image: Bloc, ordre: int) -> Bloc: """ Decoupe un bloc en quatre bloc "ordre" fois Précondition : @@ -20,6 +28,19 @@ def decoupe_image(bloc: Bloc, ordre: int) -> Bloc: $$$ """ + image.pixel_hl = (0,0) + image.pixel_lr = im.size +# if ordre !=0: +# en_4_blocs(bloc) +# decoupe_image(*arg: list[Bloc], ordre-1) +# if sont_4_blocs_uniformes_proches(bloc1, bloc2, bloc3, bloc4): +# # fonction à définir dans la classe bloc +# else: +# # fonction à définir dans la classe bloc +# else: +# # fonction à définir dans la classe bloc + + \ No newline at end of file diff --git a/Projet/logiciel_lcom.py b/Projet/logiciel_lcom.py index 90cdc524d2c010d1cfb263428427293680696423..974b70d877fea79a111375eb63354f2e07feb425 100755 --- a/Projet/logiciel_lcom.py +++ b/Projet/logiciel_lcom.py @@ -26,7 +26,7 @@ def charger_image(chemin_fichier: str): im = Image.open(chemin_fichier) return im.show() elif chemin_fichier.endswith('.csv'): - return np.loadtxt(chemin_fichier, delimiter=',', dtype=np.uint8) + return #conversion du fichier csv en fichier png else: raise ValueError("Format de fichier non pris en charge.") @@ -40,5 +40,37 @@ def traitement_image(image): """ return decoupe_image(image) +def main(): + """ + Fonction principale du fichier + Précondition : + Exemple(s) : + $$$ + + """ + + # Définition des arguments en ligne de commande + parser = argparse.ArgumentParser(description="Traitement d'image avec un algorithme spécifique") + parser.add_argument("input_file", help="Chemin vers le fichier d'entrée (PNG ou CSV)") + parser.add_argument("subdivisions", type=int, help="Nombre de subdivisions pour l'algorithme") + parser.add_argument("output_file", nargs='?', default=None, help="Chemin vers le fichier de sortie (optionnel)") + args = parser.parse_args() + + # Charger l'image + image = charger_image(args.input_file) + + # Appliquer l'algorithme sur l'image + image_mod = traitement_image(image, args.subdivisions) + + # Afficher ou enregistrer l'image résultante + if args.output_file: + cv2.imwrite(args.output_file, processed_image) + print(f"Image enregistrée sous {args.output_file}") + else: + cv2.imshow("Image traitée", processed_image) + cv2.waitKey(0) + cv2.destroyAllWindows() +if __name__ == "__main__": + main() diff --git a/Projet/src/.DS_Store b/Projet/src/.DS_Store index 6f610a638eb20b9bb21f5405e19bd72bd89031a9..95b3f438f0daa5ce3216a9763494d5501b0734f1 100644 Binary files a/Projet/src/.DS_Store and b/Projet/src/.DS_Store differ diff --git a/Projet/src/bloc.py b/Projet/src/bloc.py index 4efd06c569fede531b4d03c324ddcb7cdda6068c..2a96b58dd2ea1f77bef8e19252776184d9bf7368 100755 --- a/Projet/src/bloc.py +++ b/Projet/src/bloc.py @@ -17,14 +17,12 @@ class Bloc: """Classe d'un bloc d'une image en pixel """ - def __init__(self, bloc: Image): + def __init__(self, pixel_hl, pixel_lr): """ Initialise le type bloc à la valeur de l'image """ - largeur, hauteur = image.size - pixel_hl = image.getpixel((0, 0)) - pixel_lr = image.getpixel((largeur, hauteur)) - self.bloc = bloc + self.pixel_hl = pixel_hl + self.pixel_lr = pixel_lr def __eq__(self, other): """ @@ -44,8 +42,8 @@ class Bloc: $$$ """ - return est_couleur_proche(moyenne_couleur_bloc(bloc1), moyenne_couleur_bloc(bloc2)) and \n - est_couleur_proche(moyenne_couleur_bloc(bloc1), moyenne_couleur_bloc(bloc3)) and \n + return est_couleur_proche(moyenne_couleur_bloc(bloc1), moyenne_couleur_bloc(bloc2)) and \ + est_couleur_proche(moyenne_couleur_bloc(bloc1), moyenne_couleur_bloc(bloc3)) and \ est_couleur_proche(moyenne_couleur_bloc(bloc1), moyenne_couleur_bloc(bloc4)) @@ -87,13 +85,13 @@ class Bloc: $$$ """ - bloc1 = pixel_hl = image.getpixel((0, 0)) and \n - pixel_lr = image.getpixel((largeur/2, hauteur/2)) \n - bloc2 = pixel_hl = image.getpixel((largeur/2, 0)) and \n - pixel_lr = image.getpixel((largeur, hauteur/2)) \n - bloc3 = pixel_hl = image.getpixel((0, hauteur/2)) and \n - pixel_lr = image.getpixel((largeur/2, hauteur)) \n - bloc4 = pixel_hl = image.getpixel((largeur/2, hauteur/2)) and \n + 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)) return [bloc1, bloc2, bloc3, bloc4] diff --git a/Projet/src/csv_en_png.py b/Projet/src/csv_en_png.py new file mode 100755 index 0000000000000000000000000000000000000000..ecd4f087c4b6beb4690e6bd12fbc610d366c99bf --- /dev/null +++ b/Projet/src/csv_en_png.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +""" +:mod:`fonctions` module : convertisseur de fichiers csv pour obtenir en rgb + +:author: Louis Chmielewski + +:date: 2024 mars + +""" + +import csv +from PIL import Image, ImageDraw + +# Créer une nouvelle image avec un fond noir +width, height = 256, 256 +image = Image.new("RGB", (width, height), "black") +draw = ImageDraw.Draw(image) + +# Chemin vers le fichier CSV +csv_file = "assets/mystere.csv" + +# Lire les données à partir du fichier CSV +with open(csv_file, newline='') as csvfile: + csv_reader = csv.reader(csvfile) + for row in csv_reader: + # Convertir les valeurs de la ligne en entiers + x1, y1, x2, y2, r, g, b = map(int, row) + # Dessiner un rectangle avec la couleur spécifiée + draw.rectangle([x1, y1, x2, y2], fill=(r, g, b)) + +# Afficher l'image +image.show() diff --git a/Tp05/.DS_Store b/Tp05/.DS_Store index 5b10303b2ee0c66a010d9c83b7955f08361dac24..9984507427bbe5c9f45b353f8f59f0dbb187900b 100644 Binary files a/Tp05/.DS_Store and b/Tp05/.DS_Store differ