Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.decomposition import PCA
- from skimage import io
- from PIL import Image
- import sys
- im = io.imread(sys.argv[1])
- s = im.shape
- n = 2
- pca = PCA(n_components = n)
- im_c = im.reshape((-1,3))
- print(im_c.shape)
- pca.fit(im_c)
- im_pca = pca.fit_transform(im_c)
- print(im_pca.shape)
- im_restored = pca.inverse_transform(im_pca).reshape(s)
- io.imsave("out.jpg", im_restored)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement