Skip to content

Commit

Permalink
[hdr] Split hdr test into multiple executables
Browse files Browse the repository at this point in the history
Currently HDR test is one of the longest running tests at ~120 seconds
on AMD 2990WX. Splitting it up reduces test runtime in cases testsuite
is run in parallel.
  • Loading branch information
p12tic committed Oct 10, 2022
1 parent 9c8d8ed commit a9aae95
Show file tree
Hide file tree
Showing 6 changed files with 463 additions and 416 deletions.
14 changes: 12 additions & 2 deletions src/aliceVision/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ alicevision_add_library(aliceVision_hdr
)

# Unit tests
alicevision_add_test(hdr_test.cpp
NAME "hdr"
alicevision_add_test(hdrDebevec_test.cpp
NAME "hdr_debevec"
LINKS aliceVision_image aliceVision_hdr)

alicevision_add_test(hdrGrossberg_test.cpp
NAME "hdr_grossberg"
LINKS aliceVision_image aliceVision_hdr)

alicevision_add_test(hdrLaguerre_test.cpp
NAME "hdr_laguerre"
LINKS aliceVision_image aliceVision_hdr)


92 changes: 92 additions & 0 deletions src/aliceVision/hdr/hdrDebevec_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// This file is part of the AliceVision project.
// Copyright (c) 2022 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#define BOOST_TEST_MODULE hdr_debevec

#include "hdrTestCommon.hpp"
#include "DebevecCalibrate.hpp"
#include "LaguerreBACalibration.hpp"

#include <boost/test/unit_test.hpp>

using namespace aliceVision;

BOOST_AUTO_TEST_CASE(hdr_debevec)
{
std::vector<std::string> paths;
std::vector<double> times;

const size_t quantization = pow(2, 10);
hdr::rgbCurve gt_curve(quantization);

std::array<float, 3> laguerreParams = {-0.8, 0.8, -0.3};
for(int i = 0; i < quantization; i++)
{
float x = float(i) / float(quantization - 1);
gt_curve.getCurve(0)[i] = hdr::laguerreFunction(laguerreParams[0], x);
gt_curve.getCurve(1)[i] = hdr::laguerreFunction(laguerreParams[1], x);
gt_curve.getCurve(2)[i] = hdr::laguerreFunction(laguerreParams[2], x);
}

test::buildBrackets(paths, times, gt_curve);

std::vector<std::vector<std::string>> all_paths;
all_paths.push_back(paths);

std::vector<std::vector<double>> exposures;
exposures.push_back(times);

hdr::DebevecCalibrate calib;
hdr::rgbCurve response(quantization);
hdr::rgbCurve calibrationWeight(quantization);

calibrationWeight.setTriangular();

std::vector<std::vector<hdr::ImageSample>> samples;
test::extractSamplesGroups(samples, all_paths, exposures, quantization);
calib.process(samples, exposures, quantization, calibrationWeight, 0.001, response);
response.exponential();

for(int imageId = 0; imageId < paths.size() - 1; imageId++)
{
image::Image<image::RGBfColor> imgA, imgB;
image::readImage(paths[imageId], imgA, image::EImageColorSpace::LINEAR);
image::readImage(paths[imageId + 1], imgB, image::EImageColorSpace::LINEAR);

BOOST_CHECK(imgA.size() == imgB.size());
double ratioExposures = times[imageId] / times[imageId + 1];

double max_diff = 0.0;
for(int i = 0; i < imgA.Height(); i++)
{
for(int j = 0; j < imgA.Width(); j++)
{
image::RGBfColor Ba = imgA(i, j);
image::RGBfColor Bb = imgB(i, j);
for(int k = 0; k < 3; k++)
{
double responseA = response(Ba(k), k);
double responseB = response(Bb(k), k);
double hdrA = responseA / times[imageId];
double hdrB = responseB / times[imageId + 1];
double diff = std::abs(responseA - ratioExposures * responseB);

if (Ba(k) < 0.01) diff = 0.0;
if (Bb(k) > 0.96) diff = 0.0;
if (hdrA > 0.99) diff = 0.0;
if (hdrB > 0.99) diff = 0.0;

max_diff = std::max(diff, max_diff);

}
}
}


BOOST_CHECK(std::isfinite(max_diff));
BOOST_CHECK_SMALL(max_diff, 0.01);
}
}
97 changes: 97 additions & 0 deletions src/aliceVision/hdr/hdrGrossberg_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// This file is part of the AliceVision project.
// Copyright (c) 2022 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#define BOOST_TEST_MODULE hdr_debevec

#include "hdrTestCommon.hpp"
#include "GrossbergCalibrate.hpp"

#include <boost/test/unit_test.hpp>

using namespace aliceVision;

BOOST_AUTO_TEST_CASE(hdr_grossberg)
{
std::vector<std::string> paths;
std::vector<double> times;

const size_t quantization = pow(2, 10);
hdr::rgbCurve gt_curve(quantization);

gt_curve.setEmor(0);
std::array<double, 3> grossberg_params[3] = {
{0.8, 0.3, 0.2},
{-0.1, -0.3, 0.2},
{2.1, 0.05, 0.4}
};

for(int dim = 0; dim < 3; dim++)
{
hdr::rgbCurve dim_curve(quantization);
dim_curve.setEmor(dim + 1);

for(int k = 0; k < quantization; k++)
{
gt_curve.getCurve(0)[k] += grossberg_params[0][dim] * dim_curve.getCurve(0)[k];
gt_curve.getCurve(1)[k] += grossberg_params[1][dim] * dim_curve.getCurve(0)[k];
gt_curve.getCurve(2)[k] += grossberg_params[2][dim] * dim_curve.getCurve(0)[k];
}
}

test::buildBrackets(paths, times, gt_curve);

std::vector<std::vector<std::string>> all_paths;
std::vector<std::vector<double>> exposures;

all_paths.push_back(paths);
exposures.push_back(times);

hdr::GrossbergCalibrate calib(9);
hdr::rgbCurve response(quantization);

std::vector<std::vector<hdr::ImageSample>> samples;
test::extractSamplesGroups(samples, all_paths, exposures, quantization);
calib.process(samples, exposures, quantization, response);

for(int imageId = 0; imageId < paths.size() - 1; imageId++)
{
image::Image<image::RGBfColor> imgA, imgB;
image::readImage(paths[imageId], imgA, image::EImageColorSpace::LINEAR);
image::readImage(paths[imageId + 1], imgB, image::EImageColorSpace::LINEAR);

BOOST_CHECK(imgA.size() == imgB.size());
double ratioExposures = times[imageId] / times[imageId + 1];

double max_diff = 0.0;
for(int i = 0; i < imgA.Height(); i++)
{
for(int j = 0; j < imgA.Width(); j++)
{
image::RGBfColor Ba = imgA(i, j);
image::RGBfColor Bb = imgB(i, j);
for(int k = 0; k < 3; k++)
{
double responseA = response(Ba(k), k);
double responseB = response(Bb(k), k);
double hdrA = responseA / times[imageId];
double hdrB = responseB / times[imageId + 1];
double diff = std::abs(responseA - ratioExposures * responseB);

if (Bb(k) > 0.93) diff = 0.0;
if (hdrA > 0.99) diff = 0.0;
if (hdrB > 0.99) diff = 0.0;

max_diff = std::max(diff, max_diff);

}
}
}


BOOST_CHECK(std::isfinite(max_diff));
BOOST_CHECK_SMALL(max_diff, 2.0 * 1e-3);
}
}
84 changes: 84 additions & 0 deletions src/aliceVision/hdr/hdrLaguerre_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// This file is part of the AliceVision project.
// Copyright (c) 2022 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#define BOOST_TEST_MODULE hdr_debevec

#include "hdrTestCommon.hpp"
#include "LaguerreBACalibration.hpp"

#include <boost/test/unit_test.hpp>

using namespace aliceVision;

BOOST_AUTO_TEST_CASE(hdr_laguerre)
{
std::vector<std::string> paths;
std::vector<double> times;

const size_t quantization = pow(2, 10);
hdr::rgbCurve gt_curve(quantization);

std::array<float, 3> laguerreParams = {-0.2, 0.4, -0.3};
for(int i = 0; i < quantization; i++)
{
float x = float(i) / float(quantization - 1);
gt_curve.getCurve(0)[i] = hdr::laguerreFunction(laguerreParams[0], x);
gt_curve.getCurve(1)[i] = hdr::laguerreFunction(laguerreParams[1], x);
gt_curve.getCurve(2)[i] = hdr::laguerreFunction(laguerreParams[2], x);
}

test::buildBrackets(paths, times, gt_curve);

std::vector<std::vector<std::string>> all_paths;
all_paths.push_back(paths);
std::vector<std::vector<double>> exposures;
exposures.push_back(times);
hdr::LaguerreBACalibration calib;
hdr::rgbCurve response(quantization);

std::vector<std::vector<hdr::ImageSample>> samples;
test::extractSamplesGroups(samples, all_paths, exposures, quantization);
calib.process(samples, exposures, quantization, false, response);

for(int imageId = 0; imageId < paths.size() - 1; imageId++)
{
image::Image<image::RGBfColor> imgA, imgB;
image::readImage(paths[imageId], imgA, image::EImageColorSpace::LINEAR);
image::readImage(paths[imageId + 1], imgB, image::EImageColorSpace::LINEAR);

BOOST_CHECK(imgA.size() == imgB.size());
double ratioExposures = times[imageId] / times[imageId + 1];

double max_diff = 0.0;
for(int i = 0; i < imgA.Height(); i++)
{
for(int j = 0; j < imgA.Width(); j++)
{
image::RGBfColor Ba = imgA(i, j);
image::RGBfColor Bb = imgB(i, j);
for(int k = 0; k < 3; k++)
{
double responseA = response(Ba(k), k);
double responseB = response(Bb(k), k);
double hdrA = responseA / times[imageId];
double hdrB = responseB / times[imageId + 1];
double diff = std::abs(responseA - ratioExposures * responseB);

if (Bb(k) > 0.99) diff = 0.0;
if (hdrA > 1.0) diff = 0.0;
if (hdrB > 1.0) diff = 0.0;

max_diff = std::max(diff, max_diff);

}
}
}


BOOST_CHECK(std::isfinite(max_diff));
BOOST_CHECK_SMALL(max_diff, 1e-3);
}
}
Loading

0 comments on commit a9aae95

Please sign in to comment.