Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from PIL import Image
  4.  
  5. billede = Image.open("Advent.bmp")
  6. graybillede = billede.convert("LA")
  7.  
  8. billedearray = np.array(list(graybillede.getdata(band=0)),float)
  9. billedearray.shape = (graybillede.size[1], graybillede.size[0])
  10. print ("billedearray = \n", billedearray,"\n")
  11. billedematrix = np.matrix(billedearray)
  12. print ("billedematrix = \n", billedematrix,"\n")
  13.  
  14. U, sigma, V = np.linalg.svd(billedematrix)
  15. print ("V =\n", np.round(V,decimals=2))
  16.  
  17. kompri = np.matrix(U[:, :1]*np.diag(sigma[:1])*np.matrix(V[:1, :]))
  18. plt.imshow(kompri, cmap="gray")
  19. plt.title("efter svd v = 1")
  20.  
  21. fig = plt.figure()
  22.  
  23. for i in range (10, 50+1, 10):
  24.     komprirange = np.matrix(U[:, :i]*np.diag(sigma[:i])*np.matrix(V[:i, :]))
  25.     plt.imshow(komprirange, cmap="gray")
  26.     plt.title("billede v =" + str(i))
  27.     plt.figure()                
  28.  
  29. for i in range (1,100+1,1):
  30.     plt.plot(250000/(1001*i),i, color="green",marker=".")
  31.  
  32. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement