Spaces:
Sleeping
Sleeping
| import cv2 | |
| import numpy as np | |
| import gradio as gr | |
| # Mozaik Efekti | |
| def apply_mosaic_filter(frame, block_size=20): | |
| (h, w) = frame.shape[:2] | |
| y_blocks = h // block_size | |
| x_blocks = w // block_size | |
| for y in range(y_blocks): | |
| for x in range(x_blocks): | |
| x_start, y_start = x * block_size, y * block_size | |
| x_end, y_end = x_start + block_size, y_start + block_size | |
| block = frame[y_start:y_end, x_start:x_end] | |
| color = cv2.mean(block)[:3] | |
| frame[y_start:y_end, x_start:x_end] = color | |
| return frame | |
| def apply_color_change(frame, red_ratio=1.5, green_ratio=1.0, blue_ratio=0.5): | |
| b, g, r = cv2.split(frame) | |
| r = cv2.multiply(r, red_ratio) | |
| g = cv2.multiply(g, green_ratio) | |
| b = cv2.multiply(b, blue_ratio) | |
| frame = cv2.merge((b, g, r)) | |
| return frame | |
| # Gradio arayüzü | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Mozaik ve Renk Değiştirme") | |
| # Filtre Seçimi | |
| filter_type = gr.Dropdown( | |
| label="Filtre Seçin", | |
| choices=["Mozaik", "Renk Değiştirme"], | |
| value="Mozaik" | |
| ) | |
| input_image = gr.Image(label="Görüntü Yükle", type="numpy", height=200, width=200) | |
| output_image = gr.Image(label="Filtre Uygulandı", height=200, width=200) | |
| def apply_filter(filter_type, input_image=None): | |
| if input_image is not None: | |
| if filter_type == "Mozaik": | |
| return apply_mosaic_filter(input_image, block_size=20) | |
| elif filter_type == "Renk Değiştirme": | |
| return apply_color_change(input_image, red_ratio=1.5, green_ratio=0.5, blue_ratio=1.2) | |
| return input_image | |
| input_image.change(fn=apply_filter, inputs=[filter_type, input_image], outputs=output_image) | |
| filter_type.change(fn=apply_filter, inputs=[filter_type, input_image], outputs=output_image) | |
| demo.launch() | |