0% found this document useful (0 votes)
49 views11 pages

Opencv: Cartoonifying Images: by Sri Sai Chandu Adabala

Ppt for ml
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views11 pages

Opencv: Cartoonifying Images: by Sri Sai Chandu Adabala

Ppt for ml
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

OpenCV:

Cartoonifying
Images
OpenCV is a powerful library for computer vision, enabling
tasks like image processing and object detection. This article
will guide you through building a Python application that
transforms images into cartoons using OpenCV.

by Sri Sai chandu Adabala


What is OpenCV?
OpenCV is a cross-platform library used for Computer Vision. It includes applications like video and image capturing and process

Image Transformation Object Detection Face Recognition


OpenCV is used for image OpenCV can be used to detect OpenCV can be used to recognize
transformation, such as resizing, objects in images, such as faces, faces in images, which has
rotating, and flipping images. cars, and pedestrians. applications in security and access
control.
Cartoonifier Application
This article will guide you through building a Python application that transforms images into cartoons using OpenCV.

Original Image Cartoonified Image


The original image is the input to the cartoonifier application.
The cartoonified image is the output of the cartoonifier
application.
Steps to Develop Image Cartoonifier
The process of cartoonifying an image involves several steps, including importing modules, building a file box, and performing image transformations.

1 Step 1: Importing Modules


Import necessary modules like OpenCV, easyGUI, NumPy, Imageio, Matplotlib, and OS.

2 Step 2: Building a File Box


Create a file box using easyGUI to allow users to select an image from their system.

3 Step 3: Image Storage


Read the selected image using OpenCV and store it as a NumPy array.

4 Step 4: Image Transformations


Perform image transformations, such as converting to grayscale, smoothing, and edge detection.

5 Step 5: Cartoon Effect


Combine the transformed images to create a cartoon effect using masking.

6 Step 6: Plotting and Saving


Plot the original and cartoonified images and save the cartoonified image.
Step 1: Importing Modules
Import the necessary modules for image processing and user interface.

1 OpenCV (cv2) 2 easyGUI


Used for image processing tasks. Used to create a file box for selecting images.

3 NumPy 4 ImageIO
Used for array manipulation. Used to read images from files.

5 Matplotlib 6 OS
Used for plotting images. Used for interacting with the operating system.
Step 2: Building a File Box
Create a file box using easyGUI to allow users to select an image from
their system.

Open File Box


Use the easyGUI module's fileopenbox() method to open a
file box.

Select Image
The user selects an image from their system.

Return Image Path


The fileopenbox() method returns the path of the selected
image as a string.
Step 3: Image Storage
Read the selected image using OpenCV and store it as a NumPy array.

OpenCV's imread() Method NumPy Array

Use the cv2.imread() method to read the image The imread() method returns the image as a
from the file path. NumPy array, where each cell represents a pixel's
RGB values.
Step 4: Image Transformations
Perform image transformations, such as converting to grayscale, smoothing, and edge detection.

Transformation Description

Grayscale Convert the image to grayscale using cv2.cvtColor() with the


BGR2GRAY flag.

Smoothing Smooth the grayscale image using cv2.blur() or


cv2.GaussianBlur() to reduce noise.

Edge Detection Detect edges in the image using cv2.Canny() to highlight outlines.
Step 5: Cartoon Effect
Combine the transformed images to create a cartoon effect
using masking.

Prepare a Mask Image


Create a mask image by applying a bilateral filter to the
smoothed grayscale image.

Apply the Mask


Perform a bitwise AND operation between the mask image and
the original image to create the cartoon effect.
Step 6: Plotting and Saving
Plot the original and cartoonified images and save the cartoonified image.

1 Plot Images 2 Save Cartoonified Image


Use Matplotlib to plot the original and Use OpenCV's imwrite() method to save the
cartoonified images side-by-side. cartoonified image to a file.

You might also like