Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,17 +10,14 @@ nn = set() # Pixels non validés
|
|
| 10 |
|
| 11 |
# Fonction pour traiter et redimensionner l'image importée
|
| 12 |
def process_uploaded_image(uploaded_file):
|
| 13 |
-
image = Image.open(uploaded_file).convert("RGB").resize((
|
| 14 |
pixel_data = np.array(image)
|
| 15 |
return pixel_data
|
| 16 |
|
| 17 |
# Fonction pour déterminer la couleur dominante
|
| 18 |
def dominant_color(surrounding_pixels):
|
| 19 |
-
# Convertir les pixels en tuples pour pouvoir utiliser Counter
|
| 20 |
colors = [tuple(pixel) for pixel in surrounding_pixels]
|
| 21 |
-
# Compter les occurrences de chaque couleur
|
| 22 |
color_counts = Counter(colors)
|
| 23 |
-
# Trouver la couleur avec le maximum d'occurrences
|
| 24 |
return np.array(color_counts.most_common(1)[0][0], dtype=np.uint8)
|
| 25 |
|
| 26 |
# Fonction pour générer une image en fonction des pixels voisins
|
|
@@ -31,8 +28,8 @@ def generate_image_from_neighbors(base_pixels):
|
|
| 31 |
# Itération sur chaque pixel de l'image
|
| 32 |
for i in range(height):
|
| 33 |
for j in range(width):
|
| 34 |
-
# Collecte des couleurs des pixels environnants
|
| 35 |
surrounding_pixels = []
|
|
|
|
| 36 |
for di in range(-1, 2): # -1, 0, 1
|
| 37 |
for dj in range(-1, 2): # -1, 0, 1
|
| 38 |
if 0 <= i + di < height and 0 <= j + dj < width:
|
|
@@ -41,7 +38,7 @@ def generate_image_from_neighbors(base_pixels):
|
|
| 41 |
# Déterminer la couleur dominante parmi les pixels environnants
|
| 42 |
new_pixel_color = dominant_color(surrounding_pixels)
|
| 43 |
|
| 44 |
-
# Ajouter une petite variation aléatoire
|
| 45 |
variation = np.array([random.randint(-10, 10) for _ in range(3)])
|
| 46 |
new_pixel_color = np.clip(new_pixel_color + variation, 0, 255)
|
| 47 |
|
|
|
|
| 10 |
|
| 11 |
# Fonction pour traiter et redimensionner l'image importée
|
| 12 |
def process_uploaded_image(uploaded_file):
|
| 13 |
+
image = Image.open(uploaded_file).convert("RGB").resize((300, 300)) # Conversion en RGB et redimensionnement à 300x300
|
| 14 |
pixel_data = np.array(image)
|
| 15 |
return pixel_data
|
| 16 |
|
| 17 |
# Fonction pour déterminer la couleur dominante
|
| 18 |
def dominant_color(surrounding_pixels):
|
|
|
|
| 19 |
colors = [tuple(pixel) for pixel in surrounding_pixels]
|
|
|
|
| 20 |
color_counts = Counter(colors)
|
|
|
|
| 21 |
return np.array(color_counts.most_common(1)[0][0], dtype=np.uint8)
|
| 22 |
|
| 23 |
# Fonction pour générer une image en fonction des pixels voisins
|
|
|
|
| 28 |
# Itération sur chaque pixel de l'image
|
| 29 |
for i in range(height):
|
| 30 |
for j in range(width):
|
|
|
|
| 31 |
surrounding_pixels = []
|
| 32 |
+
# Collecte des couleurs des pixels environnants
|
| 33 |
for di in range(-1, 2): # -1, 0, 1
|
| 34 |
for dj in range(-1, 2): # -1, 0, 1
|
| 35 |
if 0 <= i + di < height and 0 <= j + dj < width:
|
|
|
|
| 38 |
# Déterminer la couleur dominante parmi les pixels environnants
|
| 39 |
new_pixel_color = dominant_color(surrounding_pixels)
|
| 40 |
|
| 41 |
+
# Ajouter une petite variation aléatoire
|
| 42 |
variation = np.array([random.randint(-10, 10) for _ in range(3)])
|
| 43 |
new_pixel_color = np.clip(new_pixel_color + variation, 0, 255)
|
| 44 |
|