常见的卷积核

常见的卷积核

常见的卷积核

低通滤波器

$$
\left [
\begin{matrix}
1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1
\end{matrix}
\right ] * \frac{1}{9}
\tag{1}
$$

$$
\left [
\begin{matrix}
1 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 1
\end{matrix}
\right ] * \frac{1}{10}
\tag{2}
$$

$$
\left [
\begin{matrix}
1 & 2 & 1 \\ 2 & 4 & 2 \\ 1 & 2 & 1
\end{matrix}
\right ] * \frac{1}{16}
\tag{3}
$$

卷积核-(1)对应效果
卷积核-(2)对应效果
卷积核-(3)对应效果

高通滤波器

$$
\left [
\begin{matrix}
0 & -1 & 0 \\ -1 & 5 & -1 \\ 0 & -1 & 0
\end{matrix}
\right ]
\tag{4}
$$

$$
\left [
\begin{matrix}
-1 & -1 & -1 \\ -1 & 9 & -1 \\ -1 & -1 & -1
\end{matrix}
\right ]
\tag{5}
$$

$$
\left [
\begin{matrix}
1 & -2 & 1 \\ -2 & 5 & -2 \\ 1 & -2 & 1
\end{matrix}
\right ]
\tag{6}
$$

卷积核-(4)对应效果
卷积核-(5)对应效果
卷积核-(6)对应效果

平移和查分边缘检测

$$
\left [
\begin{matrix}
0 & 0 & 0 \\ -1 & 1 & 0 \\ 0 & 0 & 0
\end{matrix}
\right ]
\tag{7}
$$

$$
\left [
\begin{matrix}
0 & -1 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 0
\end{matrix}
\right ]
\tag{8}
$$

$$
\left [
\begin{matrix}
-1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 0
\end{matrix}
\right ]
\tag{9}
$$

卷积核-(7)对应效果
卷积核-(8)对应效果
卷积核-(9)对应效果

匹配滤波边缘检测

$$
\left [
\begin{matrix}
-1 & -1 & -1 & -1 & -1 \\ 0 & 0 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 & 1
\end{matrix}
\right ]
\tag{10}
$$

$$
\left [
\begin{matrix}
-1 & 0 & 1 \\ -1 & 0 & 1 \\ -1 & 0 & 1 \\ -1 & 0 & 1 \\ -1 & 0 & 1
\end{matrix}
\right ]
\tag{11}
$$

卷积核-(10)对应效果
卷积核-(11)对应效果

边缘检测

$$
\left [
\begin{matrix}
-1 & 0 & -1 \\ 0 & 4 & 0 \\ -1 & 0 & -1
\end{matrix}
\right ]
\tag{12}
$$

$$
\left [
\begin{matrix}
-1 & -1 & -1 \\ -1 & 8 & -1 \\ -1 & -1 & -1
\end{matrix}
\right ]
\tag{13}
$$

$$
\left [
\begin{matrix}
-1 & -1 & -1 \\ -1 & 9 & -1 \\ -1 & -1 & -1
\end{matrix}
\right ]
\tag{14}
$$

$$
\left [
\begin{matrix}
1 & -2 & 1 \\ -2 & 1 & -2 \\ 1 & -2 & 1
\end{matrix}
\right ]
\tag{15}
$$

卷积核-(12)对应效果
卷积核-(13)对应效果
卷积核-(14)对应效果
卷积核-(15)对应效果

梯度方向边缘检测

$$
\left [
\begin{matrix}
1 & 1 & 1 \\ 1 & -2 & 1 \\ -1 & -1 & -1
\end{matrix}
\right ]
\tag{16}
$$

$$
\left [
\begin{matrix}
1 & 1 & 1 \\ -1 & -2 & 1 \\ -1 & -1 & 1
\end{matrix}
\right ]
\tag{17}
$$

$$
\left [
\begin{matrix}
-1 & 1 & 1 \\ -1 & -2 & 1 \\ -1 & 1 & 1
\end{matrix}
\right ]
\tag{18}
$$

$$
\left [
\begin{matrix}
-1 & -1 & 1 \\ -1 & -2 & 1 \\ 1 & 1 & 1
\end{matrix}
\right ]
\tag{19}
$$

