Commit 476167ed authored by clunietp's avatar clunietp

BRISQUE initial commit

Set BRISQUE expected scores from original impl

Added BRISQUE models and interface, test methods

[alalek] drop changes from libsvm files
parent f0e70cbf
set(the_description "Image Quality Analysis API")
ocv_define_module(quality opencv_core opencv_imgproc WRAP python)
ocv_add_testdata(testdata/ contrib/quality
FILES_MATCHING PATTERN "*.dat"
)
\ No newline at end of file
......@@ -10,5 +10,6 @@
#include "quality/qualitypsnr.hpp"
#include "quality/qualityssim.hpp"
#include "quality/qualitygmsd.hpp"
#include "quality/qualitybrisque.hpp"
#endif
\ No newline at end of file
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_QUALITY_QUALITYBRISQUE_HPP
#define OPENCV_QUALITY_QUALITYBRISQUE_HPP
#include "qualitybase.hpp"
namespace cv
{
namespace quality
{
/**
@brief TODO: Brief description and reference to original BRISQUE paper/implementation
*/
class CV_EXPORTS_W QualityBRISQUE : public QualityBase {
public:
/** @brief Computes XXX for reference images supplied in class constructor and provided comparison images
@param imgs Images for which to compute quality
@returns TODO: describe the resulting cv::Scalar
*/
CV_WRAP cv::Scalar compute( InputArrayOfArrays imgs ) CV_OVERRIDE;
/**
@brief Create an object which calculates quality
*/
CV_WRAP static Ptr<QualityBRISQUE> create(cv::String model, cv::String range);
/**
@brief static method for computing quality
@param model cv::String containing BRISQUE calculation model
@param range cv::String containing BRISQUE calculation range
@param imgs image(s) for which to compute quality
@param qualityMaps output quality map(s), or cv::noArray() TODO: remove this parameter if algorithm doesn't generate output quality maps
@returns TODO: describe the resulting cv::Scalar
*/
CV_WRAP static cv::Scalar compute( const cv::String& model, const cv::String& range, InputArrayOfArrays imgs, OutputArrayOfArrays qualityMaps );
/** @brief return the model used for computation */
CV_WRAP const cv::String& getModel() const { return _model; }
/** @brief sets the model used for computation */
CV_WRAP void setModel( cv::String val ) { this->_model = std::move(val); }
/** @brief return the range used for computation */
CV_WRAP const cv::String& getRange() const { return _range; }
/** @brief sets the range used for computation */
CV_WRAP void setRange(cv::String val) { this->_range = std::move(val); }
protected:
/**
@brief Constructor
*/
QualityBRISQUE( cv::String model, cv::String range );
/** @brief BRISQUE model string */
cv::String _model;
/** @brief BRISQUE range string */
cv::String _range;
}; // QualityBRISQUE
} // quality
} // cv
#endif
\ No newline at end of file
This diff is collapsed.
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
#define TEST_CASE_NAME CV_Quality_BRISQUE
namespace opencv_test
{
namespace quality_test
{
// brisque per channel
// computed test file values via original brisque impl, libsvm 318, opencv 2.x
const cv::Scalar
BRISQUE_EXPECTED_1 = { 31.155 } // testfile_1a
, BRISQUE_EXPECTED_2 = { 15.4114 } // testfile_2a
;
inline cv::String readfile(const cv::String& path)
{
std::ifstream is{ path };
std::stringstream buffer;
buffer << is.rdbuf();
return buffer.str();
}
// location of BRISQUE model and range file
// place these files in ${OPENCV_TEST_DATA_PATH}/quality/, or the tests will be skipped
inline cv::String readbrisquemodel() { return readfile(cvtest::findDataFile("brisque_allmodel.dat", false)); }
inline cv::String readbrisquerange() { return readfile(cvtest::findDataFile("brisque_allrange.dat", false)); }
// instantiates a brisque object for testing
inline cv::Ptr<quality::QualityBRISQUE> create_brisque()
{
return quality::QualityBRISQUE::create(
readbrisquemodel()
, readbrisquerange()
);
}
// static method
TEST(TEST_CASE_NAME, static_ )
{
std::vector<cv::Mat> qMats = {};
quality_expect_near(
quality::QualityBRISQUE::compute( readbrisquemodel(), readbrisquerange(), get_testfile_1a(), qMats), BRISQUE_EXPECTED_1
);
EXPECT_EQ(qMats.size(), 1U);
}
// single channel, instance method, with and without opencl
TEST(TEST_CASE_NAME, single_channel )
{
auto fn = []() { quality_test(create_brisque(), get_testfile_1a(), BRISQUE_EXPECTED_1); };
OCL_OFF( fn() );
OCL_ON( fn() );
}
// multi-channel
TEST(TEST_CASE_NAME, multi_channel)
{
quality_test(create_brisque(), get_testfile_2a(), BRISQUE_EXPECTED_2);
}
// multi-frame test
TEST(TEST_CASE_NAME, multi_frame)
{
// result mse == average of all frames
cv::Scalar expected;
cv::add(BRISQUE_EXPECTED_1, BRISQUE_EXPECTED_2, expected);
expected /= 2.;
quality_test(create_brisque(), get_testfile_1a2a(), expected, 2 );
}
// internal a/b test
/*
TEST(TEST_CASE_NAME, performance)
{
auto ref = get_testfile_1a();
quality_performance_test("BRISQUE", [&]() { cv::quality::QualityBRISQUE::compute(ref, cv::noArray()); });
}
*/
}
} // namespace
\ No newline at end of file
......@@ -3,4 +3,6 @@
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
CV_TEST_MAIN("")
\ No newline at end of file
CV_TEST_MAIN("",
cvtest::addDataSearchSubDirectory("quality")
)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment