Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import gradio as gr
|
3 |
+
def convert_photo_to_Sketch(image):
|
4 |
+
img = cv2.resize(image, (256, 256))
|
5 |
+
#convert image to RGB from BGR
|
6 |
+
RGB_img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
|
7 |
+
#convert imge to grey
|
8 |
+
grey_img=cv2.cvtColor(RGB_img, cv2.COLOR_BGR2GRAY)
|
9 |
+
#invert grey scale image
|
10 |
+
invert_img=255-grey_img
|
11 |
+
#Gaussian fun to blur the image
|
12 |
+
blur_img=cv2.GaussianBlur(invert_img, (21,21),0)
|
13 |
+
#invert the blur image
|
14 |
+
inverted_blurred_img = 255 - blur_img
|
15 |
+
#skecth the image
|
16 |
+
sketch_img=cv2.divide(grey_img,inverted_blurred_img, scale=256.0)
|
17 |
+
rgb_sketch=cv2.cvtColor(sketch_img, cv2.COLOR_BGR2RGB)
|
18 |
+
#return the final sketched image
|
19 |
+
return rgb_sketch
|
20 |
+
|
21 |
+
#built interface with gradio to test the function
|
22 |
+
imagein = gr.inputs.Image(label='Orjinal Resim')
|
23 |
+
imageout = gr.outputs.Image(label='Sketch Resim',type='pil')
|
24 |
+
gr.Interface(fn=convert_photo_to_Sketch, inputs=imagein, outputs=imageout,title='Convert RGB Image to Sketch').launch()
|