Update app.py
Browse files
app.py
CHANGED
@@ -2,44 +2,47 @@ import gradio as gr
|
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
|
5 |
-
def apply_filter(image, filter_type):
|
|
|
|
|
|
|
6 |
if filter_type == "Grayscale":
|
7 |
# ํ๋ฐฑ ๋ณํ
|
8 |
return convert_to_grayscale(image)
|
9 |
elif filter_type == "Soft Glow":
|
10 |
# Soft Glow ํจ๊ณผ
|
11 |
gaussian = cv2.GaussianBlur(image, (15, 15), 0)
|
12 |
-
soft_glow = cv2.addWeighted(image,
|
13 |
return soft_glow
|
14 |
elif filter_type == "Portrait Enhancer":
|
15 |
# ๊ฐ๋จํ ํฌํธ๋ ์ดํธ ํฅ์ (๋ถ๋๋ฝ๊ฒ ์กฐ์ ๋ ๋๋น ๋ฐ ๋ฐ๊ธฐ)
|
16 |
-
enhanced = cv2.detailEnhance(image, sigma_s=5, sigma_r=0.1)
|
17 |
return enhanced
|
18 |
elif filter_type == "Warm Tone":
|
19 |
# ๋ฐ๋ปํ ํค ํจ๊ณผ (๋นจ๊ฐ ๋ฐ ๋
ธ๋ ํค์ ๊ฐ์กฐ)
|
20 |
-
increase_red = np.array([[1.2, 0.0, 0.0],
|
21 |
[0.0, 1.0, 0.0],
|
22 |
-
[0.0, 0.0, 0.
|
23 |
warm_image = cv2.transform(image, increase_red)
|
24 |
return warm_image
|
25 |
elif filter_type == "Cold Tone":
|
26 |
# ์ฐจ๊ฐ์ด ํค ํจ๊ณผ (ํ๋ ํค์ ๊ฐ์กฐ)
|
27 |
-
increase_blue = np.array([[0.
|
28 |
[0.0, 1.0, 0.0],
|
29 |
-
[0.0, 0.0, 1.2]])
|
30 |
cold_image = cv2.transform(image, increase_blue)
|
31 |
return cold_image
|
32 |
elif filter_type == "High-Key":
|
33 |
# High-Key ํจ๊ณผ (๋ฐ๊ธฐ ์ฆ๊ฐ)
|
34 |
-
high_key = cv2.convertScaleAbs(image, alpha=1.2, beta=30)
|
35 |
return high_key
|
36 |
elif filter_type == "Low-Key":
|
37 |
# Low-Key ํจ๊ณผ (๋ฐ๊ธฐ ๊ฐ์)
|
38 |
-
low_key = cv2.convertScaleAbs(image, alpha=0.
|
39 |
return low_key
|
40 |
elif filter_type == "Haze":
|
41 |
# Haze ํจ๊ณผ
|
42 |
-
haze = cv2.addWeighted(image, 0.
|
43 |
return haze
|
44 |
else:
|
45 |
return image
|
@@ -49,9 +52,9 @@ def convert_to_grayscale(image):
|
|
49 |
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
50 |
return gray_image
|
51 |
|
52 |
-
def convert_and_save(image, filter_type):
|
53 |
-
# ์ ํํ
|
54 |
-
filtered_image = apply_filter(image, filter_type)
|
55 |
# ์ด๋ฏธ์ง๋ฅผ ์ ์ฅ
|
56 |
output_path = "output.jpg"
|
57 |
cv2.imwrite(output_path, filtered_image)
|
@@ -65,11 +68,12 @@ iface = gr.Interface(
|
|
65 |
gr.Radio(
|
66 |
["Grayscale", "Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"],
|
67 |
label="ํํฐ ์ ํ"
|
68 |
-
)
|
|
|
69 |
],
|
70 |
outputs=["image", "file"],
|
71 |
title="์ด๋ฏธ์ง ํํฐ ๋ฐ ํ๋ฐฑ ๋ณํ๊ธฐ",
|
72 |
-
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ
|
73 |
)
|
74 |
|
75 |
iface.launch()
|
|
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
|
5 |
+
def apply_filter(image, filter_type, intensity):
|
6 |
+
# ๊ฐ๋๋ฅผ 0.0์์ 1.0 ์ฌ์ด๋ก ์ ๊ทํ
|
7 |
+
normalized_intensity = intensity / 100.0
|
8 |
+
|
9 |
if filter_type == "Grayscale":
|
10 |
# ํ๋ฐฑ ๋ณํ
|
11 |
return convert_to_grayscale(image)
|
12 |
elif filter_type == "Soft Glow":
|
13 |
# Soft Glow ํจ๊ณผ
|
14 |
gaussian = cv2.GaussianBlur(image, (15, 15), 0)
|
15 |
+
soft_glow = cv2.addWeighted(image, 1 - normalized_intensity, gaussian, normalized_intensity, 0)
|
16 |
return soft_glow
|
17 |
elif filter_type == "Portrait Enhancer":
|
18 |
# ๊ฐ๋จํ ํฌํธ๋ ์ดํธ ํฅ์ (๋ถ๋๋ฝ๊ฒ ์กฐ์ ๋ ๋๋น ๋ฐ ๋ฐ๊ธฐ)
|
19 |
+
enhanced = cv2.detailEnhance(image, sigma_s=5, sigma_r=0.1 + 0.15 * normalized_intensity)
|
20 |
return enhanced
|
21 |
elif filter_type == "Warm Tone":
|
22 |
# ๋ฐ๋ปํ ํค ํจ๊ณผ (๋นจ๊ฐ ๋ฐ ๋
ธ๋ ํค์ ๊ฐ์กฐ)
|
23 |
+
increase_red = np.array([[1.0 + 0.2 * normalized_intensity, 0.0, 0.0],
|
24 |
[0.0, 1.0, 0.0],
|
25 |
+
[0.0, 0.0, 1.0 - 0.2 * normalized_intensity]])
|
26 |
warm_image = cv2.transform(image, increase_red)
|
27 |
return warm_image
|
28 |
elif filter_type == "Cold Tone":
|
29 |
# ์ฐจ๊ฐ์ด ํค ํจ๊ณผ (ํ๋ ํค์ ๊ฐ์กฐ)
|
30 |
+
increase_blue = np.array([[1.0 - 0.2 * normalized_intensity, 0.0, 0.0],
|
31 |
[0.0, 1.0, 0.0],
|
32 |
+
[0.0, 0.0, 1.0 + 0.2 * normalized_intensity]])
|
33 |
cold_image = cv2.transform(image, increase_blue)
|
34 |
return cold_image
|
35 |
elif filter_type == "High-Key":
|
36 |
# High-Key ํจ๊ณผ (๋ฐ๊ธฐ ์ฆ๊ฐ)
|
37 |
+
high_key = cv2.convertScaleAbs(image, alpha=1.0 + 0.2 * normalized_intensity, beta=30)
|
38 |
return high_key
|
39 |
elif filter_type == "Low-Key":
|
40 |
# Low-Key ํจ๊ณผ (๋ฐ๊ธฐ ๊ฐ์)
|
41 |
+
low_key = cv2.convertScaleAbs(image, alpha=1.0 - 0.3 * normalized_intensity, beta=-30)
|
42 |
return low_key
|
43 |
elif filter_type == "Haze":
|
44 |
# Haze ํจ๊ณผ
|
45 |
+
haze = cv2.addWeighted(image, 1.0 - 0.3 * normalized_intensity, np.full(image.shape, 255, dtype=np.uint8), 0.3 * normalized_intensity, 0)
|
46 |
return haze
|
47 |
else:
|
48 |
return image
|
|
|
52 |
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
53 |
return gray_image
|
54 |
|
55 |
+
def convert_and_save(image, filter_type, intensity):
|
56 |
+
# ์ ํํ ํํฐ์ ๊ฐ๋๋ฅผ ์ด๋ฏธ์ง์ ์ ์ฉ
|
57 |
+
filtered_image = apply_filter(image, filter_type, intensity)
|
58 |
# ์ด๋ฏธ์ง๋ฅผ ์ ์ฅ
|
59 |
output_path = "output.jpg"
|
60 |
cv2.imwrite(output_path, filtered_image)
|
|
|
68 |
gr.Radio(
|
69 |
["Grayscale", "Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"],
|
70 |
label="ํํฐ ์ ํ"
|
71 |
+
),
|
72 |
+
gr.Slider(minimum=1, maximum=100, default=50, label="ํํฐ ๊ฐ๋")
|
73 |
],
|
74 |
outputs=["image", "file"],
|
75 |
title="์ด๋ฏธ์ง ํํฐ ๋ฐ ํ๋ฐฑ ๋ณํ๊ธฐ",
|
76 |
+
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ํํฐ์ ๊ฐ๋๋ฅผ ์ ํํ๋ฉด, ๋ณํ๋ ์ด๋ฏธ์ง๋ฅผ JPG ํ์ผ๋ก ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค."
|
77 |
)
|
78 |
|
79 |
iface.launch()
|