Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from PIL import Image
- billede = Image.open("Advent.bmp")
- graybillede = billede.convert("LA")
- billedearray = np.array(list(graybillede.getdata(band=0)),float)
- billedearray.shape = (graybillede.size[1], graybillede.size[0])
- print ("billedearray = \n", billedearray,"\n")
- billedematrix = np.matrix(billedearray)
- print ("billedematrix = \n", billedematrix,"\n")
- U, sigma, V = np.linalg.svd(billedematrix)
- print ("V =\n", np.round(V,decimals=2))
- kompri = np.matrix(U[:, :1]*np.diag(sigma[:1])*np.matrix(V[:1, :]))
- plt.imshow(kompri, cmap="gray")
- plt.title("efter svd v = 1")
- fig = plt.figure()
- for i in range (10, 50+1, 10):
- komprirange = np.matrix(U[:, :i]*np.diag(sigma[:i])*np.matrix(V[:i, :]))
- plt.imshow(komprirange, cmap="gray")
- plt.title("billede v =" + str(i))
- plt.figure()
- for i in range (1,100+1,1):
- plt.plot(250000/(1001*i),i, color="green",marker=".")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement