qualityssim.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #ifndef OPENCV_QUALITY_QUALITYSSIM_HPP
  5. #define OPENCV_QUALITY_QUALITYSSIM_HPP
  6. #include "qualitybase.hpp"
  7. namespace cv
  8. {
  9. namespace quality
  10. {
  11. /**
  12. @brief Full reference structural similarity algorithm https://en.wikipedia.org/wiki/Structural_similarity
  13. */
  14. class CV_EXPORTS_W QualitySSIM
  15. : public QualityBase {
  16. public:
  17. /**
  18. @brief Computes SSIM
  19. @param cmp Comparison image
  20. @returns cv::Scalar with per-channel quality values. Values range from 0 (worst) to 1 (best)
  21. */
  22. CV_WRAP cv::Scalar compute( InputArray cmp ) CV_OVERRIDE;
  23. /** @brief Implements Algorithm::empty() */
  24. CV_WRAP bool empty() const CV_OVERRIDE { return _refImgData.empty() && QualityBase::empty(); }
  25. /** @brief Implements Algorithm::clear() */
  26. CV_WRAP void clear() CV_OVERRIDE { _refImgData = _mat_data(); QualityBase::clear(); }
  27. /**
  28. @brief Create an object which calculates quality
  29. @param ref input image to use as the reference image for comparison
  30. */
  31. CV_WRAP static Ptr<QualitySSIM> create( InputArray ref );
  32. /**
  33. @brief static method for computing quality
  34. @param ref reference image
  35. @param cmp comparison image
  36. @param qualityMap output quality map, or cv::noArray()
  37. @returns cv::Scalar with per-channel quality values. Values range from 0 (worst) to 1 (best)
  38. */
  39. CV_WRAP static cv::Scalar compute( InputArray ref, InputArray cmp, OutputArray qualityMap );
  40. protected:
  41. // holds computed values for a mat
  42. struct _mat_data
  43. {
  44. // internal mat type
  45. using mat_type = QualityBase::_mat_type;
  46. mat_type
  47. I
  48. , I_2
  49. , mu
  50. , mu_2
  51. , sigma_2
  52. ;
  53. // allow default construction
  54. _mat_data() = default;
  55. // construct from mat_type
  56. _mat_data(const mat_type&);
  57. // construct from inputarray
  58. _mat_data(InputArray);
  59. // return flag if this is empty
  60. bool empty() const { return I.empty() && I_2.empty() && mu.empty() && mu_2.empty() && sigma_2.empty(); }
  61. // computes ssim and quality map for single frame
  62. static std::pair<cv::Scalar, mat_type> compute(const _mat_data& lhs, const _mat_data& rhs);
  63. }; // mat_data
  64. /** @brief Reference image data */
  65. _mat_data _refImgData;
  66. /**
  67. @brief Constructor
  68. @param refImgData reference image, converted to internal type
  69. */
  70. QualitySSIM( _mat_data refImgData )
  71. : _refImgData( std::move(refImgData) )
  72. {}
  73. }; // QualitySSIM
  74. } // quality
  75. } // cv
  76. #endif