File size: 2,520 Bytes
ec0dbf0 58f5984 ec0dbf0 58f5984 ec0dbf0 ee7d7d6 ec0dbf0 ee7d7d6 58f5984 ee7d7d6 ec0dbf0 ee7d7d6 58f5984 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 |
import gradio as gr
import cv2
import numpy as np
def apply_filter(image, filter_type):
if filter_type == "Grayscale":
# ํ๋ฐฑ ๋ณํ
return convert_to_grayscale(image)
elif filter_type == "Soft Glow":
# Soft Glow ํจ๊ณผ
gaussian = cv2.GaussianBlur(image, (15, 15), 0)
soft_glow = cv2.addWeighted(image, 0.5, gaussian, 0.5, 0)
return soft_glow
elif filter_type == "Portrait Enhancer":
# ๊ฐ๋จํ ํฌํธ๋ ์ดํธ ํฅ์ (์: ๋๋น ๋ฐ ๋ฐ๊ธฐ ์กฐ์ )
enhanced = cv2.detailEnhance(image, sigma_s=10, sigma_r=0.15)
return enhanced
elif filter_type == "Warm Tone":
# ๋ฐ๋ปํ ํค ํจ๊ณผ
warm_image = cv2.applyColorMap(image, cv2.COLORMAP_AUTUMN)
return warm_image
elif filter_type == "Cold Tone":
# ์ฐจ๊ฐ์ด ํค ํจ๊ณผ
cold_image = cv2.applyColorMap(image, cv2.COLORMAP_WINTER)
return cold_image
elif filter_type == "High-Key":
# High-Key ํจ๊ณผ (๋ฐ๊ธฐ ์ฆ๊ฐ)
high_key = cv2.convertScaleAbs(image, alpha=1.2, beta=30)
return high_key
elif filter_type == "Low-Key":
# Low-Key ํจ๊ณผ (๋ฐ๊ธฐ ๊ฐ์)
low_key = cv2.convertScaleAbs(image, alpha=0.7, beta=-30)
return low_key
elif filter_type == "Haze":
# Haze ํจ๊ณผ
haze = cv2.addWeighted(image, 0.7, np.full(image.shape, 255, dtype=np.uint8), 0.3, 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):
# ์ ํํ ํํฐ๋ฅผ ์ด๋ฏธ์ง์ ์ ์ฉ
filtered_image = apply_filter(image, filter_type)
# ์ด๋ฏธ์ง๋ฅผ ์ ์ฅ
output_path = "output.jpg"
cv2.imwrite(output_path, filtered_image)
return filtered_image, output_path
# Gradio ์ธํฐํ์ด์ค ์ ์
iface = gr.Interface(
fn=convert_and_save,
inputs=[
"image",
gr.Radio(
["None", "Grayscale", "Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"],
label="ํํฐ ์ ํ"
)
],
outputs=["image", "file"],
title="์ด๋ฏธ์ง ํํฐ ๋ฐ ํ๋ฐฑ ๋ณํ๊ธฐ",
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ํํฐ(๋๋ ํ๋ฐฑ ๋ณํ)๋ฅผ ์ ํํ๋ฉด, ๋ณํ๋ ์ด๋ฏธ์ง๋ฅผ JPG ํ์ผ๋ก ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค."
)
iface.launch()
|