Spaces:
Sleeping
Sleeping
Correction erreur
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import numpy as np
|
|
4 |
import cv2
|
5 |
import matplotlib.pyplot as plt
|
6 |
|
7 |
-
# Fonctions de traitement d'image
|
8 |
def load_image(image):
|
9 |
return image
|
10 |
|
@@ -77,7 +76,7 @@ def image_processing(image, operation, threshold=128, width=100, height=100, ang
|
|
77 |
elif operation == "Extraction de contours":
|
78 |
return extract_edges(image)
|
79 |
|
80 |
-
|
81 |
with gr.Blocks() as demo:
|
82 |
gr.Markdown("## Projet de Traitement d'Image")
|
83 |
|
@@ -85,37 +84,37 @@ with gr.Blocks() as demo:
|
|
85 |
image_input = gr.Image(type="pil", label="Charger Image")
|
86 |
operation = gr.Radio(["Négatif", "Binarisation", "Redimensionner", "Rotation", "Histogramme des niveaux de gris", "Filtre gaussien", "Extraction de contours", "Erosion", "Dilatation"], label="Opération")
|
87 |
|
88 |
-
threshold = gr.Slider(0, 255, 128, label="Seuil de binarisation", visible=
|
89 |
-
width = gr.Number(value=100, label="Largeur", visible=
|
90 |
-
height = gr.Number(value=100, label="Hauteur", visible=
|
91 |
-
angle = gr.Number(value=0, label="Angle de Rotation", visible=
|
92 |
-
kernel_width = gr.Number(value=5, label="Largeur du kernel du filtre gaussien", visible=
|
93 |
-
kernel_height = gr.Number(value=5, label="Hauteur du kernel du filtre gaussien", visible=
|
94 |
-
taille_e = gr.Number(value=3, label="Taille du filtre pour l'érosion", visible=
|
95 |
-
taille_d = gr.Number(value=3, label="Taille du filtre pour la dilatation", visible=
|
96 |
|
97 |
image_output = gr.Image(label="Image Modifiée")
|
98 |
|
99 |
def update_inputs(operation):
|
100 |
if operation == "Binarisation":
|
101 |
-
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
102 |
elif operation == "Redimensionner":
|
103 |
-
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
104 |
elif operation == "Rotation":
|
105 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
106 |
elif operation == "Filtre gaussien":
|
107 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(visible=False)
|
108 |
elif operation == "Erosion":
|
109 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
110 |
elif operation == "Dilatation":
|
111 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
112 |
else:
|
113 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
114 |
|
115 |
operation.change(update_inputs, inputs=operation, outputs=[threshold, width, height, angle, kernel_width, kernel_height, taille_e, taille_d])
|
116 |
|
117 |
submit_button = gr.Button("Appliquer")
|
118 |
submit_button.click(image_processing, inputs=[image_input, operation, threshold, width, height, angle, kernel_width, kernel_height, taille_e, taille_d], outputs=image_output)
|
119 |
|
120 |
-
|
121 |
demo.launch()
|
|
|
4 |
import cv2
|
5 |
import matplotlib.pyplot as plt
|
6 |
|
|
|
7 |
def load_image(image):
|
8 |
return image
|
9 |
|
|
|
76 |
elif operation == "Extraction de contours":
|
77 |
return extract_edges(image)
|
78 |
|
79 |
+
|
80 |
with gr.Blocks() as demo:
|
81 |
gr.Markdown("## Projet de Traitement d'Image")
|
82 |
|
|
|
84 |
image_input = gr.Image(type="pil", label="Charger Image")
|
85 |
operation = gr.Radio(["Négatif", "Binarisation", "Redimensionner", "Rotation", "Histogramme des niveaux de gris", "Filtre gaussien", "Extraction de contours", "Erosion", "Dilatation"], label="Opération")
|
86 |
|
87 |
+
threshold = gr.Slider(0, 255, 128, label="Seuil de binarisation", visible=False)
|
88 |
+
width = gr.Number(value=100, label="Largeur", visible=False)
|
89 |
+
height = gr.Number(value=100, label="Hauteur", visible=False)
|
90 |
+
angle = gr.Number(value=0, label="Angle de Rotation", visible=False)
|
91 |
+
kernel_width = gr.Number(value=5, label="Largeur du kernel du filtre gaussien", visible=False)
|
92 |
+
kernel_height = gr.Number(value=5, label="Hauteur du kernel du filtre gaussien", visible=False)
|
93 |
+
taille_e = gr.Number(value=3, label="Taille du filtre pour l'érosion", visible=False)
|
94 |
+
taille_d = gr.Number(value=3, label="Taille du filtre pour la dilatation", visible=False)
|
95 |
|
96 |
image_output = gr.Image(label="Image Modifiée")
|
97 |
|
98 |
def update_inputs(operation):
|
99 |
if operation == "Binarisation":
|
100 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
101 |
elif operation == "Redimensionner":
|
102 |
+
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
103 |
elif operation == "Rotation":
|
104 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
105 |
elif operation == "Filtre gaussien":
|
106 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
107 |
elif operation == "Erosion":
|
108 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
109 |
elif operation == "Dilatation":
|
110 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
111 |
else:
|
112 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
113 |
|
114 |
operation.change(update_inputs, inputs=operation, outputs=[threshold, width, height, angle, kernel_width, kernel_height, taille_e, taille_d])
|
115 |
|
116 |
submit_button = gr.Button("Appliquer")
|
117 |
submit_button.click(image_processing, inputs=[image_input, operation, threshold, width, height, angle, kernel_width, kernel_height, taille_e, taille_d], outputs=image_output)
|
118 |
|
119 |
+
|
120 |
demo.launch()
|