hackkobaz commited on
Commit
4fb2a74
·
verified ·
1 Parent(s): cf4f93e

Upload app5.py

Browse files

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')
img2=np.array(img)
img_bw=cv2.cvtColor(img2,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('Orginal vs Sketch')
col1,col2=st.columns(2)
with col1:
st.image(img, caption='Original',use_container_width=True)
with col2:
st.image(sketch, caption='Sketch',use_container_width=True)

Files changed (1) hide show
  1. app5.py +26 -0
app5.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ st.title('Image to Sketch')
7
+ file=st.file_uploader('Upload an portrait image', type=['jpg','png','jpeg'])
8
+ if file:
9
+ img=Image.open(file).convert('RGB')
10
+ img2=np.array(img)
11
+ img_bw=cv2.cvtColor(img2,cv2.COLOR_RGB2BGR)
12
+ gray=cv2.cvtColor(img_bw,cv2.COLOR_RGB2GRAY)
13
+ inverted=255-gray
14
+ blurred=cv2.GaussianBlur(inverted,(21,21),0)
15
+
16
+ def dodge(front,back):
17
+ return cv2.divide(front, 255-back, scale=255)
18
+
19
+ sketch=dodge(gray,blurred)
20
+
21
+ st.subheader('Orginal vs Sketch')
22
+ col1,col2=st.columns(2)
23
+ with col1:
24
+ st.image(img, caption='Original',use_container_width=True)
25
+ with col2:
26
+ st.image(sketch, caption='Sketch',use_container_width=True)