File size: 2,386 Bytes
f559527 9bb5cf1 f559527 9bb5cf1 f559527 9bb5cf1 f559527 9bb5cf1 f559527 9bb5cf1 | 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 | import gradio as gr
import cv2
import numpy as np
def convert_to_grayscale(image):
# ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํ
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
return gray_image
def apply_filter(image, filter_type):
if filter_type == "Soft Glow":
# ๋ถ๋๋ฌ์ด ๋น ํจ๊ณผ
blurred = cv2.GaussianBlur(image, (15, 15), 0)
soft_glow = cv2.addWeighted(image, 0.5, blurred, 0.5, 0)
return soft_glow
elif filter_type == "Portrait Enhancer":
# ์ด์ํ ๊ฐํ ํจ๊ณผ
kernel = np.array([[0, -1, 0], [-1, 5,-1], [0, -1, 0]])
enhanced = cv2.filter2D(image, -1, kernel)
return enhanced
elif filter_type == "Warm Tone":
# ๋ฐ๋ปํ ํค ํจ๊ณผ
warm = cv2.applyColorMap(image, cv2.COLORMAP_AUTUMN)
return warm
elif filter_type == "Cold Tone":
# ์ฐจ๊ฐ์ด ํค ํจ๊ณผ
cold = cv2.applyColorMap(image, cv2.COLORMAP_WINTER)
return cold
elif filter_type == "High-Key":
# ํ์ดํค ํจ๊ณผ
high_key = cv2.convertScaleAbs(image, alpha=1.2, beta=50)
return high_key
elif filter_type == "Low-Key":
# ๋ก์ฐํค ํจ๊ณผ
low_key = cv2.convertScaleAbs(image, alpha=0.8, beta=-30)
return low_key
elif filter_type == "Haze":
# ํค์ด์ฆ ํจ๊ณผ
haze = cv2.addWeighted(image, 0.8, np.full(image.shape, 255, dtype=np.uint8), 0.2, 0)
return haze
else:
# ํํฐ๊ฐ ์ ํ๋์ง ์์์ ๊ฒฝ์ฐ ์๋ณธ ๋ฐํ
return image
def convert_and_save_with_filter(image, filter_type):
# ์ ํํ ํํฐ ์ ์ฉ ๋ฐ ํ๋ฐฑ ๋ณํ
filtered_image = apply_filter(image, filter_type)
gray_image = convert_to_grayscale(filtered_image)
output_path = "output.jpg"
cv2.imwrite(output_path, gray_image)
return gray_image, output_path
# Gradio ์ธํฐํ์ด์ค ์ ์
iface = gr.Interface(
fn=convert_and_save_with_filter,
inputs=["image", gr.Radio(["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="Select Filter")],
outputs=["image", "file"],
title="์ด๋ฏธ์ง ํ๋ฐฑ ๋ณํ๊ธฐ ๋ฐ ํํฐ ์ ์ฉ",
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ํํฐ๋ฅผ ์ ํํ๋ฉด ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ JPG ํ์ผ๋ก ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค."
)
if __name__ == "__main__":
iface.launch()
|