File size: 1,721 Bytes
8535875
 
678fc41
8535875
678fc41
 
 
 
 
 
8535875
678fc41
 
 
8535875
678fc41
 
 
8535875
678fc41
 
 
 
 
 
 
8535875
678fc41
 
 
 
 
 
 
8535875
678fc41
8535875
 
 
678fc41
c4d908c
678fc41
 
 
c4d908c
678fc41
8535875
678fc41
8535875
 
678fc41
 
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
import gradio as gr
import numpy as np
import cv2

def create_dot_effect(image, dot_size=10, spacing=2):
    # Convert to grayscale if image is color
    if len(image.shape) == 3:
        gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
    else:
        gray = image
    
    # Create a blank canvas
    height, width = gray.shape
    canvas = np.zeros_like(gray)
    
    # Calculate number of dots based on spacing
    y_dots = range(0, height, dot_size + spacing)
    x_dots = range(0, width, dot_size + spacing)
    
    # Create dots based on brightness
    for y in y_dots:
        for x in x_dots:
            # Get the average brightness of the region
            region = gray[y:min(y+dot_size, height), x:min(x+dot_size, width)]
            if region.size > 0:
                brightness = np.mean(region)
                
                # Draw circle if the region is bright enough
                if brightness > 30:  # Threshold can be adjusted
                    cv2.circle(canvas, 
                             (x + dot_size//2, y + dot_size//2), 
                             dot_size//2, 
                             (255), 
                             -1)
    
    return canvas

# Create Gradio interface
iface = gr.Interface(
    fn=create_dot_effect,
    inputs=[
        gr.Image(label="Input Image"),
        gr.Slider(minimum=2, maximum=20, value=10, step=1, label="Dot Size"),
        gr.Slider(minimum=0, maximum=10, value=2, step=1, label="Dot Spacing")
    ],
    outputs=gr.Image(label="Dotted Image"),
    title="ChatGPT Ad Maker",
    description="Convert your image into a dotted pattern. Adjust dot size and spacing using the sliders."
)

if __name__ == "__main__":
    iface.launch()