-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pencil_Sketch.py
37 lines (27 loc) · 937 Bytes
/
Pencil_Sketch.py
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
35
36
37
# Description : Program to convert Image to Pencil Sketch
'''
Data Science Intern at Let's Grow More LGMVIP Sept 22
Beginner Level Task
Image to Pencil Sketch with Python
Anish Dhondi
'''
#Importing cv2 module
import cv2
#Getting the Image Location and Image
img_location = 'C:/Users/Anish Mithil/OneDrive/Desktop/'
filename = '1.jpg'
#Read the image
img = cv2.imread(img_location+filename)
#Convert the img to grayscale
gray_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#Invert the Img
inverted_gray_image = 255 - gray_img
#blur the img by gaussian function
blurred_img = cv2.GaussianBlur(inverted_gray_image,(21,21),0)
#Invert the Blurred Image
inverted_blurred_image = 255 - blurred_img
#Creating the Pencil sketch Image
pencil_sketch_IMG = cv2.divide(gray_img,inverted_blurred_image, scale=256.0 )
cv2.imshow('Original image',img)
cv2.imshow('New image',pencil_sketch_IMG)
cv2.waitKey(0)