清晰易懂版相關濾波推導

讀研期間做相關濾波視覺跟蹤,讀了很多相關濾波的論文,但是由於當年矩陣論和數字信號處理基礎太菜,一直沒搞明白相關濾波的閉合解是怎麼推出來的,各種論文裏面的推導都是直接給個結果,過程不詳。最近終於搞明白了推導的過程和原理,在這裏記錄一下。我覺得應該是全網最清晰最易懂的相關濾波推導了。

如果不加說明,以下粗體字x\mathbf{x}代表列向量,加帽x^\hat{\mathbf{x}}代表x\mathbf{x}的傅里葉變換

在推導之前首先回顧幾個定理:

循環卷積定理x\mathbf{x}的傅里葉變換爲x^\hat{\mathbf{x}}y\mathbf{y}的傅里葉變換爲y^\hat{\mathbf{y}},則x\mathbf{x}y\mathbf{y}的卷積xy\mathbf{x}\otimes\mathbf{y}的傅里葉變換爲x^\hat{\mathbf{x}}y^\hat{\mathbf{y}}的點積x^y^\hat{\mathbf{x}}\odot\hat{\mathbf{y}}

帕斯瓦爾定理
x2=1Nx^2 ||\mathbf{x}||^2=\frac{1}{N}||\hat{\mathbf{x}}||^2
NN爲信號長度。

還有一個小結論,信號的反序的傅里葉變換等於原信號傅里葉變換的共軛

證明一下,記y\mathbf{y}x\mathbf{x}的反序,即y[k]=x[Nk]\mathbf{y}[k]=\mathbf{x}[N-k]
y^[k]=n=0N1x[Nn]ej2πNn \hat{\mathbf{y}}[k]=\sum_{n=0}^{N-1}\mathbf{x}[N-n]e^{-j\frac{2\pi}{N}n}
Nn=tN-n=t
y^[k]=t=0N1x[t]ej2πN(Nt)=t=0N1x[t]ej2πNt=x^[k] \hat{\mathbf{y}}[k]=\sum_{t=0}^{N-1}\mathbf{x}[t]e^{-j\frac{2\pi}{N}(N-t)}\\ =\sum_{t=0}^{N-1}\mathbf{x}[t]e^{j\frac{2\pi}{N}t}=\hat{\mathbf{x}^{*}}[k]

在卷積操作中,信號要經過反褶操作,而信號的互相關沒有經過反褶操作,因此則x\mathbf{x}y\mathbf{y}的互相關xy\mathbf{x}*\mathbf{y}的傅里葉變換爲x^\hat{\mathbf{x}^{*}}y^\hat{\mathbf{y}}的點積x^y^\hat{\mathbf{x}^{*}}\odot\hat{\mathbf{y}}

有了這幾個定理,現在開始推導吧。

相關濾波是要學習一個與x\mathbf{x}維度相同的濾波器h\mathbf{h},使兩者的互相關hx\mathbf{h}*\mathbf{x}儘量接近目標函數y\mathbf{y},使下面的目標函數最小。
E(h)=hxy2+λh2 E(\mathbf{h})=||\mathbf{h}*\mathbf{x}-\mathbf{y}||^2+\lambda||\mathbf{h}||^2
根據帕斯瓦爾定理,最小化上式相當於最小化
E(h^)=h^x^y^2+λh^2 E(\hat{\mathbf{h}})=||\hat{\mathbf{h}}\odot\hat{\mathbf{x}}-\hat{\mathbf{y}}||^2+\lambda||\hat{\mathbf{h}}||^2
把點積寫成矩陣相乘的形式
E(h^)=diag(x^)h^y^2+λh^2 E(\hat{\mathbf{h}})=||diag(\hat{\mathbf{x}})\hat{\mathbf{h}}-\hat{\mathbf{y}}||^2+\lambda||\hat{\mathbf{h}}||^2
往下推還需要知道幾個結論
x2=xHx ||\mathbf{x}||^2=\mathbf{x}^H\mathbf{x}
H表示共軛轉置

