svd_roration_view.py 2.0 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_and_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. Image.fromarray(rotations[i]).show()
  19. mean_image = processing.fusion_images(rotations, pil=False)
  20. mean_data = processing.get_LAB_L_SVD_s(mean_image)
  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. mean_data = utils.normalize_arr_with_range(mean_data, min_val, max_val)
  26. return [utils.normalize_arr_with_range(data, min_val, max_val) for data in svd_data_rotation], mean_data
  27. scene = 'Appart1opt02'
  28. indices = ["00020", "00080", "00150", "00300", "00500", "00700", "00900"]
  29. for index in indices:
  30. path = os.path.join(data_folder, scene + '/appartAopt_' + index + '.png')
  31. svd_data, mean_svd_data = get_svd_mean_and_image_rotations(path)
  32. plt.title("SVD information of rotations and merged image from " + scene + " scene", fontsize=22)
  33. plt.ylabel('Singular values', fontsize=18)
  34. plt.xlabel('Vector features', fontsize=18)
  35. for id, data in enumerate(svd_data):
  36. p_label = "appartAopt_" + index + "_" + str((id +1) * 90)
  37. plt.plot(data, label=p_label)
  38. mean_label = "appartAopt_" + index + "_mean"
  39. plt.plot(mean_svd_data, label=mean_label)
  40. plt.legend(bbox_to_anchor=(0.8, 1), loc=2, borderaxespad=0.2, fontsize=16)
  41. plt.ylim(0, 0.01)
  42. plt.show()