N步相移算法的推导
相机采集的N步相移图案可以表示为
\begin{equation} \begin{split} I_n &=a+b \cos(\varphi+\Delta\varphi_n)\\ &=a+b\cos\varphi\cos\Delta\varphi_n-b\sin\varphi\sin\Delta\varphi_n \end{split} \end{equation}
将记作,将记作,那么
\begin{equation} I_n=a+c\cos\Delta\varphi_n-s\sin\Delta\varphi_n \end{equation}
我们需要从N个公式(2)中求取未知量和,很自然地采用最小二乘法求解,最优化以下偏差:
\begin{equation} \varepsilon=\sum_{n=1}^N \big(I_n-(a+c\cos\Delta\varphi_n-s\sin\Delta\varphi_n)\big)^2 \end{equation}
由偏导可得
\begin{equation} \sum_{n=1}^{N}I_n=aN+c\sum_{n=1}^{N}\cos\Delta\varphi_n-s\sum_{n=1}^{N}\sin\Delta\varphi_n \end{equation}
由偏导可得
\begin{equation} \sum_{n=1}^{N}I_n\cos\Delta\varphi_n=a\sum_{n=1}^{N}\cos\Delta\varphi_n+c\sum_{n=1}^{N}\cos^2\Delta\varphi_n-s\sum_{n=1}^{N}\sin\Delta\varphi_n\cos\Delta\varphi_n \end{equation}
由偏导可得
\begin{equation} \sum_{n=1}^{N}I_n\sin\Delta\varphi_n=a\sum_{n=1}^{N}\sin\Delta\varphi_n+c\sum_{n=1}^{N}\sin\Delta\varphi_n\cos\Delta\varphi_n-s\sum_{n=1}^{N}\sin^2\Delta\varphi_n \end{equation}
综合公式(4),公式(5)和公式(6),整理成矩阵形式,为
\begin{equation} \begin{pmatrix}N&\sum_{n=1}^{N}\cos\Delta\varphi_n&-\sum_{n=1}^{N}\sin\Delta\varphi_n & \\\sum_{n=1}^{N}\cos\Delta\varphi_n & \sum_{n=1}^{N}\cos^2\Delta\varphi_n & -\sum_{n=1}^{N}\sin\Delta\varphi_n\cos\Delta\varphi_n \\ \sum_{n=1}^{N}\sin\Delta\varphi_n & \sum_{n=1}^{N}\sin\Delta\varphi_n\cos\Delta\varphi_n & -\sum_{n=1}^{N}\sin^2\Delta\varphi_n \end{pmatrix}\begin{pmatrix}a\\c\\s\end{pmatrix}=\begin{pmatrix}\sum_{n=1}^{N}I_n\\\sum_{n=1}^{N}I_n\cos\Delta\varphi_n\\\sum_{n=1}^{N}I_n\sin\Delta\varphi_n\end{pmatrix} \end{equation}
由于, ,, , , 代入公式(7)中可得,
\begin{equation} \begin{pmatrix}N&0&0 \\0&\frac{N}{2}&0 \\ 0&0&-\frac{N}{2}\end{pmatrix}\begin{pmatrix}a \\ c \\ s \end{pmatrix}=\begin{pmatrix}\sum_{n=1}^{N}I_n\\\sum_{n=1}^{N}I_n\cos\Delta\varphi_n\\\sum_{n=1}^{N}I_n\sin\Delta\varphi_n\end{pmatrix} \end{equation}
此时,易得
\begin{equation} \begin{split} a&=\frac1N\sum_{n=1}^{N}I_n\\ c&=\frac2N\sum_{n=1}^{N}I_n\cos\Delta\varphi_n\\ s&=-\frac2N\sum_{n=1}^{N}I_n\sin\Delta\varphi_n \end{split} \end{equation}
由于, ,可得
\begin{equation} \begin{split} \tan\varphi&=-\frac{\sum_{n=1}^{N}I_n\sin\Delta\varphi_n}{\sum_{n=1}^{N}I_n\cos\Delta\varphi_n}\\ b&=\frac2N\sqrt{(\sum_{n=1}^{N}I_n\sin\Delta\varphi_n)^2+(\sum_{n=1}^{N}I_n\cos\Delta\varphi_n)^2} \end{split} \end{equation}
推导完毕。