File size: 3,305 Bytes
ec0dbf0
 
 
 
0bee58f
 
 
 
58f5984
 
 
ec0dbf0
0bee58f
ec0dbf0
 
8c4ce03
 
42691c3
8c4ce03
 
42691c3
8c4ce03
 
42691c3
8c4ce03
 
 
 
ec0dbf0
0bee58f
50a5493
0bee58f
50a5493
ec0dbf0
 
0bee58f
50a5493
0bee58f
50a5493
ec0dbf0
 
0bee58f
ec0dbf0
 
0bee58f
ec0dbf0
 
0bee58f
ec0dbf0
 
 
 
58f5984
 
 
 
0bee58f
 
ec0dbf0
ee7d7d6
 
ec0dbf0
 
 
ee7d7d6
 
58f5984
50a5493
58f5984
0bee58f
841fb88
ee7d7d6
ec0dbf0
ee7d7d6
0bee58f
ec0dbf0
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import gradio as gr
import cv2
import numpy as np

def apply_filter(image, filter_type, intensity):
    # 강도λ₯Ό 0.0μ—μ„œ 1.0 μ‚¬μ΄λ‘œ μ •κ·œν™”
    normalized_intensity = intensity / 100.0

    if filter_type == "Grayscale":
        return convert_to_grayscale(image)
    elif filter_type == "Soft Glow":
        gaussian = cv2.GaussianBlur(image, (15, 15), 0)
        soft_glow = cv2.addWeighted(image, 1 - normalized_intensity, gaussian, normalized_intensity, 0)
        return soft_glow
    elif filter_type == "Portrait Enhancer":
        # Step 1: Detail Enhance 적용 (λ‹€μ†Œ κ°•ν•˜κ²Œ)
        enhanced = cv2.detailEnhance(image, sigma_s=10, sigma_r=0.1 + 0.1 * normalized_intensity)
        
        # Step 2: Gaussian Blur 적용 (강도 μ‘°μ •)
        blurred = cv2.GaussianBlur(enhanced, (5, 5), 0)
        
        # Step 3: Bilateral Filter 적용 (μ•½ν•˜κ²Œ, 경계 보쑴)
        smoothed = cv2.bilateralFilter(blurred, d=5, sigmaColor=50, sigmaSpace=50)
        
        # Step 4: 원본 이미지와 ν˜Όν•©ν•˜μ—¬ μ„ λͺ…함 μœ μ§€
        final_image = cv2.addWeighted(enhanced, 0.7, smoothed, 0.3, 0)
        
        return final_image
    elif filter_type == "Warm Tone":
        increase_red = np.array([[1.0 + 0.2 * normalized_intensity, 0.0, 0.0],
                                 [0.0, 1.0, 0.0],
                                 [0.0, 0.0, 1.0 - 0.2 * normalized_intensity]])
        warm_image = cv2.transform(image, increase_red)
        return warm_image
    elif filter_type == "Cold Tone":
        increase_blue = np.array([[1.0 - 0.2 * normalized_intensity, 0.0, 0.0],
                                  [0.0, 1.0, 0.0],
                                  [0.0, 0.0, 1.0 + 0.2 * normalized_intensity]])
        cold_image = cv2.transform(image, increase_blue)
        return cold_image
    elif filter_type == "High-Key":
        high_key = cv2.convertScaleAbs(image, alpha=1.0 + 0.2 * normalized_intensity, beta=30)
        return high_key
    elif filter_type == "Low-Key":
        low_key = cv2.convertScaleAbs(image, alpha=1.0 - 0.3 * normalized_intensity, beta=-30)
        return low_key
    elif filter_type == "Haze":
        haze = cv2.addWeighted(image, 1.0 - 0.3 * normalized_intensity, np.full(image.shape, 255, dtype=np.uint8), 0.3 * normalized_intensity, 0)
        return haze
    else:
        return image

def convert_to_grayscale(image):
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    return gray_image

def convert_and_save(image, filter_type, intensity):
    filtered_image = apply_filter(image, filter_type, intensity)
    output_path = "output.jpg"
    cv2.imwrite(output_path, filtered_image)
    return filtered_image, output_path

iface = gr.Interface(
    fn=convert_and_save, 
    inputs=[
        "image", 
        gr.Radio(
            ["Grayscale", "Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], 
            label="ν•„ν„° 선택"
        ),
        gr.Slider(minimum=1, maximum=100, value=50, label="ν•„ν„° 강도")
    ], 
    outputs=["image", "file"], 
    title="이미지 ν•„ν„° 및 흑백 λ³€ν™˜κΈ°",
    description="이미지λ₯Ό μ—…λ‘œλ“œν•˜κ³  필터와 강도λ₯Ό μ„ νƒν•˜λ©΄, λ³€ν™˜λœ 이미지λ₯Ό JPG 파일둜 λ‹€μš΄λ‘œλ“œν•  수 μžˆμŠ΅λ‹ˆλ‹€."
)

iface.launch()