kebincontreras commited on
Commit
e7acccd
·
verified ·
1 Parent(s): 9b48268

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -49
app.py CHANGED
@@ -1,25 +1,25 @@
1
  import gradio as gr
2
- from image_processing import apply_blur, clip_image, wrap_image
3
- from detection import yolov10_inference, calculate_detection_metrics
4
  from PIL import Image
5
  import numpy as np
6
  import torchvision.transforms as transforms
7
  import torch
8
- from utils import *
9
- from utils import modulo
 
 
10
  import cv2
11
  import matplotlib.pyplot as plt
 
12
 
13
- # Definir el tamaño de la imagen constante
14
  IMAGE_SIZE = 640 # Asignar el valor constante para image_size
15
 
16
  def process_image(image, model_id, sat_factor, selected_method):
17
- # Definir valores fijos dentro de la función
18
  conf_threshold = 0.85
19
  correction = 1.0
20
- kernel_size = 7 # Definir kernel_size como constante
21
 
22
- # Valores fijos para DO, t y vertical
23
  DO = 1
24
  t = 0.7
25
  vertical = True
@@ -30,12 +30,11 @@ def process_image(image, model_id, sat_factor, selected_method):
30
  original_image = original_image * 255.0
31
  original_image = original_image.astype(np.uint8)
32
 
33
- # scaling factor
34
  scaling = 1.0
35
  original_image = cv2.resize(original_image, (0, 0), fx=scaling, fy=scaling)
36
 
37
  blurred_image = apply_blur(original_image / 255.0, kernel_size)
38
- clipped_image = clip_image(blurred_image, correction, sat_factor)
39
 
40
  img_tensor = torch.tensor(blurred_image, dtype=torch.float32).permute(2, 0, 1).unsqueeze(0)
41
  img_tensor = modulo(img_tensor * sat_factor, L=1.0)
@@ -47,7 +46,13 @@ def process_image(image, model_id, sat_factor, selected_method):
47
  clipped_annotated, clipped_detections = yolov10_inference((clipped_image*255.0).astype(np.uint8), "yolov10n", IMAGE_SIZE, conf_threshold)
48
  wrapped_annotated, wrapped_detections = yolov10_inference(wrapped_image, model_id, IMAGE_SIZE, conf_threshold)
49
 
50
- recon_image = recons(img_tensor, DO=DO, L=1.0, vertical=vertical, t=t)
 
 
 
 
 
 
51
  recon_image_pil = transforms.ToPILImage()(recon_image.squeeze(0))
52
  recon_image_np = np.array(recon_image_pil).astype(np.uint8)
53
 
@@ -64,16 +69,6 @@ def app():
64
  image_width = int(600 * image_scaler)
65
  image_height = int(200 * image_scaler)
66
 
67
- bibtex_citation = """
68
- @inproceedings{contreras2024high,
69
- title={High Dynamic Range Modulo Imaging for Robust Object Detection in Autonomous Driving},
70
- author={Kebin Contreras, Brayan Monroy and Jorge Bacca},
71
- booktitle={ECCV 2024},
72
- year={2024},
73
- organization={European Conference on Computer Vision (ECCV)}
74
- }
75
- """
76
-
77
  with gr.Blocks(css=f"""
78
  .fixed-size-image img {{
79
  width: {image_width}px;
@@ -87,7 +82,7 @@ def app():
87
  }}
88
  .gr-column {{
89
  display: flex;
90
- flex-direction: column;
91
  align-items: center;
92
  padding: 0 !important;
93
  margin: 0 !important;
@@ -101,12 +96,13 @@ def app():
101
  }}
102
  .custom-button {{
103
  display: inline-block;
104
- padding: 5px 10px; /* Ajustar el tamaño del botón */
105
- font-size: 12px; /* Reducir el tamaño de la fuente */
106
  font-weight: bold;
107
  color: white;
108
  border-radius: 5px;
109
- margin: 5px; /* Ajustar el margen */
 
110
  text-decoration: none;
111
  text-align: center;
112
  }}
@@ -120,8 +116,8 @@ def app():
120
  background-color: #007bff;
121
  }}
122
  .gr-examples img {{
123
- width: 200px; /* Ajusta este valor al doble del tamaño original */
124
- height: 200px; /* Ajusta este valor al doble del tamaño original */
125
  }}
126
  """) as demo:
