File size: 1,074 Bytes
56bba82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7040660
 
 
56bba82
 
 
 
 
 
 
 
 
 
 
 
13d16a8
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
import gradio as gr
import skimage.feature
import numpy as np
import imageio.v3 as iio


def detect_edges(image:str, sigma, upper_thresh, lower_thresh)->np.ndarray:
    
    if lower_thresh>upper_thresh:
        gr.Warning(message="Lower threshold has to be lower than the upper threshold")
    
    image = iio.imread(uri=image, mode="L").astype(np.uint8)
    edges:np.ndarray = skimage.feature.canny(
        image=image,
        sigma=sigma,
        low_threshold=lower_thresh,
        high_threshold=upper_thresh,
    )
    edges = edges*255
    inverted_image_array = 255 - edges
    return inverted_image_array

edge_detector_interface = gr.Interface(
    fn=detect_edges,
    inputs=[
        gr.Image(label="Input Image", type='filepath', height=400),
        gr.Slider(minimum=0, maximum=33, label="Sigma"),
        gr.Slider(minimum=0, maximum=10, label="Upper Threshold"),
        gr.Slider(minimum=0, maximum=10, label="Lower Threshold"),
    ],
    outputs=[gr.Image(label="Edge Detected Image", image_mode="L", height=400)]
)

edge_detector_interface.launch()