### C++ OpenCV cv::sqrt()

sqrt()

Description:

It is a special case of OpenCV pow() function,it computes element wise square root of an array.
There is also such thing as a square root of a matrix, that is, a matrix B whose relationship with some matrix A is that B*B = A. If A is square and positive definite, then if B exists, it is unique. If A can be diagonalized, then there is a matrix V (made from the eigen vectors of A as columns) such that A = VDV%u20131, where D is a diagonal matrix. The square root of a diagonal matrix D is just the square roots of the elements of D. So to compute A ½, we simply use the matrix V and get:

A^(1/2)=V*D^(1/2)*V^(-1)

Example:

void matrix_square_root( const cv::Mat& A, cv::Mat& sqrtA )
{
cv::Mat U, V, Vi, E;
cv::eigen( A, E, U );
V = U.T();
cv::transpose( V, Vi ); // inverse of the orthogonal V
cv::sqrt(E, E);         //We have to assume that A is positively defined,
// otherwise its square root will be complex-valued
sqrtA = V * Mat::diag(E) * Vi; //element wise square root of an array.
}