Sadiyath commited on
Commit
dbc9cae
·
verified ·
1 Parent(s): 2ad3fa4

Upload app and requierements

Browse files
Files changed (2) hide show
  1. app.py +93 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image, ImageFilter
3
+ 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
+
11
+ def apply_negative(image):
12
+ img_np = np.array(image)
13
+ negative = 255 - img_np
14
+ return Image.fromarray(negative)
15
+
16
+ def binarize_image(image, threshold):
17
+ img_np = np.array(image.convert('L'))
18
+ _, binary = cv2.threshold(img_np, threshold, 255, cv2.THRESH_BINARY)
19
+ return Image.fromarray(binary)
20
+
21
+ def resize_image(image, width, height):
22
+ return image.resize((width, height))
23
+
24
+ def rotate_image(image, angle):
25
+ return image.rotate(angle)
26
+
27
+ def histo_gray(image):
28
+ hist = cv2.calcHist([image], [0], None, [256], [0, 256])
29
+ plt.plot(hist)
30
+ plt.title('Histogramme des niveaux de gris')
31
+ plt.xlabel('Intensité des pixels')
32
+ plt.ylabel('Nombre de pixels')
33
+ plt.show()
34
+ return hist
35
+
36
+ def filtre_gauss(image, kernel_width, kernel_heigth):
37
+ return cv2.GaussianBlur(image, (kernel_width, kernel_heigth), 0)
38
+
39
+ def erosion(image, taille):
40
+ return image.filter(ImageFilter.MinFilter(taille_e))
41
+
42
+ def dilatation(image, taille):
43
+ return image.filter(ImageFilter.MaxFilter(taille_d))
44
+
45
+ def extract_edges(image):
46
+ image_sobelx = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize = 5)
47
+ image_sobely = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize = 5)
48
+ return image_sobelx, image_sobely
49
+
50
+ # Interface Gradio
51
+ def image_processing(image, operation, threshold=128, width=100, height=100, angle=0):
52
+ if operation == "Négatif":
53
+ return apply_negative(image)
54
+ elif operation == "Binarisation":
55
+ return binarize_image(image, threshold)
56
+ elif operation == "Redimensionner":
57
+ return resize_image(image, width, height)
58
+ elif operation == "Rotation":
59
+ return rotate_image(image, angle)
60
+ elif operation == "Histogramme des niveaux de gris":
61
+ return histo_gray(image)
62
+ elif operation == "Filtre gaussien":
63
+ return filtre_gauss(image, kernel_width, kernel_heigth)
64
+ elif operation == "Erosion":
65
+ return erosion(image, taille_e)
66
+ elif operation == "Dilatation":
67
+ return dilatation(image, taille_d)
68
+ elif operation == "Extraction de contours":
69
+ return extract_edges(image)
70
+
71
+ # Interface Gradio
72
+ with gr.Blocks() as demo:
73
+ gr.Markdown("## Projet de Traitement d'Image")
74
+
75
+ with gr.Row():
76
+ image_input = gr.Image(type="pil", label="Charger Image")
77
+ operation = gr.Radio(["Négatif", "Binarisation", "Redimension", "Rotation", "Histogramme des niveaux de gris", "Filtre gaussien", "Extraction de contours", "Erosion", "Dilatation"], label="Opération")
78
+ threshold = gr.Slider(0, 255, 128, label="Seuil de binarisation", visible=False)
79
+ width = gr.Number(value=100, label="Largeur", visible=False)
80
+ height = gr.Number(value=100, label="Hauteur", visible=False)
81
+ angle = gr.Number(value=0, label="Angle de Rotation", visible=False)
82
+ kernel_width = gr.Number(value=5, label="Largeur du kernel du filtre gaussien", visible=False)
83
+ kernel_heigth = gr.Number(value=5, label="Hauteur du kernel du filtre gaussien", visible=False)
84
+ taille_e = gr.Number(value=3, label="Taille du filtre pour l'érosion", visible=False)
85
+ taille_d = gr.Number(value=3, label="Taille du filtre pour la dilatation", visible=False)
86
+
87
+ image_output = gr.Image(label="Image Modifiée")
88
+
89
+ submit_button = gr.Button("Appliquer")
90
+ submit_button.click(image_processing, inputs=[image_input, operation, threshold, width, height, angle], outputs=image_output)
91
+
92
+ # Lancer l'application Gradio
93
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio==3.40.0
2
+ Pillow==9.4.0
3
+ opencv-python-headless==4.8.0.74
4
+ matplotlib==3.7.1
5
+ numpy==1.24.3