Kims12 commited on
Commit
24cb82a
โ€ข
1 Parent(s): 6808183

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -19
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(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
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 = cv2.cvtColor(np.array(image_pil), cv2.COLOR_RGB2BGR)
38
  return enhanced_image
39
  elif filter_type == "Warm Tone":
40
- # ๋”ฐ๋œปํ•œ ํ†ค ์ ์šฉ
41
- warm_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
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 = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
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) # ํ•„ํ„ฐ ์ ์šฉ ํ›„ ์ผ๊ด€์„ฑ์„ ์œ„ํ•ด BGR๋กœ ๋ณ€ํ™˜
64
 
65
  def convert_and_save(image, filter_type, intensity):
66
- filtered_image = apply_filter(image, filter_type, intensity)
 
67
 
68
- # numpy array๋ฅผ PIL ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜
69
- original_image_pil = Image.fromarray(cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR))
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