Kims12 commited on
Commit
6e53669
ยท
verified ยท
1 Parent(s): 841fb88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -13
app.py CHANGED
@@ -7,60 +7,51 @@ def apply_filter(image, filter_type, intensity):
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
49
 
50
  def convert_to_grayscale(image):
51
- # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
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)
61
  return filtered_image, output_path
62
 
63
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
64
  iface = gr.Interface(
65
  fn=convert_and_save,
66
  inputs=[
 
7
  normalized_intensity = intensity / 100.0
8
 
9
  if filter_type == "Grayscale":
 
10
  return convert_to_grayscale(image)
11
  elif filter_type == "Soft Glow":
 
12
  gaussian = cv2.GaussianBlur(image, (15, 15), 0)
13
  soft_glow = cv2.addWeighted(image, 1 - normalized_intensity, gaussian, normalized_intensity, 0)
14
  return soft_glow
15
  elif filter_type == "Portrait Enhancer":
16
  # ๊ฐ„๋‹จํ•œ ํฌํŠธ๋ ˆ์ดํŠธ ํ–ฅ์ƒ (๋ถ€๋“œ๋Ÿฝ๊ฒŒ ์กฐ์ •๋œ ๋Œ€๋น„ ๋ฐ ๋ฐ๊ธฐ)
17
+ enhanced = cv2.detailEnhance(image, sigma_s=5, sigma_r=0.05 + 0.1 * normalized_intensity)
18
+ # ํ”ผ๋ถ€ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ์ถ”๊ฐ€์ ์ธ ๋ธ”๋Ÿฌ ์ ์šฉ
19
+ smoothed = cv2.bilateralFilter(enhanced, d=9, sigmaColor=75, sigmaSpace=75)
20
+ return smoothed
21
  elif filter_type == "Warm Tone":
 
22
  increase_red = np.array([[1.0 + 0.2 * normalized_intensity, 0.0, 0.0],
23
  [0.0, 1.0, 0.0],
24
  [0.0, 0.0, 1.0 - 0.2 * normalized_intensity]])
25
  warm_image = cv2.transform(image, increase_red)
26
  return warm_image
27
  elif filter_type == "Cold Tone":
 
28
  increase_blue = np.array([[1.0 - 0.2 * normalized_intensity, 0.0, 0.0],
29
  [0.0, 1.0, 0.0],
30
  [0.0, 0.0, 1.0 + 0.2 * normalized_intensity]])
31
  cold_image = cv2.transform(image, increase_blue)
32
  return cold_image
33
  elif filter_type == "High-Key":
 
34
  high_key = cv2.convertScaleAbs(image, alpha=1.0 + 0.2 * normalized_intensity, beta=30)
35
  return high_key
36
  elif filter_type == "Low-Key":
 
37
  low_key = cv2.convertScaleAbs(image, alpha=1.0 - 0.3 * normalized_intensity, beta=-30)
38
  return low_key
39
  elif filter_type == "Haze":
 
40
  haze = cv2.addWeighted(image, 1.0 - 0.3 * normalized_intensity, np.full(image.shape, 255, dtype=np.uint8), 0.3 * normalized_intensity, 0)
41
  return haze
42
  else:
43
  return image
44
 
45
  def convert_to_grayscale(image):
 
46
  gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
47
  return gray_image
48
 
49
  def convert_and_save(image, filter_type, intensity):
 
50
  filtered_image = apply_filter(image, filter_type, intensity)
 
51
  output_path = "output.jpg"
52
  cv2.imwrite(output_path, filtered_image)
53
  return filtered_image, output_path
54
 
 
55
  iface = gr.Interface(
56
  fn=convert_and_save,
57
  inputs=[