Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. from scipy.misc import imread
  2. from scipy.linalg import svd
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5.  
  6.  
  7. if __name__ == '__main__':
  8. img = imread('mm.jpg')
  9. h, w, c = img.shape
  10.  
  11. U0, S0, V0 = svd(img[:, :, 0])
  12. U1, S1, V1 = svd(img[:, :, 1])
  13. U2, S2, V2 = svd(img[:, :, 2])
  14. S0 = np.diag(S0)
  15. S1 = np.diag(S1)
  16. S2 = np.diag(S2)
  17.  
  18. c0 = (U0[:, :20] @ S0[:20, :20] @ V0[:20, :]).reshape(h, w, 1)
  19. c1 = (U1[:, :20] @ S1[:20, :20] @ V1[:20, :]).reshape(h, w, 1)
  20. c2 = (U2[:, :20] @ S2[:20, :20] @ V2[:20, :]).reshape(h, w, 1)
  21. new_img = np.concatenate((c0, c1, c2), axis=2)
  22.  
  23. plt.imshow(np.uint8(new_img))
  24. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement