42#include <visp3/core/vpConfig.h>
44#if defined(VISP_HAVE_CATCH2)
45#define CATCH_CONFIG_RUNNER
48#include <visp3/core/vpImageConvert.h>
49#include <visp3/core/vpIoTools.h>
50#include <visp3/io/vpImageIo.h>
52static const double maxMeanPixelError = 1.5;
53static const unsigned int width = 223, height = 151;
55TEST_CASE(
"Gray to RGBa conversion",
"[image_conversion]")
57 SECTION(
"Image 1x16 (SSE41 aligned=true)")
59 unsigned int h = 1, w = 16;
61 common_tools::fill(gray);
64 common_tools::grayToRGBaRef(gray.bitmap,
reinterpret_cast<unsigned char *
>(rgba_ref.bitmap), gray.getSize());
68 CHECK((rgba == rgba_ref));
70 SECTION(
"Image 1x17 (SSE41 aligned=false)")
72 unsigned int h = 1, w = 17;
74 common_tools::fill(gray);
77 common_tools::grayToRGBaRef(gray.bitmap,
reinterpret_cast<unsigned char *
>(rgba_ref.bitmap), gray.getSize());
81 CHECK((rgba == rgba_ref));
83 SECTION(
"Image 1x32 (AVX2 aligned=true)")
85 unsigned int h = 1, w = 32;
87 common_tools::fill(gray);
90 common_tools::grayToRGBaRef(gray.bitmap,
reinterpret_cast<unsigned char *
>(rgba_ref.bitmap), gray.getSize());
94 CHECK((rgba == rgba_ref));
96 SECTION(
"Image 1x33 (AVX2 aligned=false)")
98 unsigned int h = 1, w = 33;
100 common_tools::fill(gray);
103 common_tools::grayToRGBaRef(gray.bitmap,
reinterpret_cast<unsigned char *
>(rgba_ref.bitmap), gray.getSize());
107 CHECK((rgba == rgba_ref));
109 SECTION(
"Image 4x64 (general aligned = true")
111 unsigned int h = 4, w = 64;
113 common_tools::fill(gray);
116 common_tools::grayToRGBaRef(gray.bitmap,
reinterpret_cast<unsigned char *
>(rgba_ref.bitmap), gray.getSize());
120 CHECK((rgba == rgba_ref));
122 SECTION(
"Image 5x65 (general aligned = false")
124 unsigned int h = 5, w = 65;
126 common_tools::fill(gray);
129 common_tools::grayToRGBaRef(gray.bitmap,
reinterpret_cast<unsigned char *
>(rgba_ref.bitmap), gray.getSize());
133 CHECK((rgba == rgba_ref));
137TEST_CASE(
"RGBa to Gray conversion",
"[image_conversion]")
139 SECTION(
"Image 1x16 (SSE41 aligned=true)")
141 unsigned int h = 1, w = 16;
143 common_tools::fill(rgba);
146 common_tools::RGBaToGrayRef(
reinterpret_cast<unsigned char *
>(rgba.
bitmap), gray_ref.bitmap, rgba.
getSize());
151 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
152 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
154 SECTION(
"Image 1x17 (SSE41 aligned=false)")
156 unsigned int h = 1, w = 17;
158 common_tools::fill(rgba);
161 common_tools::RGBaToGrayRef(
reinterpret_cast<unsigned char *
>(rgba.
bitmap), gray_ref.bitmap, rgba.
getSize());
166 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
167 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
169 SECTION(
"Image 1x32 (AVX2 aligned=true)")
171 unsigned int h = 1, w = 32;
173 common_tools::fill(rgba);
176 common_tools::RGBaToGrayRef(
reinterpret_cast<unsigned char *
>(rgba.
bitmap), gray_ref.bitmap, rgba.
getSize());
181 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
182 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
184 SECTION(
"Image 1x33 (AVX2 aligned=false)")
186 unsigned int h = 1, w = 33;
188 common_tools::fill(rgba);
191 common_tools::RGBaToGrayRef(
reinterpret_cast<unsigned char *
>(rgba.
bitmap), gray_ref.bitmap, rgba.
getSize());
196 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
197 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
199 SECTION(
"Image 4x64 (general aligned = true")
201 unsigned int h = 4, w = 64;
203 common_tools::fill(rgba);
206 common_tools::RGBaToGrayRef(
reinterpret_cast<unsigned char *
>(rgba.
bitmap), gray_ref.bitmap, rgba.
getSize());
211 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
212 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
214 SECTION(
"Image 5x65 (general aligned = false")
216 unsigned int h = 5, w = 65;
218 common_tools::fill(rgba);
221 common_tools::RGBaToGrayRef(
reinterpret_cast<unsigned char *
>(rgba.
bitmap), gray_ref.bitmap, rgba.
getSize());
226 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
227 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
231TEST_CASE(
"RGB to Gray conversion",
"[image_conversion]")
233 SECTION(
"Image 1x16 (SSE41 aligned=true)")
235 unsigned int h = 1, w = 16;
236 std::vector<unsigned char> rgb(h * w * 3);
237 common_tools::fill(rgb);
240 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
245 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
246 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
250 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
251 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
253 SECTION(
"Image 1x17 (SSE41 aligned=false)")
255 unsigned int h = 1, w = 17;
256 std::vector<unsigned char> rgb(h * w * 3);
257 common_tools::fill(rgb);
260 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
265 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
266 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
270 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
271 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
273 SECTION(
"Image 1x32 (AVX2 aligned=true)")
275 unsigned int h = 1, w = 32;
276 std::vector<unsigned char> rgb(h * w * 3);
277 common_tools::fill(rgb);
280 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
285 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
286 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
289 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
290 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
292 SECTION(
"Image 1x33 (AVX2 aligned=false)")
294 unsigned int h = 1, w = 33;
295 std::vector<unsigned char> rgb(h * w * 3);
296 common_tools::fill(rgb);
299 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
304 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
305 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
309 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
310 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
312 SECTION(
"Image 4x64 (general aligned = true")
314 unsigned int h = 4, w = 64;
315 std::vector<unsigned char> rgb(h * w * 3);
316 common_tools::fill(rgb);
319 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
324 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
325 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
329 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
330 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
332 SECTION(
"Image 5x65 (general aligned = false")
334 unsigned int h = 5, w = 65;
335 std::vector<unsigned char> rgb(h * w * 3);
336 common_tools::fill(rgb);
339 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
344 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
345 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
349 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
350 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
354TEST_CASE(
"RGB <==> RGBa conversion",
"[image_conversion]")
356 SECTION(
"Image 1x16 (SSE41 aligned=true)")
358 unsigned int h = 1, w = 16;
360 common_tools::fill(rgba_ref);
362 std::vector<unsigned char> rgb(h * w * 3);
368 CHECK((rgba == rgba_ref));
370 SECTION(
"Image 1x17 (SSE41 aligned=false)")
372 unsigned int h = 1, w = 17;
374 common_tools::fill(rgba_ref);
376 std::vector<unsigned char> rgb(h * w * 3);
382 CHECK((rgba == rgba_ref));
384 SECTION(
"Image 1x32 (AVX2 aligned=true)")
386 unsigned int h = 1, w = 32;
388 common_tools::fill(rgba_ref);
390 std::vector<unsigned char> rgb(h * w * 3);
396 CHECK((rgba == rgba_ref));
398 SECTION(
"Image 1x33 (AVX2 aligned=false)")
400 unsigned int h = 1, w = 33;
402 common_tools::fill(rgba_ref);
404 std::vector<unsigned char> rgb(h * w * 3);
410 CHECK((rgba == rgba_ref));
412 SECTION(
"Image 4x64 (general aligned = true")
414 unsigned int h = 4, w = 64;
416 common_tools::fill(rgba_ref);
418 std::vector<unsigned char> rgb(h * w * 3);
424 CHECK((rgba == rgba_ref));
426 SECTION(
"Image 5x65 (general aligned = false")
428 unsigned int h = 5, w = 65;
430 common_tools::fill(rgba_ref);
432 std::vector<unsigned char> rgb(h * w * 3);
438 CHECK((rgba == rgba_ref));
442TEST_CASE(
"BGR to Gray conversion",
"[image_conversion]")
444 SECTION(
"Image 1x16 (SSE41 aligned=true)")
446 unsigned int h = 1, w = 16;
448 common_tools::fill(rgba_ref);
453 std::vector<unsigned char> bgr;
454 common_tools::RGBaToBGR(rgba_ref, bgr);
460 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
461 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
463 SECTION(
"Image 1x17 (SSE41 aligned=false)")
465 unsigned int h = 1, w = 17;
467 common_tools::fill(rgba_ref);
472 std::vector<unsigned char> bgr;
473 common_tools::RGBaToBGR(rgba_ref, bgr);
479 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
480 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
482 SECTION(
"Image 1x32 (AVX2 aligned=true)")
484 unsigned int h = 1, w = 32;
486 common_tools::fill(rgba_ref);
491 std::vector<unsigned char> bgr;
492 common_tools::RGBaToBGR(rgba_ref, bgr);
498 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
499 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
501 SECTION(
"Image 1x33 (AVX2 aligned=false)")
503 unsigned int h = 1, w = 33;
505 common_tools::fill(rgba_ref);
510 std::vector<unsigned char> bgr;
511 common_tools::RGBaToBGR(rgba_ref, bgr);
517 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
518 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
520 SECTION(
"Image 4x64 (general aligned = true")
522 unsigned int h = 4, w = 64;
524 common_tools::fill(rgba_ref);
529 std::vector<unsigned char> bgr;
530 common_tools::RGBaToBGR(rgba_ref, bgr);
536 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
537 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
539 SECTION(
"Image 5x65 (general aligned = false")
541 unsigned int h = 5, w = 65;
543 common_tools::fill(rgba_ref);
548 std::vector<unsigned char> bgr;
549 common_tools::RGBaToBGR(rgba_ref, bgr);
555 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
556 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
560TEST_CASE(
"BGRa to Gray conversion",
"[image_conversion]")
562 SECTION(
"Image 1x16 (SSE41 aligned=true)")
564 unsigned int h = 1, w = 16;
566 common_tools::fill(rgba_ref);
571 std::vector<unsigned char> bgra;
572 common_tools::RGBaToBGRa(rgba_ref, bgra);
578 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
579 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
581 SECTION(
"Image 1x17 (SSE41 aligned=false)")
583 unsigned int h = 1, w = 17;
585 common_tools::fill(rgba_ref);
590 std::vector<unsigned char> bgra;
591 common_tools::RGBaToBGRa(rgba_ref, bgra);
597 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
598 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
600 SECTION(
"Image 1x32 (AVX2 aligned=true)")
602 unsigned int h = 1, w = 32;
604 common_tools::fill(rgba_ref);
609 std::vector<unsigned char> bgra;
610 common_tools::RGBaToBGRa(rgba_ref, bgra);
616 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
617 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
619 SECTION(
"Image 1x33 (AVX2 aligned=false)")
621 unsigned int h = 1, w = 33;
623 common_tools::fill(rgba_ref);
628 std::vector<unsigned char> bgra;
629 common_tools::RGBaToBGRa(rgba_ref, bgra);
635 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
636 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
638 SECTION(
"Image 4x64 (general aligned = true")
640 unsigned int h = 4, w = 64;
642 common_tools::fill(rgba_ref);
647 std::vector<unsigned char> bgra;
648 common_tools::RGBaToBGRa(rgba_ref, bgra);
654 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
655 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
657 SECTION(
"Image 5x65 (general aligned = false")
659 unsigned int h = 5, w = 65;
661 common_tools::fill(rgba_ref);
666 std::vector<unsigned char> bgra;
667 common_tools::RGBaToBGRa(rgba_ref, bgra);
673 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
674 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
678TEST_CASE(
"BGRa to RGBa conversion",
"[image_conversion]")
680 SECTION(
"Image 1x16 (SSE41 aligned=true)")
682 unsigned int h = 1, w = 16;
684 common_tools::fill(rgba_ref);
686 std::vector<unsigned char> bgra_ref;
687 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
693 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
694 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
696 SECTION(
"Image 1x17 (SSE41 aligned=false)")
698 unsigned int h = 1, w = 17;
700 common_tools::fill(rgba_ref);
702 std::vector<unsigned char> bgra_ref;
703 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
709 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
710 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
712 SECTION(
"Image 1x32 (AVX2 aligned=true)")
714 unsigned int h = 1, w = 32;
716 common_tools::fill(rgba_ref);
718 std::vector<unsigned char> bgra_ref;
719 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
725 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
726 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
728 SECTION(
"Image 1x33 (AVX2 aligned=false)")
730 unsigned int h = 1, w = 33;
732 common_tools::fill(rgba_ref);
734 std::vector<unsigned char> bgra_ref;
735 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
741 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
742 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
744 SECTION(
"Image 4x64 (general aligned = true")
746 unsigned int h = 4, w = 64;
748 common_tools::fill(rgba_ref);
750 std::vector<unsigned char> bgra_ref;
751 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
757 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
758 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
760 SECTION(
"Image 5x65 (general aligned = false")
762 unsigned int h = 5, w = 65;
764 common_tools::fill(rgba_ref);
766 std::vector<unsigned char> bgra_ref;
767 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
773 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
774 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
778TEST_CASE(
"Split <==> Merge conversion",
"[image_conversion]")
781 common_tools::fill(rgba_ref);
789 CHECK((rgba == rgba_ref));
792#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC)
793TEST_CASE(
"OpenCV Mat <==> vpImage conversion",
"[image_conversion]")
795 SECTION(
"CV_8UC3 to vpRGBa")
797 cv::Mat img(height, width, CV_8UC3);
798 common_tools::fill(img);
801 common_tools::BGRToRGBaRef(img.data,
reinterpret_cast<unsigned char *
>(rgba_ref.bitmap), img.cols, img.rows,
false);
805 CHECK((rgba_ref == rgba));
808 SECTION(
"CV_8UC1 to vpRGBa")
810 cv::Mat img(height, width, CV_8UC1);
811 common_tools::fill(img);
814 common_tools::grayToRGBaRef(img.data,
reinterpret_cast<unsigned char *
>(rgba_ref.bitmap), height * width);
818 CHECK((rgba_ref == rgba));
821 SECTION(
"CV_8UC3 to unsigned char")
823 cv::Mat img(height, width, CV_8UC3);
824 common_tools::fill(img);
827 common_tools::BGRToGrayRef(img.data, gray_ref.
bitmap, img.cols, img.rows,
false);
832 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
833 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
836 SECTION(
"CV_8UC1 to unsigned char")
838 cv::Mat img(height, width, CV_8UC1);
839 common_tools::fill(img);
847 for (
int i = 0; i < img.rows; i++) {
848 for (
int j = 0; j < img.cols; j++) {
849 REQUIRE(img.at<uchar>(i, j) == gray[i][j]);
854 SECTION(
"CV_16UC1 to uint16_t")
857 unsigned int w = 3, h = 3;
858 cv::Mat img = (cv::Mat_<uint16_t>(h, w) << 65, 650, 6500, 65000, 60000, 6000, 600, 60, 6);
865 for (
int i = 0; i < img.rows; i++) {
866 for (
int j = 0; j < img.cols; j++) {
867 REQUIRE(img.at<uint16_t>(i, j) == gray16[i][j]);
872 cv::Mat img_col1 = img.col(1);
877 REQUIRE(gray16_col1.
getWidth() == 1);
879 for (
int i = 0; i < img_col1.rows; i++) {
880 for (
int j = 0; j < img_col1.cols; j++) {
881 REQUIRE(img_col1.at<uint16_t>(i, j) == gray16_col1[i][j]);
888void col2im(
const std::vector<uint8_t> &buffer,
vpImage<uint8_t> &I_Bayer_8U)
890 for (
unsigned int i = 0; i < I_Bayer_8U.
getHeight(); i++) {
891 for (
unsigned int j = 0; j < I_Bayer_8U.
getWidth(); j++) {
892 I_Bayer_8U[i][j] = buffer[j * I_Bayer_8U.
getHeight() + i];
899 for (
unsigned int i = 0; i < I_Bayer_16U.
getHeight(); i++) {
900 for (
unsigned int j = 0; j < I_Bayer_16U.
getWidth(); j++) {
901 I_Bayer_16U[i][j] = buffer[j * I_Bayer_16U.
getHeight() + i];
908 for (
unsigned int i = 0; i < I_RGBA_8U.
getHeight(); i++) {
909 for (
unsigned int j = 0; j < I_RGBA_8U.
getWidth(); j++) {
921 for (
unsigned int i = 0; i < I_RGBA_8U.
getHeight(); i++) {
922 for (
unsigned int j = 0; j < I_RGBA_8U.
getWidth(); j++) {
923 vpColVector err = I_RGBA_8U[i][j] - I_RGBA_8U_ref[i][j];
929 return 10 * std::log10(255 * 255 / mse);
932void readBinaryFile(
const std::string &filename, std::vector<uint16_t> &buffer)
934 std::FILE *f = std::fopen(filename.c_str(),
"rb");
935 size_t sread = std::fread(&buffer[0],
sizeof buffer[0], buffer.size(), f);
936 REQUIRE(sread == buffer.size());
938#ifdef VISP_BIG_ENDIAN
939 std::vector<uint16_t> tmp = buffer;
940 for (
size_t i = 0; i < tmp.size(); i++) {
947#if (VISP_HAVE_DATASET_VERSION >= 0x030500)
948TEST_CASE(
"Bayer conversion",
"[image_conversion]")
956 const double min_PSNR_bilinear = 21, min_PSNR_Malvar = 24;
960 std::vector<uint16_t> buffer(height * width);
966 const std::string filename =
968 readBinaryFile(filename, buffer);
970 col2im(buffer, I_Bayer_16U);
977 convertTo(I_RGBA_16U, I_RGBA_8U);
978 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
979 std::cout <<
"16-bit - BGGR - Bilinear - PSNR: " << PSNR << std::endl;
980 CHECK(PSNR >= min_PSNR_bilinear);
988 convertTo(I_RGBA_16U, I_RGBA_8U);
989 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
990 std::cout <<
"16-bit - BGGR - Malvar - PSNR: " << PSNR << std::endl;
991 CHECK(PSNR >= min_PSNR_Malvar);
997 const std::string filename =
999 readBinaryFile(filename, buffer);
1001 col2im(buffer, I_Bayer_16U);
1008 convertTo(I_RGBA_16U, I_RGBA_8U);
1009 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1010 std::cout <<
"16-bit - GBRG - Bilinear - PSNR: " << PSNR << std::endl;
1011 CHECK(PSNR >= min_PSNR_bilinear);
1019 convertTo(I_RGBA_16U, I_RGBA_8U);
1020 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1021 std::cout <<
"16-bit - GBRG - Malvar - PSNR: " << PSNR << std::endl;
1022 CHECK(PSNR >= min_PSNR_Malvar);
1028 const std::string filename =
1030 readBinaryFile(filename, buffer);
1032 col2im(buffer, I_Bayer_16U);
1039 convertTo(I_RGBA_16U, I_RGBA_8U);
1040 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1041 std::cout <<
"16-bit - GRBG - Bilinear - PSNR: " << PSNR << std::endl;
1042 CHECK(PSNR >= min_PSNR_bilinear);
1050 convertTo(I_RGBA_16U, I_RGBA_8U);
1051 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1052 std::cout <<
"16-bit - GRBG - Malvar - PSNR: " << PSNR << std::endl;
1053 CHECK(PSNR >= min_PSNR_Malvar);
1059 const std::string filename =
1061 readBinaryFile(filename, buffer);
1063 col2im(buffer, I_Bayer_16U);
1070 convertTo(I_RGBA_16U, I_RGBA_8U);
1071 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1072 std::cout <<
"16-bit - RGGB - Bilinear - PSNR: " << PSNR << std::endl;
1073 CHECK(PSNR >= min_PSNR_bilinear);
1081 convertTo(I_RGBA_16U, I_RGBA_8U);
1082 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1083 std::cout <<
"16-bit - RGGB - Malvar - PSNR: " << PSNR << std::endl;
1084 CHECK(PSNR >= min_PSNR_Malvar);
1091 std::vector<uint8_t> buffer(height * width);
1097 const std::string filename =
1100 std::FILE *f = std::fopen(filename.c_str(),
"rb");
1101 size_t sread = std::fread(&buffer[0],
sizeof buffer[0], buffer.size(), f);
1102 REQUIRE(sread == buffer.size());
1104 col2im(buffer, I_Bayer_8U);
1111 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1112 std::cout <<
"8-bit - BGGR - Bilinear - PSNR: " << PSNR << std::endl;
1113 CHECK(PSNR >= min_PSNR_bilinear);
1121 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1122 std::cout <<
"8-bit - BGGR - Malvar - PSNR: " << PSNR << std::endl;
1123 CHECK(PSNR >= min_PSNR_Malvar);
1130 const std::string filename =
1133 std::FILE *f = std::fopen(filename.c_str(),
"rb");
1134 size_t sread = std::fread(&buffer[0],
sizeof buffer[0], buffer.size(), f);
1135 REQUIRE(sread == buffer.size());
1137 col2im(buffer, I_Bayer_8U);
1144 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1145 std::cout <<
"8-bit - GBRG - Bilinear - PSNR: " << PSNR << std::endl;
1146 CHECK(PSNR >= min_PSNR_bilinear);
1154 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1155 std::cout <<
"8-bit - GBRG - Malvar - PSNR: " << PSNR << std::endl;
1156 CHECK(PSNR >= min_PSNR_Malvar);
1163 const std::string filename =
1166 std::FILE *f = std::fopen(filename.c_str(),
"rb");
1167 size_t sread = std::fread(&buffer[0],
sizeof buffer[0], buffer.size(), f);
1168 REQUIRE(sread == buffer.size());
1170 col2im(buffer, I_Bayer_8U);
1177 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1178 std::cout <<
"8-bit - GRBG - Bilinear - PSNR: " << PSNR << std::endl;
1179 CHECK(PSNR >= min_PSNR_bilinear);
1187 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1188 std::cout <<
"8-bit - GRBG - Malvar - PSNR: " << PSNR << std::endl;
1189 CHECK(PSNR >= min_PSNR_Malvar);
1196 const std::string filename =
1199 std::FILE *f = std::fopen(filename.c_str(),
"rb");
1200 size_t sread = std::fread(&buffer[0],
sizeof buffer[0], buffer.size(), f);
1201 REQUIRE(sread == buffer.size());
1203 col2im(buffer, I_Bayer_8U);
1210 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1211 std::cout <<
"8-bit - RGGB - Bilinear - PSNR: " << PSNR << std::endl;
1212 CHECK(PSNR >= min_PSNR_bilinear);
1220 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1221 std::cout <<
"8-bit - RGGB - Malvar - PSNR: " << PSNR << std::endl;
1222 CHECK(PSNR >= min_PSNR_Malvar);
1231int main(
int argc,
char *argv[])
1233 Catch::Session session;
1236 session.applyCommandLine(argc, argv);
1238 int numFailed = session.run();
1246int main() {
return EXIT_SUCCESS; }
Implementation of column vector and the associated operations.
static void demosaicBGGRToRGBaBilinear(const uint8_t *bggr, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void demosaicGRBGToRGBaBilinear(const uint8_t *grbg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void split(const vpImage< vpRGBa > &src, vpImage< unsigned char > *pR, vpImage< unsigned char > *pG, vpImage< unsigned char > *pB, vpImage< unsigned char > *pa=NULL)
static void demosaicGRBGToRGBaMalvar(const uint8_t *grbg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void demosaicGBRGToRGBaMalvar(const uint8_t *gbrg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void merge(const vpImage< unsigned char > *R, const vpImage< unsigned char > *G, const vpImage< unsigned char > *B, const vpImage< unsigned char > *a, vpImage< vpRGBa > &RGBa)
static void demosaicBGGRToRGBaMalvar(const uint8_t *bggr, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void demosaicGBRGToRGBaBilinear(const uint8_t *gbrg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void demosaicRGGBToRGBaMalvar(const uint8_t *rggb, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void RGBToGrey(unsigned char *rgb, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false)
static void RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
static void BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
static void demosaicRGGBToRGBaBilinear(const uint8_t *rggb, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void BGRaToRGBa(unsigned char *bgra, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
static void RGBaToRGB(unsigned char *rgba, unsigned char *rgb, unsigned int size)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
unsigned int getWidth() const
unsigned int getSize() const
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
static double sqr(double x)
static _Tp saturate(unsigned char v)
VISP_EXPORT uint16_t swap16bits(uint16_t val)