Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2 as cv
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
def change_image_color(img, option, color_from=None, color_to=None):
|
| 6 |
+
# Orijinal görüntüyü oku
|
| 7 |
+
img_bgr = img.copy()
|
| 8 |
+
|
| 9 |
+
if option == "R-G (Kırmızı Yeşile)":
|
| 10 |
+
# Kırmızıları yeşil yap
|
| 11 |
+
b, g, r = cv.split(img_bgr)
|
| 12 |
+
new_img = cv.merge([b, r, g])
|
| 13 |
+
return new_img
|
| 14 |
+
elif option == "G-R (Yeşil Kırmızıya)":
|
| 15 |
+
# Yeşili kırmızıya çevir
|
| 16 |
+
b, g, r = cv.split(img_bgr)
|
| 17 |
+
new_img = cv.merge([b, g, r])
|
| 18 |
+
return new_img
|
| 19 |
+
elif option == "R-B (Kırmızı Maviye)":
|
| 20 |
+
# Kırmızıyı maviye çevir
|
| 21 |
+
b, g, r = cv.split(img_bgr)
|
| 22 |
+
new_img = cv.merge([r, g, b])
|
| 23 |
+
return new_img
|
| 24 |
+
elif option == "Gri Tonlamalı":
|
| 25 |
+
# Gri tonlamalı görüntü
|
| 26 |
+
gray_img = cv.cvtColor(img_bgr, cv.COLOR_BGR2GRAY)
|
| 27 |
+
return cv.cvtColor(gray_img, cv.COLOR_GRAY2RGB)
|
| 28 |
+
elif option == "Özel Renk Dönüşümü" and color_from is not None and color_to is not None:
|
| 29 |
+
# Belirli bir rengi başka bir renge dönüştür
|
| 30 |
+
color_from_bgr = [int(color_from[i:i+2], 16) for i in (1, 3, 5)]
|
| 31 |
+
color_to_bgr = [int(color_to[i:i+2], 16) for i in (1, 3, 5)]
|
| 32 |
+
lower_bound = np.array(color_from_bgr, dtype="uint8")
|
| 33 |
+
upper_bound = lower_bound
|
| 34 |
+
mask = cv.inRange(img_bgr, lower_bound, upper_bound)
|
| 35 |
+
img_bgr[mask != 0] = color_to_bgr
|
| 36 |
+
return img_bgr
|
| 37 |
+
else:
|
| 38 |
+
# Orijinal görüntü
|
| 39 |
+
return img_bgr
|
| 40 |
+
|
| 41 |
+
# Gradio arayüzü tanımla
|
| 42 |
+
interface = gr.Interface(
|
| 43 |
+
fn=change_image_color,
|
| 44 |
+
inputs=[
|
| 45 |
+
gr.Image(type="numpy", label="Resim Yükleyin"),
|
| 46 |
+
gr.Dropdown(["Orijinal", "R-G (Kırmızı Yeşile)", "G-R (Yeşil Kırmızıya)", "R-B (Kırmızı Maviye)", "Gri Tonlamalı", "Özel Renk Dönüşümü"], label="Dönüşüm Seçin"),
|
| 47 |
+
gr.ColorPicker(label="Dönüştürülecek Renk"),
|
| 48 |
+
gr.ColorPicker(label="Yeni Renk")
|
| 49 |
+
],
|
| 50 |
+
outputs="image",
|
| 51 |
+
title="Renk Dönüştürme Aracı",
|
| 52 |
+
description="Resmin rengini dönüştürmek için bir seçenek belirleyin ve isterseniz belirli bir rengi başka bir renge dönüştürün."
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Arayüzü başlat
|
| 56 |
+
interface.launch()
|