display_svd_values.py 6.3 KB

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