chenyingxu commited on
Commit
34f62d8
·
verified ·
1 Parent(s): be24459

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -5,6 +5,7 @@ import gradio as gr
5
  import cv2
6
  import os
7
  from PIL import Image
 
8
  import torchvision.transforms as transforms
9
 
10
  # 🧠 Neural network layers
@@ -106,7 +107,7 @@ def predict(input_img, ver):
106
  transform = transforms.Compose([
107
  transforms.Resize(512, Image.BICUBIC),
108
  transforms.ToTensor(),
109
- transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
110
  ])
111
 
112
  # Apply the transformation
@@ -121,11 +122,19 @@ def predict(input_img, ver):
121
  output = model1(input_tensor)
122
 
123
  # Convert the output tensor to an image
124
- output_img = transforms.ToPILImage()(output.squeeze().cpu().clamp(0, 1))
125
 
126
  # Resize the output image back to the original size
127
  output_img = output_img.resize(original_size, Image.BICUBIC)
128
 
 
 
 
 
 
 
 
 
129
  return output_img
130
 
131
  # 📝 Title for the Gradio interface
 
5
  import cv2
6
  import os
7
  from PIL import Image
8
+ from PIL import ImageEnhance
9
  import torchvision.transforms as transforms
10
 
11
  # 🧠 Neural network layers
 
107
  transform = transforms.Compose([
108
  transforms.Resize(512, Image.BICUBIC),
109
  transforms.ToTensor(),
110
+ transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) # Normalize to [-1, 1]
111
  ])
112
 
113
  # Apply the transformation
 
122
  output = model1(input_tensor)
123
 
124
  # Convert the output tensor to an image
125
+ output_img = transforms.ToPILImage()(output.squeeze().cpu().clamp(0, 1)) # Clamp the output to [0, 1]
126
 
127
  # Resize the output image back to the original size
128
  output_img = output_img.resize(original_size, Image.BICUBIC)
129
 
130
+ # Enhance the contrast to make the black areas deeper
131
+ enhancer = ImageEnhance.Contrast(output_img)
132
+ output_img = enhancer.enhance(2.0) # Increase contrast (values > 1 increase contrast, < 1 reduce contrast)
133
+
134
+ # Optionally enhance the brightness slightly if the image is still too dark
135
+ brightness_enhancer = ImageEnhance.Brightness(output_img)
136
+ output_img = brightness_enhancer.enhance(1.0) # Keep brightness the same, adjust if needed
137
+
138
  return output_img
139
 
140
  # 📝 Title for the Gradio interface