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

projet presque fini

parent 9ee2b27a
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
This diff is collapsed.
...@@ -13,40 +13,34 @@ from PIL import Image, ImageDraw ...@@ -13,40 +13,34 @@ from PIL import Image, ImageDraw
from bloc import Bloc from bloc import Bloc
import manip_couleurs import manip_couleurs
#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: def decoupe_image(image: Bloc, ordre: int) -> Bloc:
""" """
Decoupe un bloc en quatre bloc "ordre" fois Decoupe un bloc en quatre bloc "ordre" fois
Précondition : Précondition : ordre >= 0
Exemple(s) : Exemple(s) :
$$$ $$$
""" """
image.pixel_hl = (0,0) draw = ImageDraw.Draw(image)
image.pixel_lr = im.size if ordre != 0:
if ordre !=0: en_4_blocs(image)
en_4_blocs(bloc) decoupe_image(*arg, ordre - 1)
decoupe_image(*arg: list[Bloc], ordre-1) if sont_4_blocs_uniformes_proches([bloc1, bloc2, bloc3, bloc4]):
if sont_4_blocs_uniformes_proches[bloc1, bloc2, bloc3, bloc4]: couleur_mid = moyenne_couleur([bloc1, bloc2, bloc3, bloc4])
return new_bloc = moyenne_couleur_bloc(moyenne_couleur_bloc(bloc1),\ pixel_hl = image.getpixel(image.pixel_hl(bloc1))
moyenne_couleur_bloc(bloc2),\ pixel_lr = image.getpixel(image.pixel_lr(bloc4))
moyenne_couleur_bloc(bloc3),\ draw.rectangle((pixel_hl),(pixel_lr), fill(couleur_mid))
moyenne_couleur_bloc(bloc4))
else: else:
new_bloc = [bloc1, bloc2, bloc3, bloc4] pixel_hl = image.getpixel(image.pixel_hl(bloc1))
return new_bloc pixel_lr = image.getpixel(image.pixel_lr(bloc4))
draw.rectangle((pixel_hl),(pixel_lr))
else: else:
new_bloc = [bloc1, bloc2, bloc3, bloc4] couleur_mid = moyenne_couleur(bloc)
return new_bloc pixel_hl = image.getpixel(image.pixel_hl(image))
pixel_lr = image.getpixel(image.pixel_lr(image))
draw.rectangle((pixel_hl),(pixel_lr), fill(couleur_mid))
\ No newline at end of file
\ No newline at end of file
...@@ -13,6 +13,7 @@ import sys ...@@ -13,6 +13,7 @@ import sys
import argparse import argparse
import numpy as np import numpy as np
from PIL import * from PIL import *
import csv_en_png
def charger_image(chemin_fichier: str): def charger_image(chemin_fichier: str):
""" """
...@@ -22,13 +23,14 @@ def charger_image(chemin_fichier: str): ...@@ -22,13 +23,14 @@ def charger_image(chemin_fichier: str):
$$$ $$$
""" """
im = Image.open(input("Entrez le chemin du fichier : "))
im_rgb = im.convert('RGB')
if chemin_fichier.endswith('.png'): if chemin_fichier.endswith('.png'):
im = Image.open(chemin_fichier)
return im.show() return im.show()
elif chemin_fichier.endswith('.csv'): elif chemin_fichier.endswith('.csv'):
return #conversion du fichier csv en fichier png return csv_en_png
else: else:
raise ValueError("Format de fichier non pris en charge.") raise ValueError("Erreur, veuillez recommencer.")
def traitement_image(image): def traitement_image(image):
""" """
...@@ -38,38 +40,27 @@ def traitement_image(image): ...@@ -38,38 +40,27 @@ def traitement_image(image):
$$$ $$$
""" """
int(input("Veuillez entrer l'ordre à laquelle vous voulez traiter l'image"))
return decoupe_image(image) return decoupe_image(image)
def main(): def enregistre_image(image):
""" """
Fonction principale du fichier Enregistre l'image traiter
Précondition : Précondition :
Exemple(s) : Exemple(s) :
$$$ $$$
""" """
im_rgb.save("image.png", "PNG")
# 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 def main():
image_mod = traitement_image(image, args.subdivisions) """
Fonction principale du fichier
Précondition :
Exemple(s) :
$$$
# 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__": if __name__ == "__main__":
main() main()
......
...@@ -13,20 +13,27 @@ ...@@ -13,20 +13,27 @@
import csv import csv
from PIL import Image, ImageDraw from PIL import Image, ImageDraw
# Créer une nouvelle image avec un fond noir max_y2 = 0
width, height = 512, 512 fichier_csv = "../assets/mystere.csv"
# 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
image = Image.new("RGB", (width, height), "black") image = Image.new("RGB", (width, height), "black")
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
compteur = 0
fichier_csv = "assets/mystere.csv"
with open(fichier_csv, newline='') as csvfile: with open(fichier_csv, newline='') as csvfile:
csv_reader = csv.reader(csvfile) csv_reader = csv.reader(csvfile)
for row in csv_reader: for ligne in csv_reader:
if len(row) == 7: if len(ligne) == 7:
compteur = compteur + 1 x1, y1, x2, y2, r, g, b = map(int, ligne)
x1, y1, x2, y2, r, g, b = map(int, row)
draw.rectangle([x1, y1, x2, y2], fill=(r, g, b)) draw.rectangle([x1, y1, x2, y2], fill=(r, g, b))
image.show() image.show()
\ No newline at end of file
...@@ -45,7 +45,7 @@ def est_couleur_proche(couleur1 : tuple[int,int,int], couleur2 : tuple[int,int,i ...@@ -45,7 +45,7 @@ def est_couleur_proche(couleur1 : tuple[int,int,int], couleur2 : tuple[int,int,i
""" """
res = True res = True
for i in range(len(couleur1)): for i in range(len(couleur1)):
if abs(couleur1[i] - couleur2[i]) > 5: if abs(couleur1[i] - couleur2[i]) > 15:
res = False res = False
return res return res
No preview for this file type
...@@ -95,9 +95,14 @@ class ApQueue(): ...@@ -95,9 +95,14 @@ class ApQueue():
return the string representation of this queue. return the string representation of this queue.
""" """
return ApQueue.ARROW + \ return ApQueue.ARROW + \
"|".join(str(el) for el in self.__content) + \ "|".join(str(el) for el in self.__content[::-1]) + \
ApQueue.ARROW ApQueue.ARROW
def __len__(self) -> int:
"""
return the length of this queue
"""
return len(self.__content)
if __name__ == '__main__': if __name__ == '__main__':
import apl1test import apl1test
......
...@@ -132,7 +132,14 @@ class Card(object): ...@@ -132,7 +132,14 @@ class Card(object):
$$$ len(set(cartes)) $$$ len(set(cartes))
len(cartes) len(cartes)
""" """
... liste_carte = []
for i in range(n_card):
valeur = random.randint(0, len(Card.VALUES)-1)
color = random.randint(0, len(Card.COLORS)-1)
carte = Card(Card.VALUES[valeur], Card.COLORS[color])
if carte not in liste_carte:
liste_carte.append(carte)
return liste_carte
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment