display_bits_shifted.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from ipfml import image_processing
  2. from PIL import Image
  3. import numpy as np
  4. from ipfml import metrics
  5. from skimage import color
  6. import cv2
  7. nb_bits = 3
  8. max_nb_bits = 8
  9. low_bits_svd_values = []
  10. def open_and_display(path, i):
  11. img = Image.open(path)
  12. block_used = np.array(img)
  13. low_bits_block = image_processing.rgb_to_LAB_L_bits(block_used, (i + 1, i + nb_bits + 1))
  14. low_bits_svd = metrics.get_SVD_s(low_bits_block)
  15. low_bits_svd = [b / low_bits_svd[0] for b in low_bits_svd]
  16. low_bits_svd_values[i].append(low_bits_svd)
  17. path_noisy = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_00050.png'
  18. path_threshold = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_00400.png'
  19. path_ref = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_01200.png'
  20. path_list = [path_noisy, path_threshold, path_ref]
  21. for i in range(0, max_nb_bits - nb_bits + 1):
  22. low_bits_svd_values.append([])
  23. for p in path_list:
  24. open_and_display(p, i)
  25. import matplotlib.pyplot as plt
  26. # SVD
  27. # make a little extra space between the subplots
  28. fig=plt.figure(figsize=(8, 8))
  29. for id, l in enumerate(low_bits_svd_values):
  30. fig.add_subplot(3, 3, (id + 1))
  31. plt.plot(l[0], label='Noisy')
  32. plt.plot(l[1], label='Threshold')
  33. plt.plot(l[2], label='Reference')
  34. plt.title('Low ' + str(nb_bits) + ' bits SVD shifted by ' + str(id))
  35. plt.ylabel('Low ' + str(nb_bits) + ' bits SVD values')
  36. plt.xlabel('Vector features')
  37. plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
  38. plt.ylim(0, 0.1)
  39. plt.show()