Test color conversion.
#include <visp3/core/vpConfig.h>
#if defined(VISP_HAVE_CATCH2)
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
#include <visp3/core/vpImageConvert.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/io/vpImageIo.h>
#include "common.hpp"
static const double maxMeanPixelError = 1.5;
static const unsigned int width = 223, height = 151;
TEST_CASE("Gray to RGBa conversion", "[image_conversion]") {
SECTION("Image 1x16 (SSE41 aligned=true)")
{
unsigned int h = 1, w = 16;
common_tools::fill(gray);
common_tools::grayToRGBaRef(gray.
bitmap, reinterpret_cast<unsigned char*>(rgba_ref.
bitmap), gray.
getSize());
CHECK((rgba == rgba_ref));
}
SECTION("Image 1x17 (SSE41 aligned=false)")
{
unsigned int h = 1, w = 17;
common_tools::fill(gray);
common_tools::grayToRGBaRef(gray.
bitmap, reinterpret_cast<unsigned char*>(rgba_ref.
bitmap), gray.
getSize());
CHECK((rgba == rgba_ref));
}
SECTION("Image 1x32 (AVX2 aligned=true)")
{
unsigned int h = 1, w = 32;
common_tools::fill(gray);
common_tools::grayToRGBaRef(gray.
bitmap, reinterpret_cast<unsigned char*>(rgba_ref.
bitmap), gray.
getSize());
CHECK((rgba == rgba_ref));
}
SECTION("Image 1x33 (AVX2 aligned=false)")
{
unsigned int h = 1, w = 33;
common_tools::fill(gray);
common_tools::grayToRGBaRef(gray.
bitmap, reinterpret_cast<unsigned char*>(rgba_ref.
bitmap), gray.
getSize());
CHECK((rgba == rgba_ref));
}
SECTION("Image 4x64 (general aligned = true")
{
unsigned int h = 4, w = 64;
common_tools::fill(gray);
common_tools::grayToRGBaRef(gray.
bitmap, reinterpret_cast<unsigned char*>(rgba_ref.
bitmap), gray.
getSize());
CHECK((rgba == rgba_ref));
}
SECTION("Image 5x65 (general aligned = false")
{
unsigned int h = 5, w = 65;
common_tools::fill(gray);
common_tools::grayToRGBaRef(gray.
bitmap, reinterpret_cast<unsigned char*>(rgba_ref.
bitmap), gray.
getSize());
CHECK((rgba == rgba_ref));
}
}
TEST_CASE("RGBa to Gray conversion", "[image_conversion]") {
SECTION("Image 1x16 (SSE41 aligned=true)")
{
unsigned int h = 1, w = 16;
common_tools::fill(rgba);
common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.
bitmap), gray_ref.
bitmap, rgba.
getSize());
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGBa to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x17 (SSE41 aligned=false)")
{
unsigned int h = 1, w = 17;
common_tools::fill(rgba);
common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.
bitmap), gray_ref.
bitmap, rgba.
getSize());
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGBa to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x32 (AVX2 aligned=true)")
{
unsigned int h = 1, w = 32;
common_tools::fill(rgba);
common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.
bitmap), gray_ref.
bitmap, rgba.
getSize());
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGBa to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x33 (AVX2 aligned=false)")
{
unsigned int h = 1, w = 33;
common_tools::fill(rgba);
common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.
bitmap), gray_ref.
bitmap, rgba.
getSize());
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGBa to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 4x64 (general aligned = true")
{
unsigned int h = 4, w = 64;
common_tools::fill(rgba);
common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.
bitmap), gray_ref.
bitmap, rgba.
getSize());
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGBa to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 5x65 (general aligned = false")
{
unsigned int h = 5, w = 65;
common_tools::fill(rgba);
common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.
bitmap), gray_ref.
bitmap, rgba.
getSize());
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGBa to Gray conversion, mean error: " << error << std::endl;
}
}
TEST_CASE("RGB to Gray conversion", "[image_conversion]") {
SECTION("Image 1x16 (SSE41 aligned=true)")
{
unsigned int h = 1, w = 16;
std::vector<unsigned char> rgb(h*w*3);
common_tools::fill(rgb);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 1, mean error: " << error << std::endl;
CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 2, mean error: " << error << std::endl;
}
SECTION("Image 1x17 (SSE41 aligned=false)")
{
unsigned int h = 1, w = 17;
std::vector<unsigned char> rgb(h*w*3);
common_tools::fill(rgb);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 1, mean error: " << error << std::endl;
CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 2, mean error: " << error << std::endl;
}
SECTION("Image 1x32 (AVX2 aligned=true)")
{
unsigned int h = 1, w = 32;
std::vector<unsigned char> rgb(h*w*3);
common_tools::fill(rgb);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 1, mean error: " << error << std::endl;
CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 2, mean error: " << error << std::endl;
}
SECTION("Image 1x33 (AVX2 aligned=false)")
{
unsigned int h = 1, w = 33;
std::vector<unsigned char> rgb(h*w*3);
common_tools::fill(rgb);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 1, mean error: " << error << std::endl;
CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 2, mean error: " << error << std::endl;
}
SECTION("Image 4x64 (general aligned = true")
{
unsigned int h = 4, w = 64;
std::vector<unsigned char> rgb(h*w*3);
common_tools::fill(rgb);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 1, mean error: " << error << std::endl;
CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 2, mean error: " << error << std::endl;
}
SECTION("Image 5x65 (general aligned = false")
{
unsigned int h = 5, w = 65;
std::vector<unsigned char> rgb(h*w*3);
common_tools::fill(rgb);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 1, mean error: " << error << std::endl;
CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
std::cout << "RGB to Gray conversion 2, mean error: " << error << std::endl;
}
}
TEST_CASE("RGB <==> RGBa conversion", "[image_conversion]") {
SECTION("Image 1x16 (SSE41 aligned=true)")
{
unsigned int h = 1, w = 16;
common_tools::fill(rgba_ref);
std::vector<unsigned char> rgb(h*w*3);
CHECK((rgba == rgba_ref));
}
SECTION("Image 1x17 (SSE41 aligned=false)")
{
unsigned int h = 1, w = 17;
common_tools::fill(rgba_ref);
std::vector<unsigned char> rgb(h*w*3);
CHECK((rgba == rgba_ref));
}
SECTION("Image 1x32 (AVX2 aligned=true)")
{
unsigned int h = 1, w = 32;
common_tools::fill(rgba_ref);
std::vector<unsigned char> rgb(h*w*3);
CHECK((rgba == rgba_ref));
}
SECTION("Image 1x33 (AVX2 aligned=false)")
{
unsigned int h = 1, w = 33;
common_tools::fill(rgba_ref);
std::vector<unsigned char> rgb(h*w*3);
CHECK((rgba == rgba_ref));
}
SECTION("Image 4x64 (general aligned = true")
{
unsigned int h = 4, w = 64;
common_tools::fill(rgba_ref);
std::vector<unsigned char> rgb(h*w*3);
CHECK((rgba == rgba_ref));
}
SECTION("Image 5x65 (general aligned = false")
{
unsigned int h = 5, w = 65;
common_tools::fill(rgba_ref);
std::vector<unsigned char> rgb(h*w*3);
CHECK((rgba == rgba_ref));
}
}
TEST_CASE("BGR to Gray conversion", "[image_conversion]") {
SECTION("Image 1x16 (SSE41 aligned=true)")
{
unsigned int h = 1, w = 16;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgr;
common_tools::RGBaToBGR(rgba_ref, bgr);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGR to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x17 (SSE41 aligned=false)")
{
unsigned int h = 1, w = 17;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgr;
common_tools::RGBaToBGR(rgba_ref, bgr);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGR to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x32 (AVX2 aligned=true)")
{
unsigned int h = 1, w = 32;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgr;
common_tools::RGBaToBGR(rgba_ref, bgr);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGR to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x33 (AVX2 aligned=false)")
{
unsigned int h = 1, w = 33;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgr;
common_tools::RGBaToBGR(rgba_ref, bgr);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGR to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 4x64 (general aligned = true")
{
unsigned int h = 4, w = 64;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgr;
common_tools::RGBaToBGR(rgba_ref, bgr);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGR to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 5x65 (general aligned = false")
{
unsigned int h = 5, w = 65;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgr;
common_tools::RGBaToBGR(rgba_ref, bgr);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGR to Gray conversion, mean error: " << error << std::endl;
}
}
TEST_CASE("BGRa to Gray conversion", "[image_conversion]") {
SECTION("Image 1x16 (SSE41 aligned=true)")
{
unsigned int h = 1, w = 16;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra;
common_tools::RGBaToBGRa(rgba_ref, bgra);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGRa to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x17 (SSE41 aligned=false)")
{
unsigned int h = 1, w = 17;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra;
common_tools::RGBaToBGRa(rgba_ref, bgra);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGRa to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x32 (AVX2 aligned=true)")
{
unsigned int h = 1, w = 32;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra;
common_tools::RGBaToBGRa(rgba_ref, bgra);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGRa to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x33 (AVX2 aligned=false)")
{
unsigned int h = 1, w = 33;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra;
common_tools::RGBaToBGRa(rgba_ref, bgra);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGRa to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 4x64 (general aligned = true")
{
unsigned int h = 4, w = 64;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra;
common_tools::RGBaToBGRa(rgba_ref, bgra);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGRa to Gray conversion, mean error: " << error << std::endl;
}
SECTION("Image 5x65 (general aligned = false")
{
unsigned int h = 5, w = 65;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra;
common_tools::RGBaToBGRa(rgba_ref, bgra);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGRa to Gray conversion, mean error: " << error << std::endl;
}
}
TEST_CASE("BGRa to RGBa conversion", "[image_conversion]") {
SECTION("Image 1x16 (SSE41 aligned=true)")
{
unsigned int h = 1, w = 16;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra_ref;
common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
double error = 0;
CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
std::cout << "BGRa to RGBa conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x17 (SSE41 aligned=false)")
{
unsigned int h = 1, w = 17;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra_ref;
common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
double error = 0;
CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
std::cout << "BGRa to RGBa conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x32 (AVX2 aligned=true)")
{
unsigned int h = 1, w = 32;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra_ref;
common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
double error = 0;
CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
std::cout << "BGRa to RGBa conversion, mean error: " << error << std::endl;
}
SECTION("Image 1x33 (AVX2 aligned=false)")
{
unsigned int h = 1, w = 33;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra_ref;
common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
double error = 0;
CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
std::cout << "BGRa to RGBa conversion, mean error: " << error << std::endl;
}
SECTION("Image 4x64 (general aligned = true")
{
unsigned int h = 4, w = 64;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra_ref;
common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
double error = 0;
CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
std::cout << "BGRa to RGBa conversion, mean error: " << error << std::endl;
}
SECTION("Image 5x65 (general aligned = false")
{
unsigned int h = 5, w = 65;
common_tools::fill(rgba_ref);
std::vector<unsigned char> bgra_ref;
common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
double error = 0;
CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
std::cout << "BGRa to RGBa conversion, mean error: " << error << std::endl;
}
}
TEST_CASE("Split <==> Merge conversion", "[image_conversion]") {
common_tools::fill(rgba_ref);
CHECK((rgba == rgba_ref));
}
#if VISP_HAVE_OPENCV_VERSION >= 0x020100
TEST_CASE("OpenCV Mat <==> vpImage conversion", "[image_conversion]") {
SECTION("CV_8UC3 to vpRGBa")
{
cv::Mat img(height, width, CV_8UC3);
common_tools::fill(img);
common_tools::BGRToRGBaRef(img.data, reinterpret_cast<unsigned char*>(rgba_ref.
bitmap), img.cols, img.rows,
false);
CHECK((rgba_ref == rgba));
}
SECTION("CV_8UC1 to vpRGBa")
{
cv::Mat img(height, width, CV_8UC1);
common_tools::fill(img);
common_tools::grayToRGBaRef(img.data, reinterpret_cast<unsigned char*>(rgba_ref.
bitmap), height*width);
CHECK((rgba_ref == rgba));
}
SECTION("CV_8UC3 to unsigned char")
{
cv::Mat img(height, width, CV_8UC3);
common_tools::fill(img);
common_tools::BGRToGrayRef(img.data, gray_ref.
bitmap, img.cols, img.rows,
false);
double error = 0;
CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
std::cout << "BGR to Gray conversion, mean error: " << error << std::endl;
}
SECTION("CV_8UC1 to unsigned char")
{
cv::Mat img(height, width, CV_8UC1);
common_tools::fill(img);
for (int i = 0; i < img.rows; i++) {
for (int j = 0; j < img.cols; j++) {
REQUIRE(img.at<uchar>(i, j) == gray[i][j]);
}
}
}
}
#endif
{
for (
unsigned int i = 0; i < I_Bayer_8U.
getHeight(); i++) {
for (
unsigned int j = 0; j < I_Bayer_8U.
getWidth(); j++) {
I_Bayer_8U[i][j] = buffer[j*I_Bayer_8U.
getHeight() + i];
}
}
}
{
for (
unsigned int i = 0; i < I_Bayer_16U.
getHeight(); i++) {
for (
unsigned int j = 0; j < I_Bayer_16U.
getWidth(); j++) {
I_Bayer_16U[i][j] = buffer[j*I_Bayer_16U.
getHeight() + i];
}
}
}
{
for (
unsigned int i = 0; i < I_RGBA_8U.
getHeight(); i++) {
for (
unsigned int j = 0; j < I_RGBA_8U.
getWidth(); j++) {
I_RGBA_8U[i][j] =
vpRGBa(vpMath::saturate<unsigned char>(I_RGBA_16U[0][(i*I_RGBA_8U.
getWidth() + j)*4 + 0] / (
float)divisor),
vpMath::saturate<unsigned char>(I_RGBA_16U[0][(i*I_RGBA_8U.
getWidth() + j)*4 + 1] / (
float)divisor),
vpMath::saturate<unsigned char>(I_RGBA_16U[0][(i*I_RGBA_8U.
getWidth() + j)*4 + 2] / (
float)divisor));
}
}
}
{
double mse = 0;
for (
unsigned int i = 0; i < I_RGBA_8U.
getHeight(); i++) {
for (
unsigned int j = 0; j < I_RGBA_8U.
getWidth(); j++) {
vpColVector err = I_RGBA_8U[i][j] - I_RGBA_8U_ref[i][j];
}
}
return 10*std::log10(255*255 / mse);
}
void readBinaryFile(const std::string& filename, std::vector<uint16_t>& buffer)
{
std::FILE* f = std::fopen(filename.c_str(), "rb");
size_t sread = std::fread(&buffer[0], sizeof buffer[0], buffer.size(), f);
REQUIRE(sread == buffer.size());
#ifdef VISP_BIG_ENDIAN
std::vector<uint16_t> tmp = buffer;
for (size_t i = 0; i < tmp.size(); i++) {
}
#endif
std::fclose(f);
}
TEST_CASE("Bayer conversion", "[image_conversion]") {
const double min_PSNR_bilinear = 21, min_PSNR_Malvar = 24;
SECTION("16-bit")
{
std::vector<uint16_t> buffer(height*width);
SECTION("BGGR")
{
readBinaryFile(filename, buffer);
col2im(buffer, I_Bayer_16U);
SECTION("Bilinear")
{
convertTo(I_RGBA_16U, I_RGBA_8U);
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "16-bit - BGGR - Bilinear - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_bilinear);
}
SECTION("Malvar")
{
convertTo(I_RGBA_16U, I_RGBA_8U);
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "16-bit - BGGR - Malvar - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_Malvar);
}
}
SECTION("GBRG")
{
readBinaryFile(filename, buffer);
col2im(buffer, I_Bayer_16U);
SECTION("Bilinear")
{
convertTo(I_RGBA_16U, I_RGBA_8U);
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "16-bit - GBRG - Bilinear - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_bilinear);
}
SECTION("Malvar")
{
convertTo(I_RGBA_16U, I_RGBA_8U);
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "16-bit - GBRG - Malvar - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_Malvar);
}
}
SECTION("GRBG")
{
readBinaryFile(filename, buffer);
col2im(buffer, I_Bayer_16U);
SECTION("Bilinear")
{
convertTo(I_RGBA_16U, I_RGBA_8U);
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "16-bit - GRBG - Bilinear - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_bilinear);
}
SECTION("Malvar")
{
convertTo(I_RGBA_16U, I_RGBA_8U);
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "16-bit - GRBG - Malvar - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_Malvar);
}
}
SECTION("RGGB")
{
readBinaryFile(filename, buffer);
col2im(buffer, I_Bayer_16U);
SECTION("Bilinear")
{
convertTo(I_RGBA_16U, I_RGBA_8U);
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "16-bit - RGGB - Bilinear - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_bilinear);
}
SECTION("Malvar")
{
convertTo(I_RGBA_16U, I_RGBA_8U);
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "16-bit - RGGB - Malvar - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_Malvar);
}
}
}
SECTION("8-bit")
{
std::vector<uint8_t> buffer(height*width);
SECTION("BGGR")
{
std::FILE* f = std::fopen(filename.c_str(), "rb");
size_t sread = std::fread(&buffer[0], sizeof buffer[0], buffer.size(), f);
REQUIRE(sread == buffer.size());
col2im(buffer, I_Bayer_8U);
SECTION("Bilinear")
{
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "8-bit - BGGR - Bilinear - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_bilinear);
}
SECTION("Malvar")
{
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "8-bit - BGGR - Malvar - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_Malvar);
}
std::fclose(f);
}
SECTION("GBRG")
{
std::FILE* f = std::fopen(filename.c_str(), "rb");
size_t sread = std::fread(&buffer[0], sizeof buffer[0], buffer.size(), f);
REQUIRE(sread == buffer.size());
col2im(buffer, I_Bayer_8U);
SECTION("Bilinear")
{
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "8-bit - GBRG - Bilinear - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_bilinear);
}
SECTION("Malvar")
{
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "8-bit - GBRG - Malvar - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_Malvar);
}
std::fclose(f);
}
SECTION("GRBG")
{
std::FILE* f = std::fopen(filename.c_str(), "rb");
size_t sread = std::fread(&buffer[0], sizeof buffer[0], buffer.size(), f);
REQUIRE(sread == buffer.size());
col2im(buffer, I_Bayer_8U);
SECTION("Bilinear")
{
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "8-bit - GRBG - Bilinear - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_bilinear);
}
SECTION("Malvar")
{
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "8-bit - GRBG - Malvar - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_Malvar);
}
std::fclose(f);
}
SECTION("RGGB")
{
std::FILE* f = std::fopen(filename.c_str(), "rb");
size_t sread = std::fread(&buffer[0], sizeof buffer[0], buffer.size(), f);
REQUIRE(sread == buffer.size());
col2im(buffer, I_Bayer_8U);
SECTION("Bilinear")
{
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "8-bit - RGGB - Bilinear - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_bilinear);
}
SECTION("Malvar")
{
double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
std::cout << "8-bit - RGGB - Malvar - PSNR: " << PSNR << std::endl;
CHECK(PSNR >= min_PSNR_Malvar);
}
std::fclose(f);
}
}
}
int main(int argc, char *argv[])
{
Catch::Session session;
session.applyCommandLine(argc, argv);
int numFailed = session.run();
return numFailed;
}
#else
int main()
{
return 0;
}
#endif