Blanchiment ZCA avec opencv et java


J'essaie d'implémenter l'algorithme de blanchiment ZCA comme montré ici: Comment implémenter le blanchiment ZCA? Python avec opencv dans Scala (en utilisant l'api Java) mais je ne trouve pas la plupart des fonctions utilisées (phython avec numpy).

Jusqu'à présent j'ai essayé avec ceci:

Chargement de l'image sous forme de Mat:

val input = Imgcodecs.imread(img)
Imgproc.cvtColor(input, input, Imgproc.COLOR_BGR2GRAY)
input.convertTo(input, CvType.CV_64FC1)

, Puis appliquer l'algorithme:

//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, Core.SVD_FULL_UV)

//#Whitening constant, it prevents division by zero
val  epsilon = 1e-5

Pour implémenter la dernière trasformation

ZCAMatrix = np.dot(U, np.dot(np.diag(1.0/np.sqrt(S + epsilon)), U.T))

J'ai essayé avec:

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(u, ZCAMatrix, 1, new Mat, 0, ZCAMatrix)

Puis appliquer la trasformation à la image originale:

val output = new Mat
Core.gemm(ZCAMatrix, input, 1, new Mat, 0, output)

Le résultat de leur transformation est: ce

, Qui n'est pas exactement ce qu'il est censé être. Quelqu'un peut-il aider?

Author: Community, 2016-09-06