Some detailed records about the calculation of the optical flow hession matrix

Some records of optical flow's hession matrix

The above intuitive explanation:

The eigenvalue of the Hessian matrix: it describes the unevenness of the eigenvector direction near the point. The larger the eigenvalue, the stronger the convexity.

For the hessian matrix of a certain point in a two-dimensional image, its maximum eigenvalue and its corresponding eigenvector correspond to the intensity and direction of the maximum curvature of the two-dimensional curve of its neighborhood, that is, the side with a steep slope; the eigenvector corresponding to the smallest eigenvalue corresponds to The direction perpendicular to it is the gentle direction.

In simple terms, the size and sign of the eigenvalues ​​of the Hessian matrix of a certain point in the image determine the geometric structure in the neighborhood of the point

The same is true for three-dimensional images. Some filters designed by this principle (the most classic is the Frangi filter) have very important applications in MRA and CTA angiography enhancement in the medical field.

Based on the Hessian matrix, the extreme value of the multivariate function can be judged. The conclusion is as follows

If it is a positive definite matrix, the critical point is a local minimum.
If it is a negative definite matrix, the critical point is a local maximum.
If it is an indefinite matrix, the critical point is not an extreme value.

The judgment method for the positive definite and negative definite of the real quadratic matrix: The necessary and sufficient condition for the real quadratic matrix to be positive definite quadratic is that the eigenvalues ​​of the matrix are all greater than zero . The necessary and sufficient condition for the negative definite quadratic form is that the eigenvalues ​​of the matrix are all less than zero , otherwise it is indefinite.

1. The sum of the eigenvalues ​​of the matrix is ​​equal to the determinant of the matrix

2. The product of the eigenvalues ​​of the matrix is ​​equal to the trace of the matrix

The method of calculating the minimum eigenvalue uses the above things. The formula min_lambda + max_lambda = dttermiant; min_lambda * max_lambda = trace; it is easy to find min_lambda by the quadratic equation solving formula: min_lambda = trace / 2-sqrt((trace * trace) / 4-determinant);


    float trace = hession(0, 0) + hession(1, 1);
    float determinant = hession(0, 0) * hession(1, 1) - hession(0, 1) * hession(1, 0);
    float min_lambda= trace / 2 - sqrt((trace * trace) / 4 -  determinant);
    result(0, 0) = determinant;
    result(1, 0) = min_lambda;


The specific code location used in the optical flow:

hession计算特征值部分:

inline void CacluHessen(const MatrixXf &dx, const MatrixXf &dy, int x, int y,
                        MatrixXf &result, MatrixXf &hession) {

    MatrixXf dx_square = MatrixXf::Zero(WinSize, WinSize);
    MatrixXf dxy_square = MatrixXf::Zero(WinSize, WinSize);
    MatrixXf dy_square = MatrixXf::Zero(WinSize, WinSize);

    dx_square = dx.block(y - halfSize, x - halfSize, WinSize, WinSize).array() *
                dx.block(y - halfSize, x - halfSize, WinSize, WinSize).array();
    dy_square = dy.block(y - halfSize, x - halfSize, WinSize, WinSize).array() *
                dy.block(y - halfSize, x - halfSize, WinSize, WinSize).array();
    dxy_square = dx.block(y - halfSize, x - halfSize, WinSize, WinSize).array() *
                 dy.block(y - halfSize, x - halfSize, WinSize, WinSize).array();

    hession(0, 0) = dx_square.sum();
    hession(1, 1) = dy_square.sum();
    hession(0, 1) = dxy_square.sum();
    hession(1, 0) = dxy_square.sum();

    float trace = hession(0, 0) + hession(1, 1);
    float determinant = hession(0, 0) * hession(1, 1) - hession(0, 1) * hession(1, 0);
    float min_lambda= trace / 2 - sqrt((trace * trace) / 4 -  determinant);
    result(0, 0) = determinant;
    result(1, 0) = min_lambda;
}


应用部分:

if(result(1, 0) < LK_minEigThreshold || result(0, 0) < FLT_EPSILON)
{
    if(0 == level)
    {
       status(i, 0) = 0;
    }
    continue;
}


 

Guess you like

Origin blog.csdn.net/gbz3300255/article/details/113102903