0

I was creating convolution neural network dataset using images. To reduce the correlation between pixels, the data must be zero mean and variance 1. So for images, the whitening transformation does that. I was doing ZCA whitening. The code was working but the output I obtained was wrong. I am attaching my code here. Please tell me why it is so... Thanks in advance...

import numpy as np
import cv2
import matplotlib.pyplot as plt
def whiten(X,fudge=1E-18):
        Xcov = np.cov(X)
        d,V = np.linalg.eigh(Xcov)
        D = np.diag(1. / np.sqrt(d+.1))
        W = np.dot(np.dot(V, D), np.transpose(V))
        X_white = np.dot(W,X)
        return X_white, W, np.var(X_white)

x=cv2.imread('ar.jpg')
x=cv2.resize(x,(400,400))
img = cv2.cvtColor(x, cv2.COLOR_RGB2GRAY)
plt.imshow(img,cmap='Greys_r')
plt.show()
new,W,var=whiten(img)
plt.imshow(new,cmap='Greys_r')
plt.show()

The input and output is: Image

Output Image

  • Where is your zca implementation coming from? I may be thick, but I can't quite grok what you're trying to do with each of these steps. – Slater Victoroff Apr 14 '16 at 14:34
  • 5
    sir, I got the concept from this link :: http://stats.stackexchange.com/questions/117427/what-is-the-difference-between-zca-whitening-and-pca-whitening I needed an output as show in the output answered by bayerg. I need an image with variance 1 after performing the whitening operation. This link also helped me , http://stackoverflow.com/questions/31528800/how-to-implement-zca-whitening-python – arjun subramannian Apr 14 '16 at 15:20
  • I am creating my own dataset . each image is of size 32x32. so in the tutorial it is said that we should whiten the data before making the dataset. That is what I tried to do. taking each image and applying whitening operation. As an initial stage, I did whitening on an image and when I printed the result , the output was not right. Also the variance of whitened image is not 1 – arjun subramannian Apr 14 '16 at 15:25
  • Can you show us what the whitening matrix looks like? My gut says there may be some kind of transposition error there and it would be very helpful for debugging. That's W specifically. In general, you should keep in mind that a dot product is not commutative, so order matters. – Slater Victoroff Apr 14 '16 at 16:10
  • when I gave this ([[1,2,3],[3,4,6],[2,3,5]]) matrix , then the whitening matrix was[[ 2.3696113 -0.63146589 -0.63146589] [-0.63146589 1.99415284 -1.16812482] [-0.63146589 -1.16812482 1.99415284]] – arjun subramannian Apr 15 '16 at 05:06

0 Answers0