-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.py
46 lines (35 loc) · 1.01 KB
/
kernel.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
#python 3
import cv2
import numpy as np
import matplotlib.pyplot as plt
def plot(data, title):
plot.i += 1
plt.subplot(1,2,plot.i)
plt.imshow(cv2.cvtColor(data, cv2.COLOR_BGR2RGB))
plt.gray()
plt.title(title)
plot.i = 0
image_path = "C://Users//anhpn//Desktop//MEMS//code2//img//frame177.jpg"
image = cv2.imread(image_path)
# cv2.imshow("raw image", image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
plot(image, 'Original Image')
# #invert image
# cv2.imshow("invert image", 255-image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
#creat a 5x5 kernel low pass filter
kernel = np.ones(5, dtype=np.float32)/25
dst = cv2.filter2D(image, -1, kernel)
# cv2.imshow("image passes though LPF", dst)
# cv2.waitKey(0)
# plot(dst, "Low Pass Filter")
#creat a 3x3 kernel high pass filter
kernel2 = np.array([[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]])
dst = cv2.filter2D(image, -1, kernel2)
plot(dst, "High Pass Filter")
#
plt.show()