Spaces:
Sleeping
Sleeping
| 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, | |
| ) | |
| return edges*255 | |
| 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() |