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

projet presque fini

parent 9ee2b27a
Branches
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
from bloc import Bloc
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:
"""
Decoupe un bloc en quatre bloc "ordre" fois
Précondition :
Précondition : ordre >= 0
Exemple(s) :
$$$
"""
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]:
return new_bloc = moyenne_couleur_bloc(moyenne_couleur_bloc(bloc1),\
moyenne_couleur_bloc(bloc2),\
moyenne_couleur_bloc(bloc3),\
moyenne_couleur_bloc(bloc4))
"""
draw = ImageDraw.Draw(image)
if ordre != 0:
en_4_blocs(image)
decoupe_image(*arg, ordre - 1)
if sont_4_blocs_uniformes_proches([bloc1, bloc2, bloc3, bloc4]):
couleur_mid = moyenne_couleur([bloc1, bloc2, bloc3, bloc4])
pixel_hl = image.getpixel(image.pixel_hl(bloc1))
pixel_lr = image.getpixel(image.pixel_lr(bloc4))
draw.rectangle((pixel_hl),(pixel_lr), fill(couleur_mid))
else:
new_bloc = [bloc1, bloc2, bloc3, bloc4]
return new_bloc
pixel_hl = image.getpixel(image.pixel_hl(bloc1))
pixel_lr = image.getpixel(image.pixel_lr(bloc4))
draw.rectangle((pixel_hl),(pixel_lr))
else:
new_bloc = [bloc1, bloc2, bloc3, bloc4]
return new_bloc
couleur_mid = moyenne_couleur(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
import argparse
import numpy as np
from PIL import *
import csv_en_png
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'):
im = Image.open(chemin_fichier)
return im.show()
elif chemin_fichier.endswith('.csv'):
return #conversion du fichier csv en fichier png
return csv_en_png
else:
raise ValueError("Format de fichier non pris en charge.")
raise ValueError("Erreur, veuillez recommencer.")
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)
def main():
def enregistre_image(image):
"""
Fonction principale du fichier
Enregistre l'image traiter
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)
im_rgb.save("image.png", "PNG")
# Appliquer l'algorithme sur l'image
image_mod = traitement_image(image, args.subdivisions)
def main():
"""
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__":
main()
......
......@@ -13,20 +13,27 @@
import csv
from PIL import Image, ImageDraw
# Créer une nouvelle image avec un fond noir
width, height = 512, 512
max_y2 = 0
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")
draw = ImageDraw.Draw(image)
compteur = 0
fichier_csv = "assets/mystere.csv"
with open(fichier_csv, newline='') as csvfile:
csv_reader = csv.reader(csvfile)
for row in csv_reader:
if len(row) == 7:
compteur = compteur + 1
x1, y1, x2, y2, r, g, b = map(int, row)
for ligne in csv_reader:
if len(ligne) == 7:
x1, y1, x2, y2, r, g, b = map(int, ligne)
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
"""
res = True
for i in range(len(couleur1)):
if abs(couleur1[i] - couleur2[i]) > 5:
if abs(couleur1[i] - couleur2[i]) > 15:
res = False
return res
No preview for this file type
......@@ -95,9 +95,14 @@ class ApQueue():
return the string representation of this queue.
"""
return ApQueue.ARROW + \
"|".join(str(el) for el in self.__content) + \
"|".join(str(el) for el in self.__content[::-1]) + \
ApQueue.ARROW
def __len__(self) -> int:
"""
return the length of this queue
"""
return len(self.__content)
if __name__ == '__main__':
import apl1test
......
......@@ -132,7 +132,14 @@ class Card(object):
$$$ len(set(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