Image_to_Sketcho / src /streamlit_app.py
handecarkci's picture
Update src/streamlit_app.py
5334694 verified
raw
history blame contribute delete
782 Bytes
import streamlit as st
import cv2
import numpy as np
from PIL import Image
st.title('Image to Sketch')
file = st.file_uploader('Upload an portrait image', type=['jpg', 'png', 'jpeg'])
if file:
img = Image.open(file).convert('RGB')
img_np = np.array(img)
img_bw = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
gray = cv2.cvtColor(img_bw, cv2.COLOR_RGB2GRAY)
inverted = 255 - gray
blurred = cv2.GaussianBlur(inverted, (21, 21), 0)
def dodge(front, back):
return cv2.divide(front, 255 - back, scale=255)
sketch = dodge(gray, blurred)
st.subheader('Original vs Sketch')
col1, col2 = st.columns(2)
with col1:
st.image(img, caption='Original', use_column_width=True)
with col2:
st.image(sketch, caption='Sketch')