高斯核卷积高斯核
之前看sift源码中有个概念,就是对一张图像 I 0 I_0 I0,先进行标准差为 σ 1 \sigma_1 σ1的高斯核卷积,得到 I 1 I_1 I1,再基于 I 1 I_1 I1进行标准差为 σ 2 \sigma_2 σ2的高斯核卷积得到图像 I 2 I_2 I2,和 I 0 I_0 I0直接进行一次标准差为 σ \sigma σ的高斯核的卷积得到 I 2 I_2 I2之间的关系。写成表达式就是 I 0 ∗ g 1 ∗ g 2 I_0*g1*g2 I0∗g1∗g2是否等于 I 0 ∗ ( g 1 ∗ g 2 ) I_0*(g1*g2) I0∗(g1∗g2),如果成立 g = g 1 ∗ g 2 g=g1*g2 g=g1∗g2是个什么东东。结论是等号成立的,并且 g g g也是一个标准差为 σ \sigma σ的高斯分布的概率密度函数,且 σ 2 = σ 1 2 + σ 2 2 \sigma^2=\sigma_1^2 + \sigma_2^2 σ2=σ12+σ22。结合律留给有兴趣的读者,下面证明方差之间的关系。
证明
设
g
1
,
g
2
g_1,g_2
g1,g2是两个1维正态分布的概率密度函数:
g
1
(
x
)
=
1
2
π
σ
1
e
−
(
x
−
μ
1
)
2
2
σ
1
2
g_1(x)=\frac{1}{\sqrt{2\pi}\sigma_1}{e}^{-\frac{(x-\mu_1)^2}{2\sigma_1^2}}
g1(x)=2πσ11e−2σ12(x−μ1)2
g
2
(
x
)
=
1
2
π
σ
2
e
−
(
x
−
μ
2
)
2
2
σ
2
2
g_2(x)=\frac{1}{\sqrt{2\pi}\sigma_2}e^{-\frac{(x-\mu_2)^2}{2\sigma_2^2}}
g2(x)=2πσ21e−2σ22(x−μ2)2
在无穷区间上的积分,被积函数的自变量发生平移并不影响积分结果,为了简化计算,不妨设
μ
1
=
μ
2
=
0
\mu_1=\mu_2=0
μ1=μ2=0.
从而,
f
(
t
)
=
g
1
(
x
)
∗
g
2
(
x
)
f(t)=g_1(x)*g_2(x)
f(t)=g1(x)∗g2(x)
=
∫
−
∞
∞
g
1
(
x
)
g
2
(
t
−
x
)
d
x
=\displaystyle\int_{-\infty}^{\infty}g_1(x)g_2(t-x)dx
=∫−∞∞g1(x)g2(t−x)dx
=
1
2
π
σ
1
σ
2
∫
−
∞
∞
e
−
x
2
2
σ
1
2
−
−
(
t
−
x
)
2
2
σ
2
2
d
x
=\displaystyle{\frac{1}{2\pi \sigma_1\sigma_2}\int_{-\infty}^{\infty}e^{\frac{-x^2}{2\sigma_1^2}-\frac{-(t-x)^2}{2\sigma_2^2}}}dx
=2πσ1σ21∫−∞∞e2σ12−x2−2σ22−(t−x)2dx
下面对积分部分进行计算
∫
−
∞
∞
e
−
x
2
2
σ
1
2
−
−
(
t
−
x
)
2
2
σ
2
2
d
x
\displaystyle\int_{-\infty}^{\infty}e^{\frac{-x^2}{2\sigma_1^2}-\frac{-(t-x)^2}{2\sigma_2^2}}dx
∫−∞∞e2σ12−x2−2σ22−(t−x)2dx
=
∫
−
∞
∞
e
−
x
2
σ
2
2
−
σ
1
2
(
t
−
x
)
2
2
σ
1
2
σ
2
2
d
x
=\displaystyle\int_{-\infty}^{\infty}e^{\frac{-x^2\sigma_2^2-\sigma_1^2(t-x)^2}{2\sigma_1^2\sigma_2^2}}dx
=∫−∞∞e2σ12σ22−x2σ22−σ12(t−x)2dx
= ∫ − ∞ ∞ e x 2 σ 2 2 + σ 1 2 t 2 + σ 1 2 x 2 − 2 σ 1 2 t x − 2 σ 1 2 σ 2 2 d x =\displaystyle\int_{-\infty}^{\infty}e^{\frac{x^2\sigma_2^2+\sigma_1^2t^2+\sigma_1^2x^2-2\sigma_1^2tx}{-2\sigma_1^2\sigma_2^2}}dx =∫−∞∞e−2σ12σ22x2σ22+σ12t2+σ12x2−2σ12txdx
= ∫ − ∞ ∞ e ( σ 1 2 + σ 2 2 ) ( x − σ 1 2 t σ 1 2 + σ 2 2 ) 2 − σ 1 4 t 2 ( σ 1 2 + σ 2 2 ) 2 ⋅ ( σ 1 2 + σ 2 2 ) + σ 1 2 t 2 − 2 σ 1 2 σ 2 2 d x =\displaystyle\int_{-\infty}^{\infty}e^{\frac{(\sigma_1^2+\sigma_2^2)(x-\frac{\sigma_1^2t}{\sigma_1^2+\sigma_2^2})^2-\frac{\sigma_1^4t^2}{(\sigma_1^2+\sigma_2^2)^2}\cdot(\sigma_1^2+\sigma_2^2)+\sigma_1^2t^2}{-2\sigma_1^2\sigma_2^2}}dx =∫−∞∞e−2σ12σ22(σ12+σ22)(x−σ12+σ22σ12t)2−(σ12+σ22)2σ14t2⋅(σ12+σ22)+σ12t2dx
= ∫ − ∞ ∞ e ( σ 1 2 + σ 2 2 ) ( x − σ 1 2 t σ 1 2 + σ 2 2 ) 2 + σ 1 2 σ 2 2 t 2 σ 1 2 + σ 2 2 − 2 σ 1 2 σ 2 2 d x =\displaystyle\int_{-\infty}^{\infty}e^{\frac{(\sigma_1^2+\sigma_2^2)(x-\frac{\sigma_1^2t}{\sigma_1^2+\sigma_2^2})^2+\frac{\sigma_1^2\sigma_2^2t^2}{\sigma_1^2+\sigma_2^2}}{-2\sigma_1^2\sigma_2^2}}dx =∫−∞∞e−2σ12σ22(σ12+σ22)(x−σ12+σ22σ12t)2+σ12+σ22σ12σ22t2dx
= ∫ − ∞ ∞ e ( σ 1 2 + σ 2 2 ) ( x − σ 1 2 t σ 1 2 + σ 2 2 ) 2 − 2 σ 1 2 σ 2 2 − t 2 σ 1 2 + σ 2 2 d x =\displaystyle\int_{-\infty}^{\infty}e^{\frac{(\sigma_1^2+\sigma_2^2)(x-\frac{\sigma_1^2t}{\sigma_1^2+\sigma_2^2})^2}{-2\sigma_1^2\sigma_2^2}-\frac{t^2}{\sigma_1^2+\sigma_2^2}}dx =∫−∞∞e−2σ12σ22(σ12+σ22)(x−σ12+σ22σ12t)2−σ12+σ22t2dx
= e − t 2 σ 1 2 + σ 2 2 ∫ − ∞ ∞ e ( σ 1 2 + σ 2 2 ) ( x − σ 1 2 t σ 1 2 + σ 2 2 ) 2 − 2 σ 1 2 σ 2 2 d x =e^{\frac{-t^2}{\sigma_1^2+\sigma_2^2}}\displaystyle\int_{-\infty}^{\infty}e^{\frac{(\sigma_1^2+\sigma_2^2)(x-\frac{\sigma_1^2t}{\sigma_1^2+\sigma_2^2})^2}{-2\sigma_1^2\sigma_2^2}}dx =eσ12+σ22−t2∫−∞∞e−2σ12σ22(σ12+σ22)(x−σ12+σ22σ12t)2dx
前面说过,无穷积分上被积函数的自变量平移操作不影响积分值(可以用换元法证明,令
y
=
x
−
σ
1
2
t
σ
1
2
+
σ
2
2
y=x-\frac{\sigma_1^2t}{\sigma_1^2+\sigma_2^2}
y=x−σ12+σ22σ12t,
d
x
=
d
y
dx=dy
dx=dy,换元必换限,这里上下限依旧是正负无穷,不变)
上式
=
e
−
t
2
σ
1
2
+
σ
2
2
∫
−
∞
∞
e
(
σ
1
2
+
σ
2
2
)
x
2
−
2
σ
1
2
σ
2
2
d
x
=e^{\frac{-t^2}{\sigma_1^2+\sigma_2^2}}\displaystyle\int_{-\infty}^{\infty}e^{\frac{(\sigma_1^2+\sigma_2^2)x^2}{-2\sigma_1^2\sigma_2^2}}dx
=eσ12+σ22−t2∫−∞∞e−2σ12σ22(σ12+σ22)x2dx
= e − t 2 σ 1 2 + σ 2 2 ∫ − ∞ ∞ e − ( σ 1 2 + σ 2 2 2 σ 1 σ 2 x ) 2 d x =e^{\frac{-t^2}{\sigma_1^2+\sigma_2^2}}\displaystyle\int_{-\infty}^{\infty}e^{-(\frac{\sqrt{\sigma_1^2+\sigma_2^2}}{\sqrt{2}\sigma_1\sigma_2}x)^2}dx =eσ12+σ22−t2∫−∞∞e−(2σ1σ2σ12+σ22x)2dx
令
y
=
σ
1
2
+
σ
2
2
2
σ
1
σ
2
x
y=\frac{\sqrt{\sigma_1^2+\sigma_2^2}}{\sqrt{2}\sigma_1\sigma_2}x
y=2σ1σ2σ12+σ22x,则
d
x
=
2
σ
1
σ
2
σ
1
2
+
σ
2
2
d
y
dx=\frac{\sqrt{2}\sigma_1\sigma_2}{\sqrt{\sigma_1^2+\sigma_2^2}}dy
dx=σ12+σ222σ1σ2dy,换元必换限,上下限依旧是正负无穷不变,从而有
原式
=
e
−
t
2
σ
1
2
+
σ
2
2
∫
−
∞
∞
e
−
y
2
⋅
2
σ
1
σ
2
σ
1
2
+
σ
2
2
d
y
=e^{\frac{-t^2}{\sigma_1^2+\sigma_2^2}}\displaystyle\int_{-\infty}^{\infty}e^{-y^2}\cdot\frac{\sqrt2\sigma_1\sigma_2}{\sqrt{\sigma_1^2+\sigma_2^2}}dy
=eσ12+σ22−t2∫−∞∞e−y2⋅σ12+σ222σ1σ2dy
= e − t 2 σ 1 2 + σ 2 2 2 σ 1 σ 2 σ 1 2 + σ 2 2 ∫ − ∞ ∞ e − y 2 d y =e^{\frac{-t^2}{\sigma_1^2+\sigma_2^2}}\frac{\sqrt2\sigma_1\sigma_2}{\sqrt{\sigma_1^2+\sigma_2^2}}\displaystyle\int_{-\infty}^{\infty}e^{-y^2}dy =eσ12+σ22−t2σ12+σ222σ1σ2∫−∞∞e−y2dy
= e − t 2 σ 1 2 + σ 2 2 2 σ 1 σ 2 σ 1 2 + σ 2 2 π =e^{\frac{-t^2}{\sigma_1^2+\sigma_2^2}}\frac{\sqrt2\sigma_1\sigma_2}{\sqrt{\sigma_1^2+\sigma_2^2}}\sqrt\pi =eσ12+σ22−t2σ12+σ222σ1σ2π
其中 ∫ − ∞ ∞ e − y 2 d y = π \int_{-\infty}^{\infty}e^{-y^2}dy=\sqrt\pi ∫−∞∞e−y2dy=π,一般的高数书上都有,不等式放缩证明收敛性;平方后取极坐标,再两边夹取极限得到收敛的值。
最后得到
f
(
t
)
=
1
2
π
σ
1
σ
2
⋅
e
−
t
2
σ
1
2
+
σ
2
2
⋅
2
σ
1
σ
2
σ
1
2
+
σ
2
2
⋅
π
f(t)=\frac{1}{2\pi\sigma_1\sigma_2}\cdot e^{\frac{-t^2}{\sigma_1^2+\sigma_2^2}}\cdot\frac{\sqrt2\sigma_1\sigma_2}{\sqrt{\sigma_1^2+\sigma_2^2}}\cdot\sqrt\pi
f(t)=2πσ1σ21⋅eσ12+σ22−t2⋅σ12+σ222σ1σ2⋅π
=
1
2
π
σ
1
2
+
σ
2
2
e
−
t
2
σ
1
2
+
σ
2
2
=\frac{1}{\sqrt{2\pi}\sqrt{\sigma_1^2+\sigma_2^2}}e^{\frac{-t^2}{\sigma_1^2+\sigma_2^2}}
=2πσ12+σ221eσ12+σ22−t2
=
1
2
π
σ
e
−
t
2
σ
2
=\frac{1}{\sqrt{2\pi}\sigma}e^{\frac{-t^2}{\sigma^2}}
=2πσ1eσ2−t2
即
f
(
t
)
f(t)
f(t)是标准差为
σ
\sigma
σ的高斯分布的概率密度函数,其中
σ
2
=
σ
1
2
+
σ
2
2
\sigma^2=\sigma_1^2+\sigma_2^2
σ2=σ12+σ22,证毕。
从理论上说,一张图先后经过 σ 1 , σ 2 \sigma_1,\sigma_2 σ1,σ2的高斯模糊和直接经过 σ \sigma σ的模糊后的状态是一样的,但是实际操作中,由于高斯核模板大小并不是无穷的,而是取了有限个元,所以其中的误差累计,具体会是什么结果也难以预料,只能多做做实验进行对比了。而在sift尺度空间的构造中,因为 σ \sigma σ比 σ 2 \sigma_2 σ2大,所以对应的高斯模板也会大一点,运算量就大了。也就是在 I 0 , I 1 I_0,I_1 I0,I1已知的情况下,由 I 1 I_1 I1得到 I 2 I_2 I2比由 I 0 I_0 I0得到 I 2 I_2 I2的实际运算量会小点。