svd_mean_rotations_view.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from ipfml import processing, utils
  2. from skimage import transform
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. import os
  6. from PIL import Image
  7. data_folder = "../fichiersSVD_light"
  8. def get_svd_mean_image_rotations(img_path):
  9. print("Extract features from... " + img_path)
  10. img = np.asarray(Image.open(img_path))
  11. width, height, dim = img.shape
  12. img_mean = np.empty([width, height, 3])
  13. rotations = []
  14. svd_data_rotation = []
  15. for i in range(4):
  16. rotations.append(processing.rotate_image(img, (i+1)*90, pil=False))
  17. svd_data_rotation.append(processing.get_LAB_L_SVD_s(rotations[i]))
  18. nb_rotations = len(rotations)
  19. img_mean = processing.fusion_images(rotations, pil=False)
  20. data = processing.get_LAB_L_SVD_s(img_mean)
  21. # getting max and min information from min_max_filename
  22. with open(data_folder + "/lab_min_max_values", 'r') as f:
  23. min_val = float(f.readline())
  24. max_val = float(f.readline())
  25. data = utils.normalize_arr_with_range(data, min_val, max_val)
  26. return data
  27. scene = 'Appart1opt02'
  28. mean_svd_values = []
  29. indices = ["00020", "00080", "00150", "00300", "00500", "00700", "00900"]
  30. for index in indices:
  31. path = os.path.join(data_folder, scene + '/appartAopt_' + index + '.png')
  32. mean_svd_values.append(get_svd_mean_image_rotations(path))
  33. plt.title("Information from merged rotations images at different noise level from " + scene + " scene", fontsize=22)
  34. plt.ylabel('Singular values', fontsize=18)
  35. plt.xlabel('Vector features', fontsize=18)
  36. for id, data in enumerate(mean_svd_values):
  37. p_label = "appartAopt_" + indices[id]
  38. plt.plot(data, label=p_label)
  39. plt.legend(bbox_to_anchor=(0.8, 1), loc=2, borderaxespad=0.2, fontsize=16)
  40. plt.ylim(0, 0.01)
  41. plt.show()