import cv2 as cv
import numpy as np
img=cv.imread(r'T/s.jpg',cv.IMREAD_GRAYSCALE)
img=cv.resize(img,(512,512))
tdata=img.flatten()
tdata=tdata.reshape(512*512,1)
tdata=tdata-tdata.mean()
tdata=tdata/np.sqrt(tdata.var())
mean=np.array([])
mean,eigenvectors=cv.PCACompute(tdata,mean,cv.PCA_DATA_AS_COL,
maxComponents=9)
projectedVectors=cv.PCAProject(tdata,mean,eigenvectors)
result=cv.PCABackProject(tdata,mean,eigenvectors)
result=result.reshape(512,512)
cv.imshow('show',img)
cv.waitKey()
cv.imshow('show',result)
cv.waitKey()
cv.destroyAllWindows()
well,the output image doesn't change even if I've made an ajustment on the argument maxComponents. I'm sorry about that confusing anyone,and I am totally a greenhand in this filed.
what are you trying to achieve with it ?
(there's nothing really wrong in the code, but maybe just making a pca of a single image, and doing a forward/backward projection just does not make much sense ?)
I'd like to visualize a image using different amount of eigenvectors,that is, I need to know what it looks like if the image have more or less features.