|
import gradio as gr |
|
import cv2 |
|
import numpy as np |
|
|
|
def apply_filter(image, filter_type): |
|
|
|
if filter_type == "Soft Glow": |
|
image = cv2.GaussianBlur(image, (15, 15), 0) |
|
image = cv2.addWeighted(image, 1.5, cv2.GaussianBlur(image, (5, 5), 0), -0.5, 0) |
|
elif filter_type == "Portrait Enhancer": |
|
lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB) |
|
l, a, b = cv2.split(lab) |
|
l = cv2.equalizeHist(l) |
|
enhanced = cv2.merge((l, a, b)) |
|
image = cv2.cvtColor(enhanced, cv2.COLOR_LAB2BGR) |
|
elif filter_type == "Warm Tone": |
|
warm_filter = np.array([[[20, 10, 0]]], dtype=np.uint8) |
|
image = cv2.add(image, warm_filter) |
|
elif filter_type == "Cold Tone": |
|
cold_filter = np.array([[[-10, 0, 20]]], dtype=np.uint8) |
|
image = cv2.add(image, cold_filter) |
|
elif filter_type == "High-Key": |
|
image = cv2.addWeighted(image, 1.5, np.zeros_like(image, image.dtype), 0, 50) |
|
elif filter_type == "Low-Key": |
|
image = cv2.addWeighted(image, 0.8, np.zeros_like(image, image.dtype), 0, -50) |
|
elif filter_type == "Haze": |
|
haze_filter = cv2.GaussianBlur(image, (25, 25), 10) |
|
image = cv2.addWeighted(image, 0.8, haze_filter, 0.2, 0) |
|
return image |
|
|
|
def convert_and_save(image, filter_type): |
|
|
|
filtered_image = apply_filter(image, filter_type) |
|
|
|
gray_image = cv2.cvtColor(filtered_image, cv2.COLOR_BGR2GRAY) |
|
output_path = "output.jpg" |
|
cv2.imwrite(output_path, gray_image) |
|
return gray_image, output_path |
|
|
|
|
|
iface = gr.Interface( |
|
fn=convert_and_save, |
|
inputs=[ |
|
gr.Image(label="์ด๋ฏธ์ง ์
๋ก๋"), |
|
gr.Radio(["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="ํํฐ ์ ํ") |
|
], |
|
outputs=["image", "file"], |
|
title="์ด๋ฏธ์ง ํ๋ฐฑ ๋ณํ๊ธฐ", |
|
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ํํฐ๋ฅผ ์ ํํ ํ ํ๋ฐฑ์ผ๋ก ๋ณํ๋ ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค." |
|
) |
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|