OpenCV 4.5.3(日本語機械翻訳)
qualitypsnr.hpp
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
5 #ifndef OPENCV_QUALITY_QUALITYPSNR_HPP
6 #define OPENCV_QUALITY_QUALITYPSNR_HPP
7
8 #include <limits> // numeric_limits
9 #include "qualitybase.hpp"
10 #include "qualitymse.hpp"
11
12 namespace cv
13{
14 namespace quality
15{
16
20 class CV_EXPORTS_W QualityPSNR
21 : public QualityBase {
22
23 public:
24
26 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900 /*MSVS 2015*/ )
27 static constexpr double MAX_PIXEL_VALUE_DEFAULT = 255.;
28 #else
29 // support MSVS 2013
30 static const int MAX_PIXEL_VALUE_DEFAULT = 255;
31 #endif
32
38 CV_WRAP static Ptr<QualityPSNR> create( InputArray ref, double maxPixelValue = QualityPSNR::MAX_PIXEL_VALUE_DEFAULT )
39 {
40 return Ptr<QualityPSNR>(new QualityPSNR(QualityMSE::create(ref), maxPixelValue));
41 }
42
48 CV_WRAP cv::Scalar compute( InputArray cmp ) CV_OVERRIDE
49 {
50 auto result = _qualityMSE->compute( cmp );
51 _qualityMSE->getQualityMap(_qualityMap); // copy from internal obj to this obj
52 return _mse_to_psnr(
53 result
54 , _maxPixelValue
55 );
56 }
57
59 CV_WRAP bool empty() const CV_OVERRIDE { return _qualityMSE->empty() && QualityBase::empty(); }
60
62 CV_WRAP void clear() CV_OVERRIDE { _qualityMSE->clear(); QualityBase::clear(); }
63
72 CV_WRAP static cv::Scalar compute( InputArray ref, InputArray cmp, OutputArray qualityMap, double maxPixelValue = QualityPSNR::MAX_PIXEL_VALUE_DEFAULT)
73 {
74 return _mse_to_psnr(
75 QualityMSE::compute(ref, cmp, qualityMap)
76 , maxPixelValue
77 );
78 }
79
81 CV_WRAP double getMaxPixelValue() const { return _maxPixelValue; }
82
87 CV_WRAP void setMaxPixelValue(double val) { this->_maxPixelValue = val; }
88
89 protected:
90
91 Ptr<QualityMSE> _qualityMSE;
92 double _maxPixelValue = QualityPSNR::MAX_PIXEL_VALUE_DEFAULT;
93
95 QualityPSNR( Ptr<QualityMSE> qualityMSE, double maxPixelValue )
96 : _qualityMSE(std::move(qualityMSE))
97 , _maxPixelValue(maxPixelValue)
98 {}
99
100 // convert mse to psnr
101 static double _mse_to_psnr(double mse, double max_pixel_value)
102 {
103 return (mse == 0.)
104 ? std::numeric_limits<double>::infinity()
105 : 10. * std::log10((max_pixel_value * max_pixel_value) / mse)
106 ;
107 }
108
109 // convert scalar of mses to psnrs
110 static cv::Scalar _mse_to_psnr(cv::Scalar mse, double max_pixel_value)
111 {
112 for (int i = 0; i < mse.rows; ++i)
113 mse(i) = _mse_to_psnr(mse(i), max_pixel_value);
114 return mse;
115 }
116
117}; // QualityPSNR
118} // quality
119} // cv
120 #endif
This type is very similar to InputArray except that it is used for input/output and output function p...
Definition: mat.hpp:295
Definition: qualitybase.hpp:25
CV_WRAP void clear() CV_OVERRIDE
Implements Algorithm::clear()
Definition: qualitybase.hpp:46
CV_WRAP bool empty() const CV_OVERRIDE
Implements Algorithm::empty()
Definition: qualitybase.hpp:49
CV_WRAP cv::Scalar compute(InputArrayOfArrays cmpImgs) CV_OVERRIDE
Computes MSE for reference images supplied in class constructor and provided comparison images
static CV_WRAP Ptr< QualityMSE > create(InputArray ref)
Create an object which calculates quality
Full reference peak signal to noise ratio (PSNR) algorithm https://en.wikipedia.org/wiki/Peak_signal-...
Definition: qualitypsnr.hpp:21
static const int MAX_PIXEL_VALUE_DEFAULT
Default maximum pixel value
Definition: qualitypsnr.hpp:30
QualityPSNR(Ptr< QualityMSE > qualityMSE, double maxPixelValue)
Constructor
Definition: qualitypsnr.hpp:95
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
Definition: cvstd_wrapper.hpp:74