Spaces:
Runtime error
Runtime error
main.py
CHANGED
@@ -5,15 +5,22 @@ from cv2.ximgproc import guidedFilter
|
|
5 |
import gradio as gr
|
6 |
|
7 |
|
8 |
-
def clean_image(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
img = np.array(input_image).astype(np.float32)
|
10 |
y = img.copy()
|
11 |
|
12 |
for _ in range(64):
|
13 |
-
y = cv2.bilateralFilter(y,
|
14 |
|
15 |
for _ in range(4):
|
16 |
-
y = guidedFilter(img, y,
|
17 |
|
18 |
output_image = Image.fromarray(y.clip(0, 255).astype(np.uint8))
|
19 |
return output_image
|
@@ -34,13 +41,66 @@ def ui():
|
|
34 |
input_image = gr.Image(type="pil", label="Input Image")
|
35 |
start_btn = gr.Button(value="Start", variant="primary")
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
gr.Examples(
|
38 |
examples=[
|
39 |
["./examples/sample1.jpg"],
|
40 |
["./examples/sample2.jpg"],
|
41 |
["./examples/sample3.jpg"],
|
42 |
],
|
43 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
outputs=[],
|
45 |
fn=example,
|
46 |
cache_examples=True,
|
|
|
5 |
import gradio as gr
|
6 |
|
7 |
|
8 |
+
def clean_image(
|
9 |
+
input_image: Image,
|
10 |
+
diameter: float = 5,
|
11 |
+
sigma_color: float = 8,
|
12 |
+
sigma_space: float = 8,
|
13 |
+
radius: float = 4,
|
14 |
+
eps: float = 16,
|
15 |
+
) -> Image:
|
16 |
img = np.array(input_image).astype(np.float32)
|
17 |
y = img.copy()
|
18 |
|
19 |
for _ in range(64):
|
20 |
+
y = cv2.bilateralFilter(y, diameter, sigma_color, sigma_space)
|
21 |
|
22 |
for _ in range(4):
|
23 |
+
y = guidedFilter(img, y, radius, eps)
|
24 |
|
25 |
output_image = Image.fromarray(y.clip(0, 255).astype(np.uint8))
|
26 |
return output_image
|
|
|
41 |
input_image = gr.Image(type="pil", label="Input Image")
|
42 |
start_btn = gr.Button(value="Start", variant="primary")
|
43 |
|
44 |
+
with gr.Accordion("Advanced Config", open=False):
|
45 |
+
# ref: https://github.com/gogodr/AdverseCleanerExtension
|
46 |
+
gr.Markdown("#### Bilateral Filter")
|
47 |
+
diameter_slider = gr.Slider(
|
48 |
+
minimum=1,
|
49 |
+
maximum=30,
|
50 |
+
step=1,
|
51 |
+
value=5,
|
52 |
+
label="Diameter",
|
53 |
+
interactive=True,
|
54 |
+
)
|
55 |
+
sigma_color_slider = gr.Slider(
|
56 |
+
minimum=1,
|
57 |
+
maximum=30,
|
58 |
+
step=1,
|
59 |
+
value=8,
|
60 |
+
label="SigmaColor",
|
61 |
+
interactive=True,
|
62 |
+
)
|
63 |
+
sigma_space_slider = gr.Slider(
|
64 |
+
minimum=1,
|
65 |
+
maximum=30,
|
66 |
+
step=1,
|
67 |
+
value=8,
|
68 |
+
label="SigmaSpace",
|
69 |
+
interactive=True,
|
70 |
+
)
|
71 |
+
|
72 |
+
gr.Markdown("#### Guided Filter")
|
73 |
+
radius_slider = gr.Slider(
|
74 |
+
minimum=1,
|
75 |
+
maximum=30,
|
76 |
+
step=1,
|
77 |
+
value=4,
|
78 |
+
label="Radius",
|
79 |
+
interactive=True,
|
80 |
+
)
|
81 |
+
eps_slider = gr.Slider(
|
82 |
+
minimum=1,
|
83 |
+
maximum=30,
|
84 |
+
step=1,
|
85 |
+
value=16,
|
86 |
+
label="Accuracy",
|
87 |
+
interactive=True,
|
88 |
+
)
|
89 |
+
|
90 |
gr.Examples(
|
91 |
examples=[
|
92 |
["./examples/sample1.jpg"],
|
93 |
["./examples/sample2.jpg"],
|
94 |
["./examples/sample3.jpg"],
|
95 |
],
|
96 |
+
inputs=[
|
97 |
+
input_image,
|
98 |
+
diameter_slider,
|
99 |
+
sigma_color_slider,
|
100 |
+
sigma_space_slider,
|
101 |
+
radius_slider,
|
102 |
+
eps_slider,
|
103 |
+
],
|
104 |
outputs=[],
|
105 |
fn=example,
|
106 |
cache_examples=True,
|