ZCA implementation in java
Hello everyone,
I'm trying to implement ZCA Whitening algorithm like shown here: http://stackoverflow.com/questions/31... with opencv in Scala (using Java api) but I cannot find the most of the functions used there (phython with numpy).
So far I tried with this:
//Covariance matrix
val covar, mean = new Mat()
Core.calcCovarMatrix(input, covar, mean, Core.COVAR_NORMAL | Core.COVAR_ROWS)
Core.divide(covar, new Scalar(input.rows - 1), covar)
//Singular Value Decomposition
val w, u, vt = new Mat()
Core.SVDecomp(covar, w, u, vt)
//#Whitening constant, it prevents division by zero
val epsilon = 1e-5
To implement the last trasformation
ZCAMatrix = np.dot(U, np.dot(np.diag(1.0/np.sqrt(S + epsilon)), U.T))
I tried with:
var ZCAMatrix = new Mat
Core.add(w, new Scalar(epsilon), ZCAMatrix)
Core.sqrt(ZCAMatrix, ZCAMatrix)
Core.divide(1.0, ZCAMatrix, ZCAMatrix)
Core.gemm(Mat.diag(ZCAMatrix), u.t, 1, new Mat, 0, ZCAMatrix)
Core.gemm(ZCAMatrix, u, 1, new Mat, 0, ZCAMatrix)
The result of thei transformation is:
which is not exactly what it's supposed to be. Can someone help?