I am trying to understand how to use PCA to decorate an RGB image in python. I use the code found in the O'Reilly Computer review book:
from PIL import Image
from numpy import *
def pca(X):
num_data,dim = X.shape
mean_X = X.mean(axis=0)
for i in range(num_data):
X[i] -= mean_X
if dim>100:
print 'PCA - compact trick used'
M = dot(X,X.T)
e,EV = linalg.eigh(M)
tmp = dot(X.T,EV).T
V = tmp[::-1]
S = sqrt(e)[::-1]
else:
print 'PCA - SVD used'
U,S,V = linalg.svd(X)
V = V[:num_data]
return V,S,mean_X
I know that I need to smooth the image, but the shape is 512x512x3. Will size 3 reset my result? How to crop it? How to find a quantitative amount of information about saving information?
source
share