Vigninnou Lucien TITO commited on
Commit
ccef207
·
1 Parent(s): cd4f56e
Files changed (2) hide show
  1. open.py +52 -0
  2. requirements.txt +4 -0
open.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import numpy as np
4
+ import cv2
5
+
6
+ # Fonction pour charger et afficher l'image
7
+ def load_image(image):
8
+ return image
9
+
10
+ # Fonction pour appliquer un négatif
11
+ def apply_negative(image):
12
+ img_np = np.array(image)
13
+ negative = 255 - img_np
14
+ return Image.fromarray(negative)
15
+
16
+ # Fonction pour binariser une image
17
+ def binarize_image(image, threshold):
18
+ img_np = np.array(image.convert('L')) # Convertir en niveaux de gris
19
+ _, binary = cv2.threshold(img_np, threshold, 255, cv2.THRESH_BINARY)
20
+ return Image.fromarray(binary)
21
+
22
+ # Interface Gradio
23
+ def image_processing(image, operation, threshold=128):
24
+ if operation == "Négatif":
25
+ return apply_negative(image)
26
+ elif operation == "Binarisation":
27
+ return binarize_image(image, threshold)
28
+ return image
29
+
30
+ # Interface Gradio
31
+ with gr.Blocks() as demo:
32
+ gr.Markdown("## Projet de Traitement d'Image")
33
+
34
+ with gr.Row():
35
+ image_input = gr.Image(type="pil", label="Charger Image")
36
+ operation = gr.Radio(["Négatif", "Binarisation"], label="Opération à effectuer", value="Négatif")
37
+ threshold = gr.Slider(0, 255, 128, label="Seuil de binarisation", visible=False)
38
+
39
+ image_output = gr.Image(label="Image Modifiée")
40
+
41
+ def update_threshold(operation):
42
+ if operation == "Binarisation":
43
+ return gr.update(visible=True)
44
+ return gr.update(visible=False)
45
+
46
+ operation.change(update_threshold, inputs=operation, outputs=threshold)
47
+
48
+ submit_button = gr.Button("Appliquer")
49
+ submit_button.click(image_processing, inputs=[image_input, operation, threshold], outputs=image_output)
50
+
51
+ # Lancer l'application Gradio
52
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==3.41.2
2
+ Pillow==10.0.0
3
+ opencv-python==4.10.0.84
4
+ numpy==1.26.0