In this video, I will show you how to convert an image to a pencil sketch using the Python programming language in just 5 lines of code! Python is a general-purpose programming language that was created in the late 1980s and has seen significant growth in popularity from big tech companies and communities over the years.
📌One of the reasons for its popularity growth is its ease of use and simplicity. Just think that we are about to transform an image in just 5 lines of code !!
Actually, it could be less.
Before writing any code let’s walk through some of the steps that will be used and try to understand them a bit.
📌Step 1: Find an image that we want to convert into a pencil sketch. I am going to use the image of a Jerry.
📌Step 2: Read in the Red, Blue, Green (RBG) image and then convert it to a grayscale image. This effectively makes the image a classic “black and white” photo. This will be our “greyscale image”.
📌Step 3: We are going to invert the “grey scaled image” also known as getting the image negative, this will be our “inverted greyscale image”. Inversion can be used to enhance details.
📌Step 4: Use a Gaussian function to blur the image. In image processing, a Gaussian blur (also known as Gaussian smoothing) is the result of blurring an image by a Gaussian function.
📌Step 5: Invert the newly created “blurred image”, this will be called the “inverted blurred image”.
📌Step 6: Now we are going to create the pencil sketch image by blending the “greyscale image” with the “inverted blurred image”. This can be done by dividing the “grayscale image” by the “inverted blurred image”. Since images are just arrays we can easily do this in programming by using the divide function from the cv2 library.
Source Code & Link:
Subscribe : https://www.youtube.com/channel/UCNs6a3HlrbYw7dSUEXk9W3A
#python