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