File size: 1,877 Bytes
8413040
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()