File size: 6,767 Bytes
ceddb8d e7acccd 8168e13 e7acccd f2280ce 8168e13 e7acccd 8168e13 d3188fd 8168e13 aa91e1a d3188fd e7acccd d3188fd aa91e1a 8168e13 e7acccd 8168e13 d3188fd 8168e13 d3188fd 8168e13 e7acccd 8168e13 d3188fd 8168e13 d3188fd 8168e13 d3188fd ceddb8d d3188fd ceddb8d 36ab4ca ceddb8d 36ab4ca e7acccd d3188fd ceddb8d 36ab4ca e7acccd 36ab4ca e7acccd 36ab4ca ceddb8d eb7aa6c aa91e1a e7acccd aa91e1a ceddb8d 36ab4ca ceddb8d 36ab4ca 3fa05ab e7acccd ceddb8d 36ab4ca e7acccd ceddb8d aa91e1a 36ab4ca aa91e1a e7acccd aa91e1a d3188fd 36ab4ca aa91e1a e7acccd aa91e1a 36ab4ca ceddb8d 0b1158e 36ab4ca 0b1158e 36ab4ca fb712ac aa91e1a fb712ac ceddb8d c40ae1d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
import gradio as gr
from Scripts.image_processing import apply_blur, clip_image, wrap_image
from Scripts.detection import yolov10_inference, calculate_detection_metrics
from PIL import Image
import numpy as np
import torchvision.transforms as transforms
import torch
from Scripts.utils import *
from Scripts.utils import modulo
from Scripts.utils_spud import * # Asegúrate de que las funciones necesarias estén importadas aquí
import cv2
import matplotlib.pyplot as plt
import packaging
IMAGE_SIZE = 640 # Asignar el valor constante para image_size
def process_image(image, model_id, sat_factor, selected_method):
conf_threshold = 0.85
correction = 1.0
kernel_size = 7
DO = 1
t = 0.7
vertical = True
original_image = np.array(image)
original_image = original_image - original_image.min()
original_image = original_image / original_image.max()
original_image = original_image * 255.0
original_image = original_image.astype(np.uint8)
scaling = 1.0
original_image = cv2.resize(original_image, (0, 0), fx=scaling, fy=scaling)
blurred_image = apply_blur(original_image / 255.0, kernel_size)
clipped_image = clip_image(blurred_image, correction, sat_factor)
img_tensor = torch.tensor(blurred_image, dtype=torch.float32).permute(2, 0, 1).unsqueeze(0)
img_tensor = modulo(img_tensor * sat_factor, L=1.0)
wrapped_image = img_tensor.squeeze(0).permute(1, 2, 0).numpy()
wrapped_image = (wrapped_image*255).astype(np.uint8)
original_annotated, original_detections = yolov10_inference(original_image, model_id, IMAGE_SIZE, conf_threshold)
clipped_annotated, clipped_detections = yolov10_inference((clipped_image*255.0).astype(np.uint8), "yolov10n", IMAGE_SIZE, conf_threshold)
wrapped_annotated, wrapped_detections = yolov10_inference(wrapped_image, model_id, IMAGE_SIZE, conf_threshold)
if selected_method == "SPUD":
# Uso de la función personalizada de SPUD
recon_image = recons_spud(img_tensor, threshold=0.1, mx=1.0)
else:
# Método por defecto AHFD
recon_image = recons(img_tensor, DO=DO, L=1.0, vertical=vertical, t=t)
recon_image_pil = transforms.ToPILImage()(recon_image.squeeze(0))
recon_image_np = np.array(recon_image_pil).astype(np.uint8)
recon_annotated, recon_detections = yolov10_inference(recon_image_np, model_id, IMAGE_SIZE, conf_threshold)
metrics_clip = calculate_detection_metrics(original_detections, clipped_detections)
metrics_wrap = calculate_detection_metrics(original_detections, wrapped_detections)
metrics_recons = calculate_detection_metrics(original_detections, recon_detections)
return original_annotated, clipped_annotated, wrapped_annotated, recon_annotated, metrics_clip, metrics_wrap, metrics_recons
def app():
image_scaler = 0.55
image_width = int(600 * image_scaler)
image_height = int(200 * image_scaler)
with gr.Blocks(css=f"""
.fixed-size-image img {{
width: {image_width}px;
height: {image_height}px;
object-fit: cover;
}}
.gr-row {{
display: flex;
justify-content: center;
align-items: center;
}}
.gr-column {{
display: flex;
flex-direction: row;
align-items: center;
padding: 0 !important;
margin: 0 !important;
}}
#centered-title {{
text-align: center;
}}
#centered-text {{
text-align: center;
margin-bottom: 10px;
}}
.custom-button {{
display: inline-block;
padding: 5px 10px;
font-size: 12px;
font-weight: bold;
color: white;
border-radius: 5px;
margin-right: 5px; /* Reducir el margen entre botones */
margin-bottom: 0px;
text-decoration: none;
text-align: center;
}}
.btn-grey {{
background-color: #4b4b4b;
}}
.btn-red {{
background-color: #e94e42;
}}
.btn-blue {{
background-color: #007bff;
}}
.gr-examples img {{
width: 200px;
height: 200px;
}}
""") as demo:
gr.Markdown("## Modulo Imaging for Computer Vision", elem_id="centered-title")
with gr.Row():
with gr.Column():
gr.Markdown("### High Dynamic Range Modulo Imaging for Robust Object Detection in Autonomous Driving", elem_id="centered-text")
with gr.Row():
gr.HTML('<a href="https://openreview.net/pdf?id=2GqZFx2I7s" target="_blank" class="custom-button btn-grey">Article</a>')
gr.HTML('<a href="https://github.com/kebincontreras/Modulo_images.git" target="_blank" class="custom-button btn-blue">GitHub</a>')
with gr.Column():
gr.Markdown("### Autoregressive High-Order Finite Difference Modulo Imaging: High-Dynamic Range for Computer Vision Applications", elem_id="centered-text")
with gr.Row():
gr.HTML('<a href="https://cvlai.net/aim/2024/" target="_blank" class="custom-button btn-red">Article</a>')
gr.HTML('<a href="https://github.com/bemc22/AHFD" target="_blank" class="custom-button btn-blue">GitHub</a>')
image = gr.Image(type="pil", label="Upload Image", interactive=True)
model_id = gr.Dropdown(label="Model", choices=["yolov10n", "yolov10s", "yolov10m", "yolov10b", "yolov10l", "yolov10x"], value="yolov10x")
sat_factor = gr.Slider(label="Saturation Factor", minimum=1.0, maximum=5.0, step=0.1, value=2.0)
selected_method = gr.Radio(
label="Select Method",
choices=["AHFD","SPUD"],
value="SPUD"
)
process_button = gr.Button("Process Image")
examples = [
["Add_ons/imagen1.png"],
["Add_ons/imagen2.png"],
["Add_ons/imagen3.jpg"],
["Add_ons/imagen4.jpg"],
["Add_ons/imagen5.jpg"],
["Add_ons/imagen6.png"]
]
gr.Examples(
examples=examples,
inputs=[image],
label="Choose an Example Image"
)
with gr.Row():
with gr.Column():
output_original = gr.Image(label="Ground Truth")
output_wrap = gr.Image(label="Modulo-ADC")
with gr.Column():
output_clip = gr.Image(label="CCD-Saturated")
output_recons = gr.Image(label="Modulo-ADC + Recovery")
process_button.click(
fn=process_image,
inputs=[image, model_id, sat_factor, selected_method],
outputs=[output_original, output_clip, output_wrap, output_recons]
)
return demo
if __name__ == "__main__":
app().launch()
|