Advertisement
Guest User

PCA script

a guest
Feb 20th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. from sklearn.decomposition import PCA
  2. from skimage import io
  3. from PIL import Image
  4. import sys
  5.  
  6. im = io.imread(sys.argv[1])
  7. s = im.shape
  8. n = 2
  9. pca = PCA(n_components = n)
  10. im_c = im.reshape((-1,3))
  11. print(im_c.shape)
  12. pca.fit(im_c)
  13. im_pca = pca.fit_transform(im_c)
  14. print(im_pca.shape)
  15. im_restored = pca.inverse_transform(im_pca).reshape(s)
  16. io.imsave("out.jpg", im_restored)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement