Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Added Cartoonify Image Code #220

Merged
merged 8 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Image-Processing/Cartoonify Image/Cartoonify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Importing Libraries
import cv2
import numpy as np
from skimage import io

# Class Defination
class Cartoon:
def __init__(self):
img = io.imread("images/sunset.jpg")
# 1) Edges Image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.medianBlur(gray, 5)
edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 9, 7)

# 2) Color Image
color = cv2.bilateralFilter(img, 10, 300, 300)
RGB_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

# 3) Cartoon Image
cartoon = cv2.bitwise_and(color, color, mask=edges)
sharur7 marked this conversation as resolved.
Show resolved Hide resolved
cartoon_img = cv2.cvtColor(cartoon, cv2.COLOR_BGR2RGB)

# Re-sizeing Image
resize = cv2.resize(RGB_img, (600, 450))
resize2 = cv2.resize(cartoon_img, (600, 450))
self.resize = resize
self.resize2 = resize2

# Displaying Image
# Creating an object of class Cartoon
c1 = Cartoon()
c1.resize
c1.resize2
cv2.imshow("Original_Image", c1.resize)
cv2.imshow("Cartoonified_Image", c1.resize2)
cv2.waitKey(0)
cv2.destroyAllWindows()
15 changes: 15 additions & 0 deletions Image-Processing/Cartoonify Image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h1>Cartoonify Image</h1>

The code converts your original image i.e. the image which you have given as input, to cartoonified image.<br>
When you run Cartoonify.py, both the input image and output image will be displayed.<br>
It can be further implemented for pencil-sketch, color-pencil-sketch, water-color image, sepia effect, oldifying, etc.

<h2>Results:</h2>

<h4>Original Image</h4>
<p align="left">
<img src="images/Original%20Image.PNG" width="600" height="500"/></p>

<h4>Cartoonified Image</h4>
<p align="left">
<img src="images/Cartoonified%20Image.PNG" width="600" height="500"/></p>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.