$$
\left [
\begin{matrix}
-1 & -1 & -1 \\ 1 & -2 & 1 \\ 1 & 1 & 1
\end{matrix}
\right ]
\tag{20}
$$

$$
\left [
\begin{matrix}
1 & -1 & -1 \\ 1 & -2 & -1 \\ 1 & 1 & 1
\end{matrix}
\right ]
\tag{21}
$$

$$
\left [
\begin{matrix}
1 & 1 & -1 \\ 1 & -2 & -1 \\ 1 & 1 & -1
\end{matrix}
\right ]
\tag{22}
$$

$$
\left [
\begin{matrix}
1 & 1 & 1 \\ 1 & -2 & -1 \\ 1 & -1 & -1
\end{matrix}
\right ]
\tag{23}
$$

卷积核-(16)对应效果
卷积核-(17)对应效果
卷积核-(18)对应效果
卷积核-(19)对应效果
卷积核-(20)对应效果
卷积核-(21)对应效果
卷积核-(22)对应效果
卷积核-(23)对应效果

上图使用的代码

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import numpy as np
from scipy import signal
from scipy import misc
import matplotlib.pyplot as plt

face = misc.face(gray=True)
scharrs = [
# 低通滤波器
np.array([[1, 1, 1],
[1, 1, 1],
[1, 1, 1]]) * (1 / 9),
np.array([[1, 1, 1],
[1, 2, 1],
[1, 1, 1]]) * 0.1,
np.array([[1, 2, 1],
[2, 4, 2],
[1, 2, 1]]) * (1 / 16),
# 高通滤波器
np.array([[0, -1, 0],
[-1, 5, -1],
[0, -1, 0]]),
np.array([[-1, -1, -1],
[-1, 9, -1],
[-1, -1, -1]]),
np.array([[1, -2, 1],
[-2, 5, -2],
[1, -2, 1]]),
# 平移和查分边缘检测
np.array([[0, 0, 0],
[-1, 1, 0],
[0, 0, 0]]),

np.array([[0, -1, 0],
[0, 1, 0],
[0, 0, 0]]),
np.array([[-1, 0, 0],
[0, 1, 0],
[0, 0, 0]]),
# 匹配滤波边缘检测
np.array([[-1, -1, -1, -1, -1],
[0, 0, 0, 0, 0],
[-1, -1, -1, -1, -1]]),
np.array([[-1, 0, -1],
[-1, 0, -1],
[-1, 0, -1],
[-1, 0, -1],
[-1, 0, -1]]),
# 边缘检测
np.array([[-1, 0, -1],
[0, 4, 0],
[-1, 0, -1]]),
np.array([[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]]),
np.array([[-1, -1, -1],
[-1, 9, -1],
[-1, -1, -1]]),
np.array([[1, -2, 1],
[-2, 1, -2],
[1, -2, 1]]),
# 梯度方向边缘检测
np.array([[1, 1, 1],
[1, -2, 1],
[-1, -1, -1]]),
np.array([[1, 1, 1],
[-1, -2, 1],
[-1, -1, 1]]),
np.array([[-1, 1, 1],
[-1, -2, 1],
[-1, 1, 1]]),
np.array([[-1, -1, 1],
[-1, -2, 1],
[1, 1, 1]]),
np.array([[-1, -1, -1],
[1, -2, 1],
[1, 1, 1]]),
np.array([[1, -1, -1],
[1, -2, -1],
[1, 1, 1]]),
np.array([[1, 1, -1],
[1, -2, -1],
[1, 1, -1]]),
np.array([[1, 1, 1],
[1, -2, -1],
[1, -1, -1]])
]
count = 1
for scharr in scharrs:
grad = signal.convolve2d(face, scharr, boundary='symm', mode='same')
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 6))
ax1.imshow(face, cmap='gray')

ax1.set_axis_off()
ax2.imshow(np.absolute(grad), cmap='gray')

ax2.set_axis_off()
fig.show()
Author

BorGor

Posted on

2019-09-26

Updated on

2022-01-08

Licensed under

Comments