Pencil Photo Sketching



In the present time, we are encircled by various sorts of photograph controlling channels in our cell phones, applications… and so on In any case, do you know how they do these pictures controls… ..? In the backend, they are utilizing PC vision strategies. PC vision has a wide assortment of uses not exclusively to lessen the human exertion yet in addition utilized for diversion applications. Numerous photograph-altering applications like FaceApp, Instagram channels… and so on are utilizing PC vision procedures. 

In this article, we will attempt to change over an ordinary photograph into a pencil sketch utilizing PC vision in a python programming language. In this article, we will tell the best way to change over a picture into its relating pencil sketch in a couple of steps..





Step-1: Importing required libraries

import cv2
Step-2: Loading the image

Using the below code snippet, we will read the image that is to be processed.

img = cv2.imread('/content/pic.jpeg', 

Step-3: Converting an image into gray_scale image

Using the below code snippet, we will convert the input image into equivalent grey-scale using cv2.cvtColor.

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

Converting an image into grayscale gives us black & white pixels in the image which is used for creating a pencil sketch.
Step-4: Inverting the image

Using the below code snippet, we will invert the image color using cv2.bitwise

img_invert = cv2.bitwise_not(img_gray)


We are utilizing the bitwise_not work which is utilized to make more splendid districts lighter and the other way around so we can discover the edges to make a pencil sketch. 

Step-5: Smoothing the image

In the below code snippet, we will smooth the image using Gaussian Blur.

img_smoothing = cv2.GaussianBlur(img_invert, (21, 21),sigmaX=0, sigmaY=0)


We have utilized the gaussian haze strategy with 21 x 21 pixel and the default sigma esteems channel on the picture to smoothen our picture. By expanding the channel size, we can make slim lines for our sketch and it is utilized to lessen the commotion in the picture.


Step-6: Obtaining the final sketch

Using the below code snippet, we will obtain the final pencil sketch of the input image using a blend function dodgev2.

def dodgeV2(x, y):

return cv2.divide(x, 255 - y, scale=256)

By utilizing this capacity, it is partitioning the greyscale worth of the picture by the converse of obscured picture esteem which features the boldest edges. This procedure is utilized by conventional picture takers to print photographs from the reel.
Final Output as Pencil Sketch

final_img = dodgeV2(img_gray, img_smoothing)




Conclusion
In this article, we exhibited how to change over our picture into a pencil sketch utilizing PC vision methods in a couple of lines of code. There are various applications in PC vision of getting the sketch of a picture.


Download code : Github

Comments

Popular posts from this blog

Hand Gesture based Simple Jump unity game

Lane Detection

Gender Age Facial prediction