Coders Packet

Converting Images into Cartoon using Numpy and OpenCV in Python

By Richa Singh

Have fun by converting your images into a cartoon using Numpy and OpenCV libraries of Python Programming

Numpy is a highly optimized library in Python programming for numerical computation. It provides data structures used to deploy OpenCV with Python. So in this project, I used both to convert an image into a cartoon which involves several concepts of Computer vision.

Concepts involved :

1) Detecting and emphasizing edges 

2) Image Filtering

3) Creating a cartoon effect

4) Color quantization


1) To install Numpy : pip install numpy

2) To install OpenCV : pip install opencv-python

Steps required for implementation:

1) import Numpy and OpenCV libraries.

2)  Read the image from the given path.

3) Convert the image from BGR(Bue-Green-Red) to grayscale.

4) Apply the median blur filter to reduce noise from the image.

5) Detect and enhance edges by creating edge mask using adaptive thresholding.

6) Now, apply bilateral filtering for edge smoothing.

7) Combine the coloured input image with the edge mask image by doing bitwise AND operation.

8) Finally the cartoonified image is ready which is shown below :

Cartoonified Image

Download Complete Code


No comments yet