why dose the maxComponent argument in function cv.PCACompute doesn't work???

asked 2016-09-03 03:37:29 -0600

littletom gravatar image

updated 2016-09-03 03:42:11 -0600

berak gravatar image
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()
edit retag flag offensive close merge delete

Comments

1
  • what is the problem, exactly ?
  • please do anyone a favour, and do not alias cv2 to cv. there was an older, incompatible module with that name, and you're confusing anyone looking at your code.
berak gravatar imageberak ( 2016-09-03 03:46:02 -0600 )edit

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.

littletom gravatar imagelittletom ( 2016-09-03 03:51:19 -0600 )edit

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 ?)

berak gravatar imageberak ( 2016-09-04 00:54:45 -0600 )edit

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.

littletom gravatar imagelittletom ( 2016-09-04 02:30:34 -0600 )edit