#include "test_precomp.hpp"

namespace cvtest
{
    TEST(colorbalance_SimpleColorBalance, regression)
    {
        cv::String dir = cvtest::TS::ptr()->get_data_path();
        int nTests = 12;
        float threshold = 0.005;

        for (int i = 0; i < nTests; ++i)
        {
            cv::String srcName = dir + cv::format( "sources/%02d.png", i + 1);
            cv::Mat src = cv::imread( srcName, 1 );

            cv::String previousResultName = dir + cv::format( "results/%02d.png", i + 1 );
            cv::Mat previousResult = cv::imread( previousResultName, 1 );

            cv::Mat currentResult;
            cv::balanceWhite(src, currentResult, cv::WHITE_BALANCE_SIMPLE);

            cv::Mat sqrError = ( currentResult - previousResult )
                .mul( currentResult - previousResult );
            cv::Scalar mse = cv::sum(sqrError) / cv::Scalar::all( sqrError.total()*sqrError.channels() );

            EXPECT_LE( mse[0]+mse[1]+mse[2]+mse[3], threshold );
        }
    }
}