0
votes

I want to reduce the dimension of image from (480,640,3) to (1,512) by PCA in sklearn. So I reshape the image to (1, 921600). After then, I perform pca to reduce the dimension. But it changes to (1,1) instead of (1,512)

>>> img.shape
(1, 921600)
>>> pca = PCA(n_components=512)
>>> pca.fit_transform(img).shape
(1, 1)

Could anyone tell me how to reduce the dimension of a single image? Thanks

1
reduce the dimension of a single image This does not make sense by itself. You need to specify and think about how to reduce the dimensionality; what shall be the criterion to go from high to low dimensional space? (Or if that question is too much to swallow, what are you trying to achieve?) - MB-F

1 Answers

2
votes

That's expected. Wiki says (bold annotation by me):

PCA is a statistical procedure that uses an orthogonal transformation to convert a set of observations of possibly correlated variables into a set of values of linearly uncorrelated variables called principal components (or sometimes, principal modes of variation)

Fitting PCA on shape (1, 921600) means, that it's one sample with 921600 features.

sklearn's docs::

n_components == min(n_samples, n_features)