2
0

iqa.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2011, Tom Distler (http://tdistler.com)
  3. * All rights reserved.
  4. *
  5. * The BSD License
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. *
  13. * - Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. *
  17. * - Neither the name of the tdistler.com nor the names of its contributors may
  18. * be used to endorse or promote products derived from this software without
  19. * specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #ifndef _IQA_H_
  34. #define _IQA_H_
  35. #include "iqa_os.h"
  36. /**
  37. * Allows fine-grain control of the SSIM algorithm.
  38. */
  39. struct iqa_ssim_args {
  40. float alpha; /**< luminance exponent */
  41. float beta; /**< contrast exponent */
  42. float gamma; /**< structure exponent */
  43. int L; /**< dynamic range (2^8 - 1)*/
  44. float K1; /**< stabilization constant 1 */
  45. float K2; /**< stabilization constant 2 */
  46. int f; /**< scale factor. 0=default scaling, 1=no scaling */
  47. };
  48. /**
  49. * Allows fine-grain control of the MS-SSIM algorithm.
  50. */
  51. struct iqa_ms_ssim_args {
  52. int wang; /**< 1=original algorithm by Wang, et al. 0=MS-SSIM* by Rouse/Hemami (default). */
  53. int gaussian; /**< 1=11x11 Gaussian window (default). 0=8x8 linear window. */
  54. int scales; /**< Number of scaled images to use. Default is 5. */
  55. const float *alphas; /**< Pointer to array of alpha values for each scale. Required if 'scales' isn't 5. */
  56. const float *betas; /**< Pointer to array of beta values for each scale. Required if 'scales' isn't 5. */
  57. const float *gammas; /**< Pointer to array of gamma values for each scale. Required if 'scales' isn't 5. */
  58. };
  59. /**
  60. * Calculates the Mean Squared Error between 2 equal-sized 8-bit images.
  61. * @note The images must have the same width, height, and stride.
  62. * @param ref Original reference image
  63. * @param cmp Distorted image
  64. * @param w Width of the images
  65. * @param h Height of the images
  66. * @param stride The length (in bytes) of each horizontal line in the image.
  67. * This may be different from the image width.
  68. * @return The MSE.
  69. */
  70. float iqa_mse(const unsigned char *ref, const unsigned char *cmp, int w, int h, int stride);
  71. /**
  72. * Calculates the Peak Signal-to-Noise-Ratio between 2 equal-sized 8-bit
  73. * images.
  74. * @note The images must have the same width, height, and stride.
  75. * @param ref Original reference image
  76. * @param cmp Distorted image
  77. * @param w Width of the images
  78. * @param h Height of the images
  79. * @param stride The length (in bytes) of each horizontal line in the image.
  80. * This may be different from the image width.
  81. * @return The PSNR.
  82. */
  83. float iqa_psnr(const unsigned char *ref, const unsigned char *cmp, int w, int h, int stride);
  84. /**
  85. * Calculates the Structural SIMilarity between 2 equal-sized 8-bit images.
  86. *
  87. * See https://ece.uwaterloo.ca/~z70wang/publications/ssim.html
  88. * @note The images must have the same width, height, and stride.
  89. * @param ref Original reference image
  90. * @param cmp Distorted image
  91. * @param w Width of the images
  92. * @param h Height of the images
  93. * @param stride The length (in bytes) of each horizontal line in the image.
  94. * This may be different from the image width.
  95. * @param gaussian 0 = 8x8 square window, 1 = 11x11 circular-symmetric Gaussian
  96. * weighting.
  97. * @param args Optional SSIM arguments for fine control of the algorithm. 0 for
  98. * defaults. Defaults are a=b=g=1.0, L=255, K1=0.01, K2=0.03
  99. * @return The mean SSIM over the entire image (MSSIM), or INFINITY if error.
  100. */
  101. float iqa_ssim(const unsigned char *ref, const unsigned char *cmp, int w, int h, int stride,
  102. int gaussian, const struct iqa_ssim_args *args);
  103. /**
  104. * Calculates the Multi-Scale Structural SIMilarity between 2 equal-sized 8-bit
  105. * images. The default algorithm is MS-SSIM* proposed by Rouse/Hemami 2008.
  106. *
  107. * See https://ece.uwaterloo.ca/~z70wang/publications/msssim.pdf and
  108. * http://foulard.ece.cornell.edu/publications/dmr_hvei2008_paper.pdf
  109. *
  110. * @note 1. The images must have the same width, height, and stride.
  111. * @note 2. The minimum image width or height is 2^(scales-1) * filter, where 'filter' is 11
  112. * if a Gaussian window is being used, or 9 otherwise.
  113. * @param ref Original reference image
  114. * @param cmp Distorted image
  115. * @param w Width of the images.
  116. * @param h Height of the images.
  117. * @param stride The length (in bytes) of each horizontal line in the image.
  118. * This may be different from the image width.
  119. * @param args Optional MS-SSIM arguments for fine control of the algorithm. 0
  120. * for defaults. Defaults are wang=0, scales=5, gaussian=1.
  121. * @return The mean MS-SSIM over the entire image, or INFINITY if error.
  122. */
  123. float iqa_ms_ssim(const unsigned char *ref, const unsigned char *cmp, int w, int h, int stride,
  124. const struct iqa_ms_ssim_args *args);
  125. #endif /*_IQA_H_*/