gabrielnkl commited on
Commit
56e5dd9
·
verified ·
1 Parent(s): 80d8f3a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+
5
+ # Define some basic convolution kernels
6
+ KERNELS = {
7
+ "Edge Detection": np.array([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]]),
8
+ "Sharpen": np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]]),
9
+ "Blur": np.ones((3, 3)) / 9,
10
+ "Emboss": np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]]),
11
+ }
12
+
13
+ def apply_convolution(image, kernel_name):
14
+ # Convert image to grayscale for simplicity
15
+ gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
16
+ kernel = KERNELS[kernel_name]
17
+ convolved = cv2.filter2D(gray, -1, kernel)
18
+ return convolved
19
+
20
+ # Define Gradio interface
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown("# Interactive Convolution Visualizer")
23
+ with gr.Row():
24
+ image_input = gr.Image(type="numpy", label="Upload Image")
25
+ kernel_dropdown = gr.Dropdown(choices=list(KERNELS.keys()), label="Select Kernel")
26
+ output_image = gr.Image(type="numpy", label="Processed Image")
27
+ process_button = gr.Button("Apply Convolution")
28
+
29
+ process_button.click(apply_convolution, inputs=[image_input, kernel_dropdown], outputs=output_image)
30
+
31
+ # Launch the app
32
+ demo.launch()