forked from Data-Science-Community-SRM/Cartoonify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1 - Bilateral Filter.py
75 lines (42 loc) · 1.05 KB
/
1 - Bilateral Filter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# coding: utf-8
# In[1]:
# importing libraries
import cv2
import numpy as np
import matplotlib.pyplot as plt
# In[2]:
img_path = r'C:\Users\ANUSHKA GARG\Desktop\Bilateral filter\images\img1.jpg'
img = cv2.imread(img_path)
cv2.imshow("image", img)
cv2.waitKey(0)
plt.imshow(img)
# In[3]:
# Grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("image", gray)
cv2.waitKey(0)
plt.imshow(gray, cmap="Greys_r")
# In[4]:
gray = cv2.medianBlur(gray, 3)
cv2.imshow("image", gray)
cv2.waitKey(0)
plt.imshow(gray, cmap = "BuPu_r")
# In[5]:
edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 9)
cv2.imshow("image", edges)
cv2.waitKey(0)
plt.imshow(edges, cmap="CMRmap")
# In[11]:
# bilateral filter
color = cv2.bilateralFilter(img, 5, 50, 5)
#color = cv2.bilateralFilter(img, 23, 51, 51)
cv2.imshow("image", color)
cv2.waitKey(0)
plt.imshow(color)
# In[7]:
cartoon = cv2.bitwise_and(color, color, mask = edges)
cv2.imshow("image", cartoon)
cv2.waitKey(0)
plt.imshow(cartoon)
# In[ ]: