Spaces:
Running
Running
umair-ahmad
commited on
Commit
·
56bba82
1
Parent(s):
8802940
initial commit
Browse files- app.py +32 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import skimage.feature
|
3 |
+
import numpy as np
|
4 |
+
import imageio.v3 as iio
|
5 |
+
|
6 |
+
|
7 |
+
def detect_edges(image:str, sigma, upper_thresh, lower_thresh)->np.ndarray:
|
8 |
+
|
9 |
+
if lower_thresh>upper_thresh:
|
10 |
+
gr.Warning(message="Lower threshold has to be lower than the upper threshold")
|
11 |
+
|
12 |
+
image = iio.imread(uri=image, mode="L").astype(np.uint8)
|
13 |
+
edges:np.ndarray = skimage.feature.canny(
|
14 |
+
image=image,
|
15 |
+
sigma=sigma,
|
16 |
+
low_threshold=lower_thresh,
|
17 |
+
high_threshold=upper_thresh,
|
18 |
+
)
|
19 |
+
return edges*255
|
20 |
+
|
21 |
+
edge_detector_interface = gr.Interface(
|
22 |
+
fn=detect_edges,
|
23 |
+
inputs=[
|
24 |
+
gr.Image(label="Input Image", type='filepath', height=400),
|
25 |
+
gr.Slider(minimum=0, maximum=33, label="Sigma"),
|
26 |
+
gr.Slider(minimum=0, maximum=10, label="Upper Threshold"),
|
27 |
+
gr.Slider(minimum=0, maximum=10, label="Lower Threshold"),
|
28 |
+
],
|
29 |
+
outputs=[gr.Image(label="Edge Detected Image", image_mode="L", height=400)]
|
30 |
+
)
|
31 |
+
|
32 |
+
edge_detector_interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
scikit-image==0.21.0
|