svd_metric.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # module file which contains all image metrics used in project
  2. from numpy.linalg import svd
  3. from PIL import Image
  4. import matplotlib.pyplot as plt
  5. from scipy import misc
  6. import time
  7. import numpy as np
  8. from sklearn import preprocessing
  9. import modules.model_helper.image_conversion as img_c
  10. '''
  11. Method which extracts SVD features from image and returns 's' vector
  12. @return 's' vector
  13. '''
  14. def get_s_model_data(image):
  15. U, s, V = svd(image, full_matrices=False)
  16. size = len(s)
  17. # normalized output
  18. output_normalized = preprocessing.normalize(s, norm='l1', axis=0, copy=True, return_norm=False)
  19. result = output_normalized.reshape([size, 1, 3])
  20. return result
  21. def get_s_model_data_img(image):
  22. fig_size = plt.rcParams["figure.figsize"]
  23. fig_size[0] = 1
  24. fig_size[1] = 1
  25. plt.rcParams["figure.figsize"] = fig_size
  26. U, s, V = svd(image, full_matrices=False)
  27. plt.figure() # create a new figure
  28. output_normalized = preprocessing.normalize(s, norm='l1', axis=0, copy=True, return_norm=False)
  29. plt.plot(output_normalized[70:100, 0])
  30. plt.plot(output_normalized[70:100:, 1])
  31. plt.plot(output_normalized[70:100:, 2])
  32. img = img_c.fig2img(plt.gcf())
  33. plt.close('all')
  34. return img
  35. def get(image):
  36. return svd(image, full_matrices=False)
  37. def get_s(image):
  38. U, s, V = svd(image, full_matrices=False)
  39. return s
  40. def get_U(image):
  41. U, s, V = svd(image, full_matrices=False)
  42. return U
  43. def get_V(image):
  44. U, s, V = svd(image, full_matrices=False)
  45. return V