Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +57 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Mozaik Efekti
|
| 6 |
+
def apply_mosaic_filter(frame, block_size=20):
|
| 7 |
+
(h, w) = frame.shape[:2]
|
| 8 |
+
y_blocks = h // block_size
|
| 9 |
+
x_blocks = w // block_size
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
for y in range(y_blocks):
|
| 13 |
+
for x in range(x_blocks):
|
| 14 |
+
x_start, y_start = x * block_size, y * block_size
|
| 15 |
+
x_end, y_end = x_start + block_size, y_start + block_size
|
| 16 |
+
block = frame[y_start:y_end, x_start:x_end]
|
| 17 |
+
color = cv2.mean(block)[:3]
|
| 18 |
+
frame[y_start:y_end, x_start:x_end] = color
|
| 19 |
+
return frame
|
| 20 |
+
|
| 21 |
+
def apply_color_change(frame, red_ratio=1.5, green_ratio=1.0, blue_ratio=0.5):
|
| 22 |
+
b, g, r = cv2.split(frame)
|
| 23 |
+
r = cv2.multiply(r, red_ratio)
|
| 24 |
+
g = cv2.multiply(g, green_ratio)
|
| 25 |
+
b = cv2.multiply(b, blue_ratio)
|
| 26 |
+
frame = cv2.merge((b, g, r))
|
| 27 |
+
return frame
|
| 28 |
+
|
| 29 |
+
# Gradio arayüzü
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("# Özgün Görüntü İşleme Projesi: Mozaik ve Renk Değiştirme")
|
| 32 |
+
|
| 33 |
+
# Filtre Seçimi
|
| 34 |
+
filter_type = gr.Dropdown(
|
| 35 |
+
label="Filtre Seçin",
|
| 36 |
+
choices=["Mozaik", "Renk Değiştirme"],
|
| 37 |
+
value="Mozaik"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
input_image = gr.Image(label="Görüntü Yükle", type="numpy", height=200, width=200)
|
| 42 |
+
output_image = gr.Image(label="Filtre Uygulandı", height=200, width=200)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def apply_filter(filter_type, input_image=None):
|
| 46 |
+
if input_image is not None:
|
| 47 |
+
if filter_type == "Mozaik":
|
| 48 |
+
return apply_mosaic_filter(input_image, block_size=20)
|
| 49 |
+
elif filter_type == "Renk Değiştirme":
|
| 50 |
+
return apply_color_change(input_image, red_ratio=1.5, green_ratio=0.5, blue_ratio=1.2)
|
| 51 |
+
return input_image
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
input_image.change(fn=apply_filter, inputs=[filter_type, input_image], outputs=output_image)
|
| 55 |
+
filter_type.change(fn=apply_filter, inputs=[filter_type, input_image], outputs=output_image)
|
| 56 |
+
|
| 57 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
opencv-python
|
| 2 |
+
numpy
|
| 3 |
+
gradio
|