kebincontreras commited on
Commit
8168e13
·
verified ·
1 Parent(s): a4ed2cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py CHANGED
@@ -1,4 +1,58 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def app():
4
  # Variables para ajustar el tamaño de las imágenes
 
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 flip_odd_lines, modulo, center_modulo, unmodulo, hard_thresholding, stripe_estimation, recons
10
+ from utils import modulo
11
+ import cv2
12
+
13
+ import matplotlib.pyplot as plt
14
+
15
+ def process_image(image, model_id, image_size, conf_threshold, correction, sat_factor, kernel_size, DO, t, vertical):
16
+
17
+ original_image = np.array(image)
18
+ original_image = original_image - original_image.min()
19
+ original_image = original_image / original_image.max()
20
+ original_image = original_image * 255.0
21
+ original_image = original_image.astype(np.uint8)
22
+
23
+ # scaling factor
24
+ scaling = 1.0
25
+ original_image = cv2.resize(original_image, (0, 0), fx=scaling, fy=scaling)
26
+
27
+
28
+ blurred_image = apply_blur(original_image / 255.0, kernel_size)
29
+ clipped_image = clip_image(blurred_image, correction, sat_factor)
30
+
31
+ img_tensor = torch.tensor(blurred_image, dtype=torch.float32 ).permute(2, 0, 1).unsqueeze(0)
32
+ img_tensor = modulo( img_tensor * sat_factor, L=1.0)
33
+
34
+ wrapped_image = img_tensor.squeeze(0).permute(1, 2, 0).numpy()
35
+ wrapped_image = (wrapped_image*255).astype(np.uint8)
36
+
37
+ original_annotated, original_detections = yolov10_inference(original_image, model_id, image_size, conf_threshold)
38
+ clipped_annotated, clipped_detections = yolov10_inference((clipped_image*255.0).astype(np.uint8), "yolov10n", image_size, conf_threshold)
39
+ wrapped_annotated, wrapped_detections = yolov10_inference(wrapped_image, model_id, image_size, conf_threshold)
40
+
41
+ # Assuming `recons` is a function in `utils.py`
42
+ recon_image = recons(img_tensor, DO=1, L=1.0, vertical=(vertical == "True"), t=t)
43
+ recon_image_pil = transforms.ToPILImage()(recon_image.squeeze(0))
44
+ recon_image_np = np.array(recon_image_pil).astype(np.uint8)
45
+
46
+
47
+ recon_annotated, recon_detections = yolov10_inference(recon_image_np, model_id, image_size, conf_threshold)
48
+
49
+ metrics_clip = calculate_detection_metrics(original_detections, clipped_detections)
50
+ metrics_wrap = calculate_detection_metrics(original_detections, wrapped_detections)
51
+ metrics_recons = calculate_detection_metrics(original_detections, recon_detections)
52
+
53
+ return original_annotated, clipped_annotated, wrapped_annotated, recon_annotated, metrics_clip, metrics_wrap, metrics_recons
54
+
55
+
56
 
57
  def app():
58
  # Variables para ajustar el tamaño de las imágenes