Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,6 @@ def apply_filter(image, filter_type, intensity):
|
|
14 |
if filter_type == "Grayscale":
|
15 |
return convert_to_grayscale(image)
|
16 |
elif filter_type == "Soft Glow":
|
17 |
-
# ๊ธฐ๋ณธ 10% ๊ฐ๋์์ ์์ํ์ฌ ์ต๋ 100% ๊ฐ๋๊น์ง ์กฐ์
|
18 |
base_intensity = 0.1
|
19 |
adjusted_intensity = base_intensity + (normalized_intensity * (1 - base_intensity))
|
20 |
|
@@ -22,30 +21,25 @@ def apply_filter(image, filter_type, intensity):
|
|
22 |
soft_glow = cv2.addWeighted(image, 1 - adjusted_intensity, gaussian, adjusted_intensity, 0)
|
23 |
return soft_glow
|
24 |
elif filter_type == "Portrait Enhancer":
|
25 |
-
# ๊ธฐ๋ณธ 50% ๊ฐ๋์์ ์์ํ์ฌ ์ต๋ 100% ๊ฐ๋๊น์ง ์กฐ์
|
26 |
base_intensity = 0.5
|
27 |
adjusted_intensity = base_intensity + (normalized_intensity * (1 - base_intensity))
|
28 |
|
29 |
-
image_pil = Image.fromarray(
|
30 |
|
31 |
enhancer = ImageEnhance.Sharpness(image_pil)
|
32 |
-
image_pil = enhancer.enhance(1 + 0.5 * adjusted_intensity)
|
33 |
|
34 |
enhancer = ImageEnhance.Color(image_pil)
|
35 |
-
image_pil = enhancer.enhance(1 + 0.5 * adjusted_intensity)
|
36 |
|
37 |
-
enhanced_image =
|
38 |
return enhanced_image
|
39 |
elif filter_type == "Warm Tone":
|
40 |
-
|
41 |
-
warm_image
|
42 |
-
warm_image = cv2.applyColorMap(warm_image, cv2.COLORMAP_AUTUMN)
|
43 |
-
return cv2.cvtColor(warm_image, cv2.COLOR_RGB2BGR)
|
44 |
elif filter_type == "Cold Tone":
|
45 |
-
|
46 |
-
cold_image
|
47 |
-
cold_image = cv2.applyColorMap(cold_image, cv2.COLORMAP_WINTER)
|
48 |
-
return cv2.cvtColor(cold_image, cv2.COLOR_RGB2BGR)
|
49 |
elif filter_type == "High-Key":
|
50 |
high_key = cv2.convertScaleAbs(image, alpha=1.0 + 0.8 * normalized_intensity, beta=30)
|
51 |
return high_key
|
@@ -60,14 +54,15 @@ def apply_filter(image, filter_type, intensity):
|
|
60 |
|
61 |
def convert_to_grayscale(image):
|
62 |
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
63 |
-
return cv2.cvtColor(gray_image, cv2.COLOR_GRAY2BGR)
|
64 |
|
65 |
def convert_and_save(image, filter_type, intensity):
|
66 |
-
|
|
|
67 |
|
68 |
-
#
|
69 |
-
original_image_pil = Image.fromarray(cv2.cvtColor(
|
70 |
-
filtered_image_pil = Image.fromarray(filtered_image)
|
71 |
|
72 |
return original_image_pil, filtered_image_pil # ์๋ณธ๊ณผ ํํฐ ์ ์ฉ๋ ์ด๋ฏธ์ง๋ฅผ ๋ฐํ
|
73 |
|
|
|
14 |
if filter_type == "Grayscale":
|
15 |
return convert_to_grayscale(image)
|
16 |
elif filter_type == "Soft Glow":
|
|
|
17 |
base_intensity = 0.1
|
18 |
adjusted_intensity = base_intensity + (normalized_intensity * (1 - base_intensity))
|
19 |
|
|
|
21 |
soft_glow = cv2.addWeighted(image, 1 - adjusted_intensity, gaussian, adjusted_intensity, 0)
|
22 |
return soft_glow
|
23 |
elif filter_type == "Portrait Enhancer":
|
|
|
24 |
base_intensity = 0.5
|
25 |
adjusted_intensity = base_intensity + (normalized_intensity * (1 - base_intensity))
|
26 |
|
27 |
+
image_pil = Image.fromarray(image)
|
28 |
|
29 |
enhancer = ImageEnhance.Sharpness(image_pil)
|
30 |
+
image_pil = enhancer.enhance(1 + 0.5 * adjusted_intensity)
|
31 |
|
32 |
enhancer = ImageEnhance.Color(image_pil)
|
33 |
+
image_pil = enhancer.enhance(1 + 0.5 * adjusted_intensity)
|
34 |
|
35 |
+
enhanced_image = np.array(image_pil)
|
36 |
return enhanced_image
|
37 |
elif filter_type == "Warm Tone":
|
38 |
+
warm_image = cv2.applyColorMap(image, cv2.COLORMAP_AUTUMN)
|
39 |
+
return warm_image
|
|
|
|
|
40 |
elif filter_type == "Cold Tone":
|
41 |
+
cold_image = cv2.applyColorMap(image, cv2.COLORMAP_WINTER)
|
42 |
+
return cold_image
|
|
|
|
|
43 |
elif filter_type == "High-Key":
|
44 |
high_key = cv2.convertScaleAbs(image, alpha=1.0 + 0.8 * normalized_intensity, beta=30)
|
45 |
return high_key
|
|
|
54 |
|
55 |
def convert_to_grayscale(image):
|
56 |
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
57 |
+
return cv2.cvtColor(gray_image, cv2.COLOR_GRAY2BGR)
|
58 |
|
59 |
def convert_and_save(image, filter_type, intensity):
|
60 |
+
image_cv = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
61 |
+
filtered_image = apply_filter(image_cv, filter_type, intensity)
|
62 |
|
63 |
+
# OpenCV ์ด๋ฏธ์ง๋ฅผ ๋ค์ PIL๋ก ๋ณํ
|
64 |
+
original_image_pil = Image.fromarray(cv2.cvtColor(image_cv, cv2.COLOR_BGR2RGB))
|
65 |
+
filtered_image_pil = Image.fromarray(cv2.cvtColor(filtered_image, cv2.COLOR_BGR2RGB))
|
66 |
|
67 |
return original_image_pil, filtered_image_pil # ์๋ณธ๊ณผ ํํฐ ์ ์ฉ๋ ์ด๋ฏธ์ง๋ฅผ ๋ฐํ
|
68 |
|