下面這兩個結論參見《matrix cookbook》
xTAxx=A+AT \frac{\partial \mathbf{x^TAx}}{\partial \mathbf{x}}=\mathbf{A+A^T}


xTax=aTxx=a \frac{\partial \mathbf{x^T a}}{\partial \mathbf{x}}=\frac{\partial \mathbf{a^T x}}{\partial \mathbf{x}}=\mathbf{a}

接着往下推
E(h^)=(diag(x^)h^y^)H(diag(x^)h^y^)+λh^Hh^=h^Hdiag(x^)diag(x^)h^h^Hdiag(x^)y^y^Hdiag(x^)h^+y^Hy^+λh^Hh^ E(\hat{\mathbf{{h}}})=(diag(\hat{\mathbf{x}})\hat{\mathbf{h}}-\hat{\mathbf{y}})^H(diag(\hat{\mathbf{x}})\hat{\mathbf{h}}-\hat{\mathbf{y}})+\lambda \hat{\mathbf{h}}^H \hat{\mathbf{h}}\\ =\hat{\mathbf{h}}^Hdiag(\hat{\mathbf{x}^*})diag(\hat{\mathbf{x}})\hat{\mathbf{h}}-\hat{\mathbf{h}}^Hdiag(\hat{\mathbf{x}^*})\hat{\mathbf{y}}-\hat{\mathbf{y}}^Hdiag(\hat{\mathbf{x}})\hat{\mathbf{h}}+\hat{\mathbf{y}}^H\hat{\mathbf{y}}+\lambda \hat{\mathbf{h}}^H\hat{\mathbf{h}}
將目標函數對h^\hat{\mathbf{h}}求偏導(共軛轉置和轉置不太一樣,但是驗證一下也是成立的,不太嚴謹地求個導)
E(h^)h^=2diag(x^x^)h^2diag(x^)y^+2λh^ \frac{\partial E(\hat{\mathbf{h}})}{\partial \hat{\mathbf{h}}}=2diag(\hat{\mathbf{x}^{*}}\odot{\hat{\mathbf{x}}})\hat{\mathbf{h}}-2diag(\hat{\mathbf{x}^{*}})\hat{\mathbf{y}}+2\lambda \hat{\mathbf{h}}
E(h^)h^=0\frac{\partial E(\hat{\mathbf{h}})}{\partial \hat{\mathbf{h}}}=0,解得
h^=(diag(x^x^)+λI)1diag(x^)y^=x^y^x^x^+λ \hat{\mathbf{h}}=(diag(\hat{\mathbf{x}^{*}}\odot{\hat{\mathbf{x}}})+\lambda I)^{-1}diag(\hat{\mathbf{x}^{*}})\hat{\mathbf{y}}\\ =\frac{\hat{\mathbf{x}^{*}}\odot\hat{\mathbf{y}}}{\hat{\mathbf{x}^{*}}\odot{\hat{\mathbf{x}}}+\lambda}

這就是論文裏常見的那個公式的由來了。

多通道情況的推導參見fDSST論文的附錄,利用了每個像素之間的獨立性。

另外 Henriques的KCF論文[2]裏是利用循環矩陣傅里葉變換對角化的性質去推導的,很多博主的推導都指出原論文推導結果錯誤,推出的濾波器結果是
w^=x^y^x^x^+λ \hat{\mathbf{w}}=\frac{\hat{\mathbf{x}}\odot\hat{\mathbf{y}}}{\hat{\mathbf{x}^*}\odot\hat{\mathbf{x}}+\lambda}
分母上的x^\hat{\mathbf{x}}沒有共軛,而且從論文的附錄5的推導看,確實推不到式(57),後來看了一下作者的學位論文,推導這個公式的起點不是論文中帶有共軛轉置的(3)式,而是論文的(2)式。
w=(XTX+λI)1XTy \mathbf{w}=(X^TX+\lambda I)^{-1}X^Ty
也就是說樣本矩陣XX學習到的濾波器w\mathbf{w}在空域中都是實數。

