Making a beautiful sketch requires a lot of time and effort.

Luckily, programming has evolved so you’re able to now easily transform images and create beautiful designs.

Learn how to program such an app using the OpenCV module in the super-friendly Python language.

Blank Sketch Book with Pencil

Then start building your program using the following steps.

This example code is available in aGitHub repositoryand is free for you to use under the MIT License.

The first step is to import the OpenCV module into your environment.

Image to Sketch House with Lake

Pass the path of your image file into theimread()function to load it.

Store your image in a variablecalledimage1herefor future reference.

Store the title of the window in a variable namedwindow_name.

Image to Sketch Man

This will be useful when you choose to display the image using theimshow()function.

This function requires two parameters: the title and the image you want to display.

once you nail the desired image, you oughta perform five operations to transform it into a sketch.

First, convert the color image into grayscale.

you might do so with thecvtColor()function.

This function takes in the image whose colors you want to alter and a conversion code such asCOLOR_BGR2GRAY.

when you obtain a grayscale image, invert its colors.

At this point, you’re gonna wanna understand how a computer forms an image.

An image consists of many tiny pixels with varying intensities.

To invert the pixel intensities of this image, pass the grayscale image to thebitwise_not()function.

As the name suggests, this function inverts the value of each pixel to its complementary equivalent.

The Gaussian Blur process makes use of a Gaussian filter.

OpenCV’sGaussianBlur()function accepts four parameters.

Suppose you have a physical photograph in your hand.

If you wanted to blur it, you could apply pieces of wax or parchment paper over it.

you could imagine the kernel as this transparent bit of paper.

Digitally, this happens a bit differently.

The ksize is always a positive odd number.

As you increase the kernel size, the blur increases.

To understand sigmaX assume you are applying wax on a paper.

As you apply wax, the paper becomes uniformly translucent.

Similarly, you must keep the kernel’s values close to a specific point (the average).

The sigmaX value defines the difference between the average and other values of the pixels in an image.

Essentially the function performs the following operation:

Store the result in a variable named sketch.

Bring all the code together, and you have your program ready.

On a portrait image, the program generates the following digital sketch.

Image Processing and Computer Vision

Image processing and computer vision are two closely related fields of technology.

They both involve altering digital images to get desired outcomes.

Scikit-image is another Python library that provides a wide variety of image-processing functions.

It has several precompiled modules, filters, layers, transformations, and more.