Image To Pencil Sketch

 Image To Pencil Sketch

In today’s era, we are surrounded by different types of photo manipulating filters in our mobile phones, apps…etc. But do you know how they do these images manipulations…..? In the backend, they are using computer vision techniques. Computer vision has a wide variety of applications not only to reduce the human effort but also used for entertainment apps. Many photo editing apps like FaceApp, Instagram filters…etc are using computer vision techniques. 

In this article, we will try to convert a normal photo into a pencil sketch using computer vision in a python programming language. In this article, we will show how to convert an image into its corresponding pencil sketch in a few steps.

Code

import cv2

img_location = 'C:/Users/malle/OneDrive/Desktop/'

filename = 'mallesh.jpg'


img = cv2.imread(img_location+filename)


gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)


inverted_gray_image = 255 - gray_image


blurred_img = cv2.GaussianBlur(inverted_gray_image, (21,21), 0)


inverted_blurred_img = 255 - blurred_img


pencil_sketch_IMG = cv2.divide(gray_image, inverted_blurred_img, scale=256.0)


cv2.imshow('original Image',img)

cv2.imshow('New Image',pencil_sketch_IMG)

cv2.waitKey(0)


Output:




No comments

Powered by Blogger.