|
import cv2 |
|
import numpy as np |
|
import gradio as gr |
|
import matplotlib.pyplot as plt |
|
|
|
def gradient_magnitude_edge_detection(image_path, threshold): |
|
|
|
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) |
|
|
|
|
|
gradient_x = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=3) |
|
gradient_y = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=3) |
|
|
|
|
|
gradient_magnitude = np.sqrt(gradient_x**2 + gradient_y**2) |
|
|
|
|
|
edges = (gradient_magnitude > threshold) * 255 |
|
return edges |
|
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
fn=gradient_magnitude_edge_detection, |
|
inputs=[ |
|
gr.Image(type="filepath", label="Select Image"), |
|
gr.Slider(minimum=0, maximum=255, value=50, label="Threshold") |
|
], |
|
outputs="image", |
|
live=True |
|
) |
|
|
|
|
|
iface.launch() |
|
|