From 031b8ce458dd82cfe26c3a787648d4941137112b Mon Sep 17 00:00:00 2001
From: Louis Chmielewski <louis.chmielewski@icloud.com>
Date: Tue, 26 Mar 2024 17:31:50 +0100
Subject: [PATCH] conversion des fichiers csv en png

---
 .DS_Store                | Bin 10244 -> 10244 bytes
 Projet/README.md         |  13 ++++++++++++-
 Projet/decoupe_image.py  |  25 +++++++++++++++++++++++--
 Projet/logiciel_lcom.py  |  34 +++++++++++++++++++++++++++++++++-
 Projet/src/.DS_Store     | Bin 6148 -> 6148 bytes
 Projet/src/bloc.py       |  26 ++++++++++++--------------
 Projet/src/csv_en_png.py |  34 ++++++++++++++++++++++++++++++++++
 Tp05/.DS_Store           | Bin 6148 -> 6148 bytes
 8 files changed, 114 insertions(+), 18 deletions(-)
 create mode 100755 Projet/src/csv_en_png.py

diff --git a/.DS_Store b/.DS_Store
index 45aba7d6c48916c9f074ccfc5a4954eb3ec84658..c39c0cf358c78dc2125e92b8fd4e34e056c06e94 100644
GIT binary patch
delta 147
zcmZn(XbIS$CJ=kdk%57Mg+Y%YogtH<Bsbs1B`GIAiGhKEgMp#JX6yB%X!0p=`3*+t
zR_O8t8HT~h`MCuQAfPj0bF+Xvqq1`j0|NsaLjXe&Lq0<mLn?+f3THMS6|@%v0Lp<R
AzyJUM

delta 147
zcmZn(XbIS$CJ?(Lg@J*Ag+Y%YogtH<Bsbs1B`GIAiGhKEBRK7i`RQv%9Z}^|@X8lt
y7zQWj=N2%4fR4iEW&wFdWqURT1_m~U0EQxle1<HBR8(si7#i45Z$2t$F9rZsVkLk8

diff --git a/Projet/README.md b/Projet/README.md
index 496d72b..fd2b270 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 d1f1101..410ceaf 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 90cdc52..974b70d 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
GIT binary patch
delta 550
zcmZoMXfc=|#>B!ku~2NHo}wrh0|Nsi1A_nqLkUB%XHI@{Qcix-W=6*4%=I8CHikro
zVuoUdRAgxeuzJRQ3=9nZ|G|I(1W?o_l@}L)jACG5*pXC_lUZD1U~r9*iJ66!jh%y?
zgPS8ZI3vG2xFoTpwAd-JC>q2I$<NP8g0U0plfp7n%i{$^ob&Ta5;OBsi$H3EGgDHN
z5{qKOGxJjN%boH|^HPeznxPULoE)6-0ut5LMrH;&3T9@tIttZ>2IeL@3g(7}wY8ia
zqRRT#LGjr+xq10rAXhUmFfu}D23{x)q3RhJx)~T4P<)k>ZWx@LpIZP?0VYx8bMswX
zpuXl1RewEU`pu(`=w{^Rrw~+AkYO0CfzP6{;G(>o{JeBf>`m-3)aGSKW+-MTV~A%+
zWyoWQXDDFEV@PMvV<=##gheVe)?_!X`^~tSor9l)iG^!3Bjb1G$^0UQte`MxnCvJb
Kyg5Q-4Ko0RoQO04

delta 90
zcmZoMXfc=|#>CJ*u~2NHo}wrd0|Nsi1A_nqgC0WxL#1a<esWUI#6tDS1|lqzH?!((
vmS%gyxLJXNon>P~IOAq^4t@?MhW5>Z9N(EI^NScVGEBDNk=`65vVs`^?adaY

diff --git a/Projet/src/bloc.py b/Projet/src/bloc.py
index 4efd06c..2a96b58 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 0000000..ecd4f08
--- /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
GIT binary patch
delta 293
zcmZoMXfc=|#>B!ku~2NHo+2a9#(>?7iytsEG4f32VY*kJR9;+=l#`#tz`(F0sURn_
zxWvHV8Y2@k3o9Et2RjEhM{ICLetB?7Vo7PSQ({pxh!>KdpOXY*Cnkkurk2MGh&box
zl_X~7r51sd1ZSqCCM6cdglFcZ<d-|;m*%AugY`lsI5;^t;{_zDU8{}E40IIC%xZNM
zstpayO>`8@4Gn8+IXOg?^{s>AvvYFu^1B$ofRPbQF);8#X&BW#`3_UFI4eUYLo!1?
zLmoqMS#VKaPJUiG0|Nu&<{0MvjGNgx_&JzZxHey8{?0s^U&N7vk%55;q<?dS$Qot<
D+^SA_

delta 71
zcmZoMXfc=|#>B)qu~2NHo+2aH#(>?7j9im>Snf^U!&<u8n{5x{#)daco7p+|IhdF@
cHw$unXP(S2;>f|kz`(%Bz`(LOLSzjy0NtSyj{pDw

-- 
GitLab