File size: 1,187 Bytes
22812b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import cv2
import numpy as np

st.set_page_config(layout="wide")


def extract_edges(img, blur, ksize, sobel_scale):
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (blur, blur), 0)
    x = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=ksize, scale=scale)
    y = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=ksize, scale=scale)
    absx= cv2.convertScaleAbs(x)
    absy = cv2.convertScaleAbs(y)
    edge = cv2.addWeighted(absx, 0.5, absy, 0.5, 0)
    return cv2.bitwise_not(edge)


uploaded_file = st.file_uploader("Choose an image...", type=["jpeg", "jpg", "png"])
ksize = st.sidebar.slider("Kernel size", min_value=3, max_value=19, value=5, step=2)
scale = st.sidebar.slider("Scale", min_value=0.0, max_value=1.0, value=0.25, step=0.05)
blur = st.sidebar.slider("Gaussian blur", min_value=3, max_value=99, value=5, step=2)


if uploaded_file is not None:
    img = cv2.imdecode(np.asarray(bytearray(uploaded_file.read()), dtype="uint8"), flags=cv2.IMREAD_COLOR)

    col1, col2 = st.columns(2)
    with col1:
        st.image(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))

    with col2:
        st.image(extract_edges(img, blur, ksize, scale))