svd_metric.py 885 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # module file which contains all image metrics used in project
  2. from numpy.linalg import svd
  3. from PIL import Image
  4. from scipy import misc
  5. import time
  6. import numpy as np
  7. from sklearn import preprocessing
  8. '''
  9. Method which extracts SVD features from image and returns 's' vector
  10. @return 's' vector
  11. '''
  12. def get_s_model_data(image):
  13. U, s, V = svd(image, full_matrices=False)
  14. size = len(s)
  15. # normalized output
  16. output_normalized = preprocessing.normalize(s, norm='l2', axis=1, copy=True, return_norm=False)
  17. result = output_normalized.reshape([size, 1, 3])
  18. return result
  19. def get(image):
  20. return svd(image, full_matrices=False)
  21. def get_s(image):
  22. U, s, V = svd(image, full_matrices=False)
  23. return s
  24. def get_U(image):
  25. U, s, V = svd(image, full_matrices=False)
  26. return U
  27. def get_V(image):
  28. U, s, V = svd(image, full_matrices=False)
  29. return V