edge-detection / app.py
umairahmad1789's picture
update inversion code
7040660 verified
raw
history blame
1.07 kB
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()