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

Commit e2fa0ea

Browse files
authored
Merge pull request #220 from sharur7/ssr
Added Cartoonify Image Code
2 parents 63d4bfb + e4e3fe6 commit e2fa0ea

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Importing Libraries
2+
import cv2
3+
import numpy as np
4+
from skimage import io
5+
6+
# Class Defination
7+
class Cartoon:
8+
def __init__(self):
9+
img = io.imread("images/sunset.jpg")
10+
# 1) Edges Image
11+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
12+
gray = cv2.medianBlur(gray, 5)
13+
edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 9, 7)
14+
15+
# 2) Color Image
16+
color = cv2.bilateralFilter(img, 10, 300, 300)
17+
RGB_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
18+
19+
# 3) Cartoon Image
20+
cartoon = cv2.bitwise_and(color, color, mask=edges)
21+
cartoon_img = cv2.cvtColor(cartoon, cv2.COLOR_BGR2RGB)
22+
23+
# Re-sizeing Image
24+
resize = cv2.resize(RGB_img, (600, 450))
25+
resize2 = cv2.resize(cartoon_img, (600, 450))
26+
self.resize = resize
27+
self.resize2 = resize2
28+
29+
# Displaying Image
30+
# Creating an object of class Cartoon
31+
c1 = Cartoon()
32+
c1.resize
33+
c1.resize2
34+
cv2.imshow("Original_Image", c1.resize)
35+
cv2.imshow("Cartoonified_Image", c1.resize2)
36+
cv2.waitKey(0)
37+
cv2.destroyAllWindows()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h1>Cartoonify Image</h1>
2+
3+
The code converts your original image i.e. the image which you have given as input, to cartoonified image.<br>
4+
When you run Cartoonify.py, both the input image and output image will be displayed.<br>
5+
It can be further implemented for pencil-sketch, color-pencil-sketch, water-color image, sepia effect, oldifying, etc.
6+
7+
<h2>Results:</h2>
8+
9+
<h4>Original Image</h4>
10+
<p align="left">
11+
<img src="images/Original%20Image.PNG" width="600" height="500"/></p>
12+
13+
<h4>Cartoonified Image</h4>
14+
<p align="left">
15+
<img src="images/Cartoonified%20Image.PNG" width="600" height="500"/></p>
Loading
Loading
Loading

0 commit comments

Comments
 (0)