回顧一下論文裏的樣本矩陣
X=C(x)=[x1x2x3xnxnx1x2xn1xn1xnx1xn2x2x3x4x1] X=C(\mathbf{x})=\left[\begin{array}{ccccc}{x_{1}} & {x_{2}} & {x_{3}} & {\cdots} & {x_{n}} \\ {x_{n}} & {x_{1}} & {x_{2}} & {\cdots} & {x_{n-1}} \\ {x_{n-1}} & {x_{n}} & {x_{1}} & {\cdots} & {x_{n-2}} \\ {\vdots} & {\vdots} & {\vdots} & {\ddots} & {\vdots} \\ {x_{2}} & {x_{3}} & {x_{4}} & {\cdots} & {x_{1}}\end{array}\right]
再使用這個性質
X=Fdiag(x^)FH X=F diag(\hat{\mathbf{x}})F^{H}
這個時候發現XTX^T的第一行正好是x\mathbf{x}的倒序,因此它的傅里葉變換爲x^\hat{\mathbf{x}^*}, 所以
XTX=Fdiag(x^)FHFdiag(x^)FH=Fdiag(x^x^)FH X^TX=Fdiag(\hat{\mathbf{x}^*})F^HFdiag(\hat{\mathbf{x}})F^H=Fdiag(\hat{\mathbf{x}^*}\odot\hat{\mathbf{x}})F^H
再代入上面的式子
w=(Fdiag(x^x^)FH+λFFH)1Fdiag(x^)FHy=Fdiag(1x^x^+λ)FHFdiag(x^)FHy=Fdiag(x^x^x^+λ)y^ \mathbf{w}=(Fdiag(\hat{\mathbf{x}^*}\odot\hat{\mathbf{x}})F^H+\lambda FF^H)^{-1}Fdiag(\hat{\mathbf{x}^*})F^H\mathbf{y}\\ =Fdiag(\frac{1}{\hat{\mathbf{x}^*}\odot\hat{\mathbf{x}}+\lambda})F^{H}Fdiag(\hat{\mathbf{x}^*})F^H\mathbf{y}\\ =Fdiag(\frac{\hat{\mathbf{x}}}{\hat{\mathbf{x}^*}\odot\hat{\mathbf{x}}+\lambda})\hat{\mathbf{y}^*}
兩邊乘FHF^H
w^=diag(x^x^x^+λ)y^ \hat{\mathbf{w}}^*=diag(\frac{\hat{\mathbf{x}}}{\hat{\mathbf{x}^*}\odot\hat{\mathbf{x}}+\lambda})\hat{\mathbf{y}^*}
兩邊取共軛
w^=x^y^x^x^+λ \hat{\mathbf{w}}=\frac{\hat{\mathbf{x}^{*}}\odot\hat{\mathbf{y}}}{\hat{\mathbf{x}^*}\odot\hat{\mathbf{x}}+\lambda}
結果相同,因此原論文結果正確,只是推導過程錯誤。

記錄一點自己的理解,希望可以幫到大家。

參考博文

KCF目標跟蹤方法分析與總結

KCF公式推導錯誤及驗證

MOSSE(DSST)類和KCF類中濾波器推導結果不一致的解釋

參考文獻

[1] Petersen K B, Pedersen M S The Matrix Cookbook book

[2] Danelljan M , Häger, Gustav, Khan F S , et al. Discriminative Scale Space Tracking[J]. IEEE Transactions on Pattern Analysis & Machine Intelligence, 2016, 39(8):1561-1575. paper

[3] Henriques J F, Rui C, Martins P, et al. High-Speed Tracking with Kernelized Correlation Filters[J]. IEEE Transactions on Pattern Analysis & Machine Intelligence, 2015, 37(3):583-596. paper

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章