metrics.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # module file which contains all image metrics used in project
  2. from numpy.linalg import svd
  3. from scipy import misc
  4. import numpy as np
  5. from sklearn import preprocessing
  6. from skimage import io, color
  7. def get_SVD(image):
  8. """
  9. @brief Transforms Image into SVD
  10. @param image to convert
  11. @return U, s, V image decomposition
  12. """
  13. return svd(image, full_matrices=False)
  14. def get_SVD_s(image):
  15. """
  16. @brief Transforms Image into SVD and returns only 's' part
  17. @param image to convert
  18. @return s
  19. """
  20. U, s, V = svd(image, full_matrices=False)
  21. return s
  22. def get_SVD_U(image):
  23. """
  24. @brief Transforms Image into SVD and returns only 'U' part
  25. @param image to convert
  26. @return U
  27. """
  28. U, s, V = svd(image, full_matrices=False)
  29. return U
  30. def get_SVD_V(image):
  31. """
  32. @brief Transforms Image into SVD and returns only 'V' part
  33. @param image to convert
  34. @return V
  35. """
  36. U, s, V = svd(image, full_matrices=False)
  37. return V
  38. def get_LAB(image):
  39. """
  40. @brief Transforms PIL RGB Image into LAB
  41. @param image to convert
  42. @return Lab information
  43. """
  44. rgb = io.imread(image.filename)
  45. return color.rgb2lab(rgb)
  46. def get_LAB_L(image):
  47. """
  48. @brief Transforms PIL RGB Image into LAB and returns L
  49. @param image to convert
  50. @return Lab information
  51. """
  52. rgb = io.imread(image.filename)
  53. lab = color.rgb2lab(rgb)
  54. return lab[:, :, 0]
  55. def get_LAB_A(image):
  56. """
  57. @brief Transforms PIL RGB Image into LAB and returns A
  58. @param image to convert
  59. @return Lab information
  60. """
  61. rgb = io.imread(image.filename)
  62. lab = color.rgb2lab(rgb)
  63. return lab[:, :, 1]
  64. def get_LAB_B(image):
  65. """
  66. @brief Transforms PIL RGB Image into LAB and returns B
  67. @param image to convert
  68. @return Lab information
  69. """
  70. rgb = io.imread(image.filename)
  71. lab = color.rgb2lab(rgb)
  72. return lab[:, :, 2]
  73. def get_XYZ(image):
  74. """
  75. @brief Transforms PIL RGB Image into XYZ
  76. @param image to convert
  77. @return Lab information
  78. """
  79. rgb = io.imread(image.filename)
  80. return color.rgb2xyz(rgb)
  81. def get_XYZ_X(image):
  82. """
  83. @brief Transforms PIL RGB Image into XYZ and returns X
  84. @param image to convert
  85. @return Lab information
  86. """
  87. rgb = io.imread(image.filename)
  88. xyz = color.rgb2xyz(rgb)
  89. return xyz[:, :, 0]
  90. def get_XYZ_Y(image):
  91. """
  92. @brief Transforms PIL RGB Image into XYZ and returns Y
  93. @param image to convert
  94. @return Lab information
  95. """
  96. rgb = io.imread(image.filename)
  97. xyz = color.rgb2xyz(rgb)
  98. return xyz[:, :, 1]
  99. def get_XYZ_Z(image):
  100. """
  101. @brief Transforms PIL RGB Image into XYZ and returns Z
  102. @param image to convert
  103. @return Lab information
  104. """
  105. rgb = io.imread(image.filename)
  106. xyz = color.rgb2xyz(rgb)
  107. return xyz[:, :, 2]