topcla commited on
Commit
22812b5
1 Parent(s): 9c3817a

initial commit

Browse files
Files changed (2) hide show
  1. app.py +33 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+
5
+ st.set_page_config(layout="wide")
6
+
7
+
8
+ def extract_edges(img, blur, ksize, sobel_scale):
9
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
10
+ gray = cv2.GaussianBlur(gray, (blur, blur), 0)
11
+ x = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=ksize, scale=scale)
12
+ y = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=ksize, scale=scale)
13
+ absx= cv2.convertScaleAbs(x)
14
+ absy = cv2.convertScaleAbs(y)
15
+ edge = cv2.addWeighted(absx, 0.5, absy, 0.5, 0)
16
+ return cv2.bitwise_not(edge)
17
+
18
+
19
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpeg", "jpg", "png"])
20
+ ksize = st.sidebar.slider("Kernel size", min_value=3, max_value=19, value=5, step=2)
21
+ scale = st.sidebar.slider("Scale", min_value=0.0, max_value=1.0, value=0.25, step=0.05)
22
+ blur = st.sidebar.slider("Gaussian blur", min_value=3, max_value=99, value=5, step=2)
23
+
24
+
25
+ if uploaded_file is not None:
26
+ img = cv2.imdecode(np.asarray(bytearray(uploaded_file.read()), dtype="uint8"), flags=cv2.IMREAD_COLOR)
27
+
28
+ col1, col2 = st.columns(2)
29
+ with col1:
30
+ st.image(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
31
+
32
+ with col2:
33
+ st.image(extract_edges(img, blur, ksize, scale))
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ opencv-python==4.5.5.64