127
  gr.Markdown("## Modulo Imaging for Computer Vision", elem_id="centered-title")
@@ -129,13 +125,15 @@ def app():
129
  with gr.Row():
130
  with gr.Column():
131
  gr.Markdown("### High Dynamic Range Modulo Imaging for Robust Object Detection in Autonomous Driving", elem_id="centered-text")
132
- gr.HTML('<a href="https://openreview.net/pdf?id=2GqZFx2I7s" target="_blank" class="custom-button btn-grey">Article</a>')
133
- gr.HTML('<a href="https://github.com/kebincontreras/Modulo_images.git" target="_blank" class="custom-button btn-blue">GitHub</a>')
134
-
 
135
  with gr.Column():
136
  gr.Markdown("### Autoregressive High-Order Finite Difference Modulo Imaging: High-Dynamic Range for Computer Vision Applications", elem_id="centered-text")
137
- gr.HTML('<a href="https://cvlai.net/aim/2024/" target="_blank" class="custom-button btn-red">Article</a>')
138
- gr.HTML('<a href="https://github.com/bemc22/AHFD" target="_blank" class="custom-button btn-blue">GitHub</a>')
 
139
 
140
  image = gr.Image(type="pil", label="Upload Image", interactive=True)
141
 
@@ -144,20 +142,19 @@ def app():
144
 
145
  selected_method = gr.Radio(
146
  label="Select Method",
147
- choices=["SPUD", "AHFD"],
148
  value="SPUD"
149
  )
150
 
151
  process_button = gr.Button("Process Image")
152
 
153
- # Agregar las imágenes de ejemplo al final con tamaño más grande
154
  examples = [
155
- ["imagen1.png"],
156
- ["imagen2.png"],
157
- ["imagen3.jpg"],
158
- ["imagen4.jpg"],
159
- ["imagen5.jpg"],
160
- ["imagen6.png"]
161
  ]
162
 
163
  gr.Examples(
@@ -180,15 +177,6 @@ def app():
180
  outputs=[output_original, output_clip, output_wrap, output_recons]
181
  )
182
 
183
- # Añadir un botón pequeño para copiar la cita en BibTeX
184
- def copy_bibtex():
185
- return bibtex_citation
186
-
187
- with gr.Row():
188
- with gr.Column():
189
- gr.Button("Copy BibTeX", elem_classes="custom-button btn-blue", size="small").click(fn=copy_bibtex, outputs=[gr.Markdown("")])
190
- gr.Markdown("", visible=False)
191
-
192
  return demo
193
 
194
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ from Scripts.image_processing import apply_blur, clip_image, wrap_image
3
+ from Scripts.detection import yolov10_inference, calculate_detection_metrics
4
  from PIL import Image
5
  import numpy as np
6
  import torchvision.transforms as transforms
7
  import torch
8
+ from Scripts.utils import *
9
+ from Scripts.utils import modulo
10
+ from Scripts.utils_spud import * # Asegúrate de que las funciones necesarias estén importadas aquí
11
+
12
  import cv2
13
  import matplotlib.pyplot as plt
14
+ import packaging
15
 
 
16
  IMAGE_SIZE = 640 # Asignar el valor constante para image_size
17
 
18
  def process_image(image, model_id, sat_factor, selected_method):
 
19
  conf_threshold = 0.85
20
  correction = 1.0
21
+ kernel_size = 7
22
 
 
23
  DO = 1
24
  t = 0.7
25
  vertical = True
 
30
  original_image = original_image * 255.0
31
  original_image = original_image.astype(np.uint8)
32
 
 
33
  scaling = 1.0
34
  original_image = cv2.resize(original_image, (0, 0), fx=scaling, fy=scaling)
35
 
36
  blurred_image = apply_blur(original_image / 255.0, kernel_size)
37
+ clipped_image = clip_image(blurred_image, correction, sat_factor)
38
 
39
  img_tensor = torch.tensor(blurred_image, dtype=torch.float32).permute(2, 0, 1).unsqueeze(0)
