Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scipy.misc import imread
- from scipy.linalg import svd
- import matplotlib.pyplot as plt
- import numpy as np
- if __name__ == '__main__':
- img = imread('mm.jpg')
- h, w, c = img.shape
- U0, S0, V0 = svd(img[:, :, 0])
- U1, S1, V1 = svd(img[:, :, 1])
- U2, S2, V2 = svd(img[:, :, 2])
- S0 = np.diag(S0)
- S1 = np.diag(S1)
- S2 = np.diag(S2)
- c0 = (U0[:, :20] @ S0[:20, :20] @ V0[:20, :]).reshape(h, w, 1)
- c1 = (U1[:, :20] @ S1[:20, :20] @ V1[:20, :]).reshape(h, w, 1)
- c2 = (U2[:, :20] @ S2[:20, :20] @ V2[:20, :]).reshape(h, w, 1)
- new_img = np.concatenate((c0, c1, c2), axis=2)
- plt.imshow(np.uint8(new_img))
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement