5 samples in main
Browse files- DeFogify_Main.py +30 -7
DeFogify_Main.py
CHANGED
@@ -2,19 +2,19 @@ import cv2
|
|
2 |
import numpy as np
|
3 |
import gradio as gr
|
4 |
|
5 |
-
def dark_channel(img, size
|
6 |
r, g, b = cv2.split(img)
|
7 |
min_img = cv2.min(r, cv2.min(g, b))
|
8 |
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (size, size))
|
9 |
dc_img = cv2.erode(min_img, kernel)
|
10 |
return dc_img
|
11 |
|
12 |
-
def get_atmo(img, percent
|
13 |
-
mean_perpix = np.mean(img, axis
|
14 |
mean_topper = mean_perpix[:int(img.shape[0] * img.shape[1] * percent)]
|
15 |
return np.mean(mean_topper)
|
16 |
|
17 |
-
def get_trans(img, atom, w
|
18 |
x = img / atom
|
19 |
t = 1 - w * dark_channel(x, 15)
|
20 |
return t
|
@@ -48,8 +48,31 @@ def dehaze(image):
|
|
48 |
|
49 |
# Ensure the result is in the range [0, 1]
|
50 |
result = np.clip(result, 0, 1)
|
51 |
-
return (result * 255).astype(np.uint8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
# Create Gradio interface
|
54 |
-
PixelDehazer = gr.Interface(
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import numpy as np
|
3 |
import gradio as gr
|
4 |
|
5 |
+
def dark_channel(img, size=15):
|
6 |
r, g, b = cv2.split(img)
|
7 |
min_img = cv2.min(r, cv2.min(g, b))
|
8 |
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (size, size))
|
9 |
dc_img = cv2.erode(min_img, kernel)
|
10 |
return dc_img
|
11 |
|
12 |
+
def get_atmo(img, percent=0.001):
|
13 |
+
mean_perpix = np.mean(img, axis=2).reshape(-1)
|
14 |
mean_topper = mean_perpix[:int(img.shape[0] * img.shape[1] * percent)]
|
15 |
return np.mean(mean_topper)
|
16 |
|
17 |
+
def get_trans(img, atom, w=0.95):
|
18 |
x = img / atom
|
19 |
t = 1 - w * dark_channel(x, 15)
|
20 |
return t
|
|
|
48 |
|
49 |
# Ensure the result is in the range [0, 1]
|
50 |
result = np.clip(result, 0, 1)
|
51 |
+
return (result * 255).astype(np.uint8)
|
52 |
+
|
53 |
+
# Save example images for testing
|
54 |
+
example_images = [
|
55 |
+
"Sample Images for Testing/ai-generated-9025430_1280.jpg",
|
56 |
+
"Sample Images for Testing/meadow-5648849_1280.jpg",
|
57 |
+
"Sample Images for Testing/mountains-7662717_1280.jpg",
|
58 |
+
"Sample Images for Testing/mountains-8292685_1280.jpg",
|
59 |
+
"Sample Images for Testing/nature-6722031_1280.jpg"
|
60 |
+
]
|
61 |
+
|
62 |
+
example_paths = []
|
63 |
+
for i, img_path in enumerate(example_images):
|
64 |
+
img = cv2.imread(img_path)
|
65 |
+
save_path = f"example_image_{i+1}.png"
|
66 |
+
cv2.imwrite(save_path, img)
|
67 |
+
example_paths.append([save_path])
|
68 |
|
69 |
# Create Gradio interface
|
70 |
+
PixelDehazer = gr.Interface(
|
71 |
+
fn=dehaze,
|
72 |
+
inputs=gr.Image(type="numpy"),
|
73 |
+
outputs="image",
|
74 |
+
examples=example_paths,
|
75 |
+
cache_examples=False
|
76 |
+
)
|
77 |
+
|
78 |
+
PixelDehazer.launch()
|