Commit aecc7900 authored by AndiBraimllari's avatar AndiBraimllari
Browse files

utilize straightforward psnr

parent 261b6ccf
Pipeline #879401 failed with stages
in 5 minutes and 17 seconds
......@@ -70,8 +70,8 @@ namespace elsa
data_t meanSquaredError(DataContainer<data_t> dc1, DataContainer<data_t> dc2)
{
if (dc1.getDataDescriptor() != dc2.getDataDescriptor()) {
throw LogicError(std::string(
"Statistics::meanSquaredError: shapes of both signals should match"));
throw LogicError(
"Statistics::meanSquaredError: shapes of both signals should match");
}
DataContainer<data_t> diff = dc1 - dc2;
......@@ -162,7 +162,7 @@ namespace elsa
{
if (dc1.getDataDescriptor() != dc2.getDataDescriptor()) {
throw InvalidArgumentError(
std::string("statistics::relativeError: shapes of both signals should match"));
"statistics::relativeError: shapes of both signals should match");
}
DataContainer<data_t> diff = dc1 - dc2;
......@@ -178,30 +178,6 @@ namespace elsa
*
* @param dc1 DataContainer signal
* @param dc2 DataContainer signal
* @param dataRange The data range of the signals (distance between minimum and maximum
* possible values).
*
* @author Andi Braimllari - initial code
*
* @tparam data_t data type for the domain and range of the problem, defaulting to real_t
*/
template <typename data_t = real_t>
data_t peakSignalToNoiseRatio(DataContainer<data_t> dc1, DataContainer<data_t> dc2,
data_t dataRange)
{
if (dc1.getDataDescriptor() != dc2.getDataDescriptor()) {
throw InvalidArgumentError(std::string(
"statistics::peakSignalToNoiseRatio: shapes of both signals should match"));
}
return 10 * std::log10((std::pow(dataRange, 2) / meanSquaredError(dc1, dc2)));
}
/**
* @brief Compute the Peak Signal-to-Noise Ratio.
*
* @param dc1 DataContainer signal
* @param dc2 DataContainer signal
*
* @author Andi Braimllari - initial code
*
......@@ -211,30 +187,11 @@ namespace elsa
data_t peakSignalToNoiseRatio(DataContainer<data_t> dc1, DataContainer<data_t> dc2)
{
if (dc1.getDataDescriptor() != dc2.getDataDescriptor()) {
throw InvalidArgumentError(std::string(
"statistics::peakSignalToNoiseRatio: shapes of both signals should match"));
}
data_t dataMin = std::numeric_limits<data_t>::min();
data_t dataMax = std::numeric_limits<data_t>::max();
data_t trueMin = std::min(dc1.minElement(), dc2.minElement());
data_t trueMax = std::max(dc1.maxElement(), dc2.maxElement());
if (trueMin < dataMin || trueMax > dataMax) {
throw InvalidArgumentError(
std::string("statistics::peakSignalToNoiseRatio: extreme values of the signals "
"exceed the range expected for its data type"));
}
data_t dataRange;
if (trueMin >= 0) {
dataRange = dataMax;
} else {
dataRange = dataMax - dataMin;
"statistics::peakSignalToNoiseRatio: shapes of both signals should match");
}
return peakSignalToNoiseRatio(dc1, dc2, dataRange);
return 20 * std::log10(dc1.maxElement()) - 10 * std::log10(meanSquaredError(dc1, dc2));
}
} // namespace statistics
......
......@@ -103,10 +103,8 @@ TEST_CASE_TEMPLATE("Math: Testing the statistics", TestType, float, double)
WHEN("running the Peak Signal-to-Noise Ratio")
{
auto dataRange = static_cast<TestType>(255);
auto psnr =
statistics::peakSignalToNoiseRatio<TestType>(dataCont1, dataCont2, dataRange);
auto expectedpsnr = static_cast<TestType>(22.73990);
auto psnr = statistics::peakSignalToNoiseRatio<TestType>(dataCont1, dataCont2);
auto expectedpsnr = static_cast<TestType>(9.09461);
THEN("it produces the correct result")
{
REQUIRE_UNARY(checkApproxEq(psnr, expectedpsnr));
......
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