Kims12 commited on
Commit
0bee58f
โ€ข
1 Parent(s): dbdd417

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
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, 0.5, gaussian, 0.5, 0)
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.8]])
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.8, 0.0, 0.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.7, beta=-30)
39
  return low_key
40
  elif filter_type == "Haze":
41
  # Haze ํšจ๊ณผ
42
- haze = cv2.addWeighted(image, 0.7, np.full(image.shape, 255, dtype=np.uint8), 0.3, 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="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ•„ํ„ฐ(๋˜๋Š” ํ‘๋ฐฑ ๋ณ€ํ™˜)๋ฅผ ์„ ํƒํ•˜๋ฉด, ๋ณ€ํ™˜๋œ ์ด๋ฏธ์ง€๋ฅผ JPG ํŒŒ์ผ๋กœ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
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()