40
  img_tensor = modulo(img_tensor * sat_factor, L=1.0)
 
46
  clipped_annotated, clipped_detections = yolov10_inference((clipped_image*255.0).astype(np.uint8), "yolov10n", IMAGE_SIZE, conf_threshold)
47
  wrapped_annotated, wrapped_detections = yolov10_inference(wrapped_image, model_id, IMAGE_SIZE, conf_threshold)
48
 
49
+ if selected_method == "SPUD":
50
+ # Uso de la función personalizada de SPUD
51
+ recon_image = recons_spud(img_tensor, threshold=0.1, mx=1.0)
52
+ else:
53
+ # Método por defecto AHFD
54
+ recon_image = recons(img_tensor, DO=DO, L=1.0, vertical=vertical, t=t)
55
+
56
  recon_image_pil = transforms.ToPILImage()(recon_image.squeeze(0))
57
  recon_image_np = np.array(recon_image_pil).astype(np.uint8)
58
 
 
69
  image_width = int(600 * image_scaler)
70
  image_height = int(200 * image_scaler)
71
 
 
 
 
 
 
 
 
 
 
 
72
  with gr.Blocks(css=f"""
73
  .fixed-size-image img {{
74
  width: {image_width}px;
 
82
  }}
83
  .gr-column {{
84
  display: flex;
85
+ flex-direction: row;
86
  align-items: center;
87
  padding: 0 !important;
88
  margin: 0 !important;
 
96
  }}
97
  .custom-button {{
98
  display: inline-block;
99
+ padding: 5px 10px;
100
+ font-size: 12px;
101
  font-weight: bold;
102
  color: white;
103
  border-radius: 5px;
104
+ margin-right: 5px; /* Reducir el margen entre botones */
105
+ margin-bottom: 0px;
106
  text-decoration: none;
107
  text-align: center;
108
  }}
 
116
  background-color: #007bff;
117
  }}
118
  .gr-examples img {{
119
+ width: 200px;
120
+ height: 200px;
121
  }}
122
  """) as demo:
123
  gr.Markdown("## Modulo Imaging for Computer Vision", elem_id="centered-title")
 
125
  with gr.Row():
126
  with gr.Column():
127
  gr.Markdown("### High Dynamic Range Modulo Imaging for Robust Object Detection in Autonomous Driving", elem_id="centered-text")
128
+ with gr.Row():
129
+ gr.HTML('<a href="https://openreview.net/pdf?id=2GqZFx2I7s" target="_blank" class="custom-button btn-grey">Article</a>')
130
+ gr.HTML('<a href="https://github.com/kebincontreras/Modulo_images.git" target="_blank" class="custom-button btn-blue">GitHub</a>')
131
+
132
  with gr.Column():
133
  gr.Markdown("### Autoregressive High-Order Finite Difference Modulo Imaging: High-Dynamic Range for Computer Vision Applications", elem_id="centered-text")
134
+ with gr.Row():
135
+ gr.HTML('<a href="https://cvlai.net/aim/2024/" target="_blank" class="custom-button btn-red">Article</a>')
136
+ gr.HTML('<a href="https://github.com/bemc22/AHFD" target="_blank" class="custom-button btn-blue">GitHub</a>')
137
 
138
  image = gr.Image(type="pil", label="Upload Image", interactive=True)
139
 
 
142
 
143
  selected_method = gr.Radio(
144
  label="Select Method",
145
+ choices=["AHFD","SPUD"],
146
  value="SPUD"
147
  )
148
 
149
  process_button = gr.Button("Process Image")
150
 
 
151
  examples = [
152
+ ["Add_ons/imagen1.png"],
153
+ ["Add_ons/imagen2.png"],
154
+ ["Add_ons/imagen3.jpg"],
155
+ ["Add_ons/imagen4.jpg"],
156
+ ["Add_ons/imagen5.jpg"],
157
+ ["Add_ons/imagen6.png"]
158
  ]
159
 
160
  gr.Examples(
 
177
  outputs=[output_original, output_clip, output_wrap, output_recons]
178
  )
179
 
 
 
 
 
 
 
 
 
 
180
  return demo
181
 
182
  if __name__ == "__main__":