| import gradio as gr |
| import cv2 |
| import numpy as np |
|
|
| def apply_filter(image, filter_type, alpha, beta): |
| if filter_type == "Soft Glow": |
| gaussian = cv2.GaussianBlur(image, (15, 15), 0) |
| soft_glow = cv2.addWeighted(image, 0.5, gaussian, 0.5, 0) |
| result = soft_glow |
| elif filter_type == "Portrait Enhancer": |
| result = cv2.detailEnhance(image, sigma_s=10, sigma_r=0.15) |
| elif filter_type == "Warm Tone": |
| result = cv2.applyColorMap(image, cv2.COLORMAP_AUTUMN) |
| elif filter_type == "Cold Tone": |
| result = cv2.applyColorMap(image, cv2.COLORMAP_WINTER) |
| elif filter_type == "High-Key": |
| result = cv2.convertScaleAbs(image, alpha=1.2, beta=30) |
| elif filter_type == "Low-Key": |
| result = cv2.convertScaleAbs(image, alpha=0.7, beta=-30) |
| elif filter_type == "Haze": |
| haze = cv2.addWeighted(image, 0.7, np.full(image.shape, 255, dtype=np.uint8), 0.3, 0) |
| result = haze |
| else: |
| result = image |
|
|
| |
| adjusted = cv2.convertScaleAbs(result, alpha=alpha, beta=beta) |
| return adjusted |
|
|
| def live_preview(image, filter_type, alpha, beta): |
| |
| processed_image = apply_filter(image, filter_type, alpha, beta) |
| return processed_image |
|
|
| |
| iface = gr.Interface( |
| fn=live_preview, |
| inputs=[ |
| "image", |
| gr.Radio( |
| ["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], |
| label="필터 선택" |
| ), |
| gr.Slider(0.5, 2.0, step=0.1, value=1.0, label="밝기 (alpha)"), |
| gr.Slider(-100, 100, step=10, value=0, label="대비 (beta)") |
| ], |
| outputs="image", |
| live=True, |
| title="컬러 이미지 편집기", |
| description="이미지를 업로드하고 필터를 선택한 후 밝기와 대비를 실시간으로 조절하세요." |
| ) |
|
|
| iface.launch() |
|
|