Skip to content

Commit 9afb75d

Browse files
Create Image to sketch converter.py
1 parent 48acb67 commit 9afb75d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Image to sketch converter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import cv2 #importing cv2 to read image
2+
image = cv2.imread("img.jpg") #write image name to be uploaded.
3+
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) #this line converts image into grayscale format
4+
inverted_image = 255 - gray_image
5+
blurred = cv2.GaussianBlur(inverted_image, (21, 21), 0)
6+
inverted_blurred = 255 - blurred
7+
pencil_sketch = cv2.divide(gray_image, inverted_blurred, scale=256.0)
8+
cv2.imshow("Original Image", image)
9+
cv2.imshow("Pencil Sketch of image", pencil_sketch)
10+
cv2.waitKey(0) # this is used to stop the image.exe file to wait for sometime and then close the file.

0 commit comments

Comments
 (0)