This code is an accelerated open-source software for 2D optical flow estimation and mechanical strain. The code is based on D. Sun 1 method with some improvements.
- LO09
Y. Li and S. Osher. A new median formula with applications to pde based denoising. Commun. Math, 7:741–753, 2009.
- SRB10
D. Sun, S. Roth, and M. J. Black. Secrets of optical flow estimation and their principles. IEEE computer society conference on computer vision and pattern recognition., 17:2432–2439, 2010.
Requirements
There are two versions of the software: a CPU and a GPU version. To use the code, you will need Python 3 (3.6 or higher) with the following modules:
A. For the CPU version:
Numpy 1.20.3 or newer
Scikit-image 0.16.2 or newer
Scipy 1.6.3 or newer
OpenCV 4.2.0 or newer
B. For the GPU version:
For the GPU version you first need an NVIDIA CUDA GPU with the Compute Capability 3.0 or larger. Beside the previous packages some additional ones will be needed to run the code on GPU
Method
A. Energy:
Energy to minimize:
Where:
\(\textcolor{black}{\text{Term in braces is the same as classical methods}}\)
\(\textcolor{blue}{\text{Encourages $(\hat{u}, \hat{v})$ and $(u,v)$ to be the same}}\)
\(\textcolor{OliveGreen}{\text{Smoothes $\hat{u}, \hat{v}$}}\)
Parameter |
Definition |
|---|---|
\(\hat{u}\) |
The auxiliary horizontal flow fields |
\(\hat{v}\) |
The auxiliary vertical flow fields |
\(N_{ij}\) |
The neighbouring pixels of the pixel (i,j) |
\(\lambda _2 \text{ and }\lambda _3\) |
Scalar weights |
\(\rho_D \text{ and }\rho_D\) |
Penalties |
B. Minimization
The previous objective will be optimized by alternately minimizing:
And
\(E_O\) will be minimized first during the alterning optimization with \(\hat{u},\hat{v}\) fixed. Then with fixed \(u,v\) we minimize \(E_M\)
\(E_M\) will be optimized by applying Li and Osher’s median filter or approximately optimized by applying a simple median filter.
C. Summary of the method
Build a pyramid of the images.
Using the following derivation kernel: \(h=\frac{1}{12}[-1, 8, 0 ,-8 ,1]\)
Cancelling the derivatives at pixels where the movement is out of the edges
Compute the steps \(du,dv\) by solving a linear system using Preconditionned Minres.
Update \(u\) and \(v\)
Compute \(\hat{u},\hat{v}\) by Li and Osher or a simple median filter at each iteration