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

Commit b32d45b

Browse files
committed
Cartoonifying_Image
1 parent a1dd103 commit b32d45b

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Importing Libraries
2+
import cv2
3+
import numpy as np
4+
from skimage import io
5+
6+
7+
# Class Defination
8+
class Cartoon:
9+
def __init__(self):
10+
img = io.imread("images/sunset.jpg")
11+
# 1) Edges Image
12+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
13+
gray = cv2.medianBlur(gray, 5)
14+
edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 9, 7)
15+
16+
# 2) Color Image
17+
color = cv2.bilateralFilter(img, 10, 300, 300)
18+
RGB_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
19+
20+
# 3) Cartoon Image
21+
cartoon = cv2.bitwise_and(color, color, mask=edges)
22+
cartoon_img = cv2.cvtColor(cartoon, cv2.COLOR_BGR2RGB)
23+
24+
# Re-sizeing Image
25+
resize = cv2.resize(RGB_img, (600, 450))
26+
resize2 = cv2.resize(cartoon_img, (600, 450))
27+
self.resize = resize
28+
self.resize2 = resize2
29+
30+
31+
# Displaying Image
32+
# Creating an object of class Cartoon
33+
c1 = Cartoon()
34+
c1.resize
35+
c1.resize2
36+
cv2.imshow("Original_Image", c1.resize)
37+
cv2.imshow("Cartoonified_Image", c1.resize2)
38+
cv2.waitKey(0)
39+
cv2.destroyAllWindows()
Loading
Loading
Loading

0 commit comments

Comments
 (0)