display_svd_values.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. low_bits_2_svd_values = []
  8. low_bits_3_svd_values = []
  9. low_bits_4_svd_values = []
  10. mscn_revisited_svd_values = []
  11. mscn_svd_values = []
  12. lab_svd_values = []
  13. def open_and_display(path):
  14. img = Image.open(path)
  15. block_used = np.array(img)
  16. img_mscn = image_processing.rgb_to_mscn(block_used)
  17. #img_mscn_norm = image_processing.normalize_2D_arr(img_mscn)
  18. #print(img_mscn)
  19. img_output = img_mscn.astype('uint8')
  20. print('-------------------------')
  21. # MSCN part computation
  22. mscn_s = metrics.get_SVD_s(img_output)
  23. mscn_s = [m / mscn_s[0] for m in mscn_s]
  24. mscn_revisited_svd_values.append(mscn_s)
  25. # LAB part computation
  26. path_block_img = '/tmp/lab_img.png'
  27. img_used_pil = Image.fromarray(block_used.astype('uint8'), 'RGB')
  28. img_used_pil.save(path_block_img)
  29. lab_s = image_processing.get_LAB_L_SVD_s(Image.open(path_block_img))
  30. lab_s = [l / lab_s[0] for l in lab_s]
  31. lab_svd_values.append(lab_s)
  32. # computation of low bits parts 2 bits
  33. low_bits_block = image_processing.rgb_to_LAB_L_low_bits(block_used, 3)
  34. low_bits_svd = metrics.get_SVD_s(low_bits_block)
  35. low_bits_svd = [b / low_bits_svd[0] for b in low_bits_svd]
  36. low_bits_2_svd_values.append(low_bits_svd)
  37. # computation of low bits parts 3 bits
  38. low_bits_block = image_processing.rgb_to_LAB_L_low_bits(block_used, 7)
  39. low_bits_svd = metrics.get_SVD_s(low_bits_block)
  40. low_bits_svd = [b / low_bits_svd[0] for b in low_bits_svd]
  41. low_bits_3_svd_values.append(low_bits_svd)
  42. # computation of low bits parts 4 bits
  43. low_bits_block = image_processing.rgb_to_LAB_L_low_bits(block_used)
  44. low_bits_svd = metrics.get_SVD_s(low_bits_block)
  45. low_bits_svd = [b / low_bits_svd[0] for b in low_bits_svd]
  46. low_bits_4_svd_values.append(low_bits_svd)
  47. # Other MSCN
  48. img_grey = np.array(color.rgb2gray(np.asarray(block_used))*255, 'uint8')
  49. img_mscn_in_grey = np.array(image_processing.normalize_2D_arr(image_processing.calculate_mscn_coefficients(img_grey, 7))*255, 'uint8')
  50. svd_s_values = metrics.get_SVD_s(img_mscn_in_grey)
  51. svd_s_values = [s / svd_s_values[0] for s in svd_s_values]
  52. mscn_svd_values.append(svd_s_values)
  53. #path_noisy = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Appart1opt02/appartAopt_00020.png'
  54. #path_threshold = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Appart1opt02/appartAopt_00300.png'
  55. #path_ref = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Appart1opt02/appartAopt_00900.png'
  56. path_noisy = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_00050.png'
  57. path_threshold = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_00400.png'
  58. path_ref = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_01200.png'
  59. path_list = [path_noisy, path_threshold, path_ref]
  60. for p in path_list:
  61. open_and_display(p)
  62. import matplotlib.pyplot as plt
  63. # SVD
  64. # make a little extra space between the subplots
  65. plt.plot(lab_svd_values[0], label='Noisy')
  66. plt.plot(lab_svd_values[1], label='Threshold')
  67. plt.plot(lab_svd_values[2], label='Reference')
  68. plt.ylabel('LAB SVD')
  69. plt.xlabel('Vector features')
  70. plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
  71. plt.ylim(0, 0.1)
  72. plt.show()
  73. plt.plot(mscn_svd_values[0], label='Noisy')
  74. plt.plot(mscn_svd_values[1], label='Threshold')
  75. plt.plot(mscn_svd_values[2], label='Reference')
  76. plt.ylabel('MSCN SVD')
  77. plt.xlabel('Vector features')
  78. plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
  79. plt.ylim(0, 0.1)
  80. plt.show()
  81. plt.plot(mscn_revisited_svd_values[0], label='Noisy')
  82. plt.plot(mscn_revisited_svd_values[1], label='Threshold')
  83. plt.plot(mscn_revisited_svd_values[2], label='Reference')
  84. plt.ylabel('Revisited MSCN SVD')
  85. plt.xlabel('Vector features')
  86. plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
  87. plt.ylim(0, 0.1)
  88. plt.show()
  89. plt.plot(low_bits_2_svd_values[0], label='Noisy')
  90. plt.plot(low_bits_2_svd_values[1], label='Threshold')
  91. plt.plot(low_bits_2_svd_values[2], label='Reference')
  92. plt.ylabel('Low 2 bits SVD')
  93. plt.xlabel('Vector features')
  94. plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
  95. plt.ylim(0, 0.1)
  96. plt.show()
  97. plt.plot(low_bits_3_svd_values[0], label='Noisy')
  98. plt.plot(low_bits_3_svd_values[1], label='Threshold')
  99. plt.plot(low_bits_3_svd_values[2], label='Reference')
  100. plt.ylabel('Low 3 bits SVD')
  101. plt.xlabel('Vector features')
  102. plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
  103. plt.ylim(0, 0.1)
  104. plt.show()
  105. plt.plot(low_bits_4_svd_values[0], label='Noisy')
  106. plt.plot(low_bits_4_svd_values[1], label='Threshold')
  107. plt.plot(low_bits_4_svd_values[2], label='Reference')
  108. plt.ylabel('Low 4 bits SVD')
  109. plt.xlabel('Vector features')
  110. plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
  111. plt.ylim(0, 0.1)
  112. plt.show()