preprocessing_functions.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from numpy.linalg import svd
  2. from PIL import Image
  3. import matplotlib.pyplot as plt
  4. from scipy import misc
  5. import time
  6. import numpy as np
  7. from sklearn import preprocessing
  8. import ipfml as iml
  9. def get_s_model_data(image):
  10. s = iml.metrics.get_SVD_s(image)
  11. size = len(s)
  12. # normalized output
  13. output_normalized = preprocessing.normalize(s, norm='l1', axis=0, copy=True, return_norm=False)
  14. result = output_normalized.reshape([size, 1, 3])
  15. return result
  16. def get_s_model_data_img(image, ):
  17. fig_size = plt.rcParams["figure.figsize"]
  18. fig_size[0] = 1
  19. fig_size[1] = 1
  20. plt.rcParams["figure.figsize"] = fig_size
  21. s = iml.metrics.get_SVD_s(image)
  22. plt.figure() # create a new figure
  23. output_normalized = preprocessing.normalize(s, norm='l1', axis=0, copy=True, return_norm=False)
  24. plt.plot(output_normalized[70:100, 0])
  25. plt.plot(output_normalized[70:100:, 1])
  26. plt.plot(output_normalized[70:100:, 2])
  27. img = iml.image_processing.fig2img(plt.gcf())
  28. plt.close('all')
  29. return img