42 #include <visp3/core/vpConfig.h> 44 #if defined(VISP_HAVE_CATCH2) 45 #define CATCH_CONFIG_RUNNER 47 #include <visp3/core/vpImageConvert.h> 48 #include <visp3/core/vpIoTools.h> 49 #include <visp3/io/vpImageIo.h> 52 static const double maxMeanPixelError = 1.5;
53 static const unsigned int width = 223, height = 151;
55 TEST_CASE(
"Gray to RGBa conversion",
"[image_conversion]") {
56 SECTION(
"Image 1x16 (SSE41 aligned=true)")
58 unsigned int h = 1, w = 16;
60 common_tools::fill(gray);
63 common_tools::grayToRGBaRef(gray.bitmap, reinterpret_cast<unsigned char*>(rgba_ref.bitmap), gray.getSize());
67 CHECK((rgba == rgba_ref));
69 SECTION(
"Image 1x17 (SSE41 aligned=false)")
71 unsigned int h = 1, w = 17;
73 common_tools::fill(gray);
76 common_tools::grayToRGBaRef(gray.bitmap, reinterpret_cast<unsigned char*>(rgba_ref.bitmap), gray.getSize());
80 CHECK((rgba == rgba_ref));
82 SECTION(
"Image 1x32 (AVX2 aligned=true)")
84 unsigned int h = 1, w = 32;
86 common_tools::fill(gray);
89 common_tools::grayToRGBaRef(gray.bitmap, reinterpret_cast<unsigned char*>(rgba_ref.bitmap), gray.getSize());
93 CHECK((rgba == rgba_ref));
95 SECTION(
"Image 1x33 (AVX2 aligned=false)")
97 unsigned int h = 1, w = 33;
99 common_tools::fill(gray);
102 common_tools::grayToRGBaRef(gray.bitmap, reinterpret_cast<unsigned char*>(rgba_ref.bitmap), gray.getSize());
106 CHECK((rgba == rgba_ref));
108 SECTION(
"Image 4x64 (general aligned = true")
110 unsigned int h = 4, w = 64;
112 common_tools::fill(gray);
115 common_tools::grayToRGBaRef(gray.bitmap, reinterpret_cast<unsigned char*>(rgba_ref.bitmap), gray.getSize());
119 CHECK((rgba == rgba_ref));
121 SECTION(
"Image 5x65 (general aligned = false")
123 unsigned int h = 5, w = 65;
125 common_tools::fill(gray);
128 common_tools::grayToRGBaRef(gray.bitmap, reinterpret_cast<unsigned char*>(rgba_ref.bitmap), gray.getSize());
132 CHECK((rgba == rgba_ref));
136 TEST_CASE(
"RGBa to Gray conversion",
"[image_conversion]") {
137 SECTION(
"Image 1x16 (SSE41 aligned=true)")
139 unsigned int h = 1, w = 16;
141 common_tools::fill(rgba);
144 common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.bitmap), gray_ref.bitmap, rgba.getSize());
149 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
150 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
152 SECTION(
"Image 1x17 (SSE41 aligned=false)")
154 unsigned int h = 1, w = 17;
156 common_tools::fill(rgba);
159 common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.bitmap), gray_ref.bitmap, rgba.getSize());
164 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
165 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
167 SECTION(
"Image 1x32 (AVX2 aligned=true)")
169 unsigned int h = 1, w = 32;
171 common_tools::fill(rgba);
174 common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.bitmap), gray_ref.bitmap, rgba.getSize());
179 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
180 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
182 SECTION(
"Image 1x33 (AVX2 aligned=false)")
184 unsigned int h = 1, w = 33;
186 common_tools::fill(rgba);
189 common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.bitmap), gray_ref.bitmap, rgba.getSize());
194 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
195 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
197 SECTION(
"Image 4x64 (general aligned = true")
199 unsigned int h = 4, w = 64;
201 common_tools::fill(rgba);
204 common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.bitmap), gray_ref.bitmap, rgba.getSize());
209 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
210 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
212 SECTION(
"Image 5x65 (general aligned = false")
214 unsigned int h = 5, w = 65;
216 common_tools::fill(rgba);
219 common_tools::RGBaToGrayRef(reinterpret_cast<unsigned char*>(rgba.bitmap), gray_ref.bitmap, rgba.getSize());
224 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
225 std::cout <<
"RGBa to Gray conversion, mean error: " << error << std::endl;
229 TEST_CASE(
"RGB to Gray conversion",
"[image_conversion]") {
230 SECTION(
"Image 1x16 (SSE41 aligned=true)")
232 unsigned int h = 1, w = 16;
233 std::vector<unsigned char> rgb(h*w*3);
234 common_tools::fill(rgb);
237 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
242 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
243 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
247 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
248 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
250 SECTION(
"Image 1x17 (SSE41 aligned=false)")
252 unsigned int h = 1, w = 17;
253 std::vector<unsigned char> rgb(h*w*3);
254 common_tools::fill(rgb);
257 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
262 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
263 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
267 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
268 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
270 SECTION(
"Image 1x32 (AVX2 aligned=true)")
272 unsigned int h = 1, w = 32;
273 std::vector<unsigned char> rgb(h*w*3);
274 common_tools::fill(rgb);
277 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
282 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
283 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
286 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
287 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
289 SECTION(
"Image 1x33 (AVX2 aligned=false)")
291 unsigned int h = 1, w = 33;
292 std::vector<unsigned char> rgb(h*w*3);
293 common_tools::fill(rgb);
296 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
301 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
302 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
306 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
307 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
309 SECTION(
"Image 4x64 (general aligned = true")
311 unsigned int h = 4, w = 64;
312 std::vector<unsigned char> rgb(h*w*3);
313 common_tools::fill(rgb);
316 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
321 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
322 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
326 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
327 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
329 SECTION(
"Image 5x65 (general aligned = false")
331 unsigned int h = 5, w = 65;
332 std::vector<unsigned char> rgb(h*w*3);
333 common_tools::fill(rgb);
336 common_tools::RGBToGrayRef(rgb.data(), gray_ref.bitmap, gray_ref.getWidth(), gray_ref.getHeight(),
false);
341 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
342 std::cout <<
"RGB to Gray conversion 1, mean error: " << error << std::endl;
346 CHECK(common_tools::almostEqual(gray_ref, gray2, maxMeanPixelError, error));
347 std::cout <<
"RGB to Gray conversion 2, mean error: " << error << std::endl;
351 TEST_CASE(
"RGB <==> RGBa conversion",
"[image_conversion]") {
352 SECTION(
"Image 1x16 (SSE41 aligned=true)")
354 unsigned int h = 1, w = 16;
356 common_tools::fill(rgba_ref);
358 std::vector<unsigned char> rgb(h*w*3);
364 CHECK((rgba == rgba_ref));
366 SECTION(
"Image 1x17 (SSE41 aligned=false)")
368 unsigned int h = 1, w = 17;
370 common_tools::fill(rgba_ref);
372 std::vector<unsigned char> rgb(h*w*3);
378 CHECK((rgba == rgba_ref));
380 SECTION(
"Image 1x32 (AVX2 aligned=true)")
382 unsigned int h = 1, w = 32;
384 common_tools::fill(rgba_ref);
386 std::vector<unsigned char> rgb(h*w*3);
392 CHECK((rgba == rgba_ref));
394 SECTION(
"Image 1x33 (AVX2 aligned=false)")
396 unsigned int h = 1, w = 33;
398 common_tools::fill(rgba_ref);
400 std::vector<unsigned char> rgb(h*w*3);
406 CHECK((rgba == rgba_ref));
408 SECTION(
"Image 4x64 (general aligned = true")
410 unsigned int h = 4, w = 64;
412 common_tools::fill(rgba_ref);
414 std::vector<unsigned char> rgb(h*w*3);
420 CHECK((rgba == rgba_ref));
422 SECTION(
"Image 5x65 (general aligned = false")
424 unsigned int h = 5, w = 65;
426 common_tools::fill(rgba_ref);
428 std::vector<unsigned char> rgb(h*w*3);
434 CHECK((rgba == rgba_ref));
438 TEST_CASE(
"BGR to Gray conversion",
"[image_conversion]") {
439 SECTION(
"Image 1x16 (SSE41 aligned=true)")
441 unsigned int h = 1, w = 16;
443 common_tools::fill(rgba_ref);
448 std::vector<unsigned char> bgr;
449 common_tools::RGBaToBGR(rgba_ref, bgr);
455 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
456 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
458 SECTION(
"Image 1x17 (SSE41 aligned=false)")
460 unsigned int h = 1, w = 17;
462 common_tools::fill(rgba_ref);
467 std::vector<unsigned char> bgr;
468 common_tools::RGBaToBGR(rgba_ref, bgr);
474 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
475 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
477 SECTION(
"Image 1x32 (AVX2 aligned=true)")
479 unsigned int h = 1, w = 32;
481 common_tools::fill(rgba_ref);
486 std::vector<unsigned char> bgr;
487 common_tools::RGBaToBGR(rgba_ref, bgr);
493 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
494 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
496 SECTION(
"Image 1x33 (AVX2 aligned=false)")
498 unsigned int h = 1, w = 33;
500 common_tools::fill(rgba_ref);
505 std::vector<unsigned char> bgr;
506 common_tools::RGBaToBGR(rgba_ref, bgr);
512 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
513 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
515 SECTION(
"Image 4x64 (general aligned = true")
517 unsigned int h = 4, w = 64;
519 common_tools::fill(rgba_ref);
524 std::vector<unsigned char> bgr;
525 common_tools::RGBaToBGR(rgba_ref, bgr);
531 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
532 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
534 SECTION(
"Image 5x65 (general aligned = false")
536 unsigned int h = 5, w = 65;
538 common_tools::fill(rgba_ref);
543 std::vector<unsigned char> bgr;
544 common_tools::RGBaToBGR(rgba_ref, bgr);
550 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
551 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
555 TEST_CASE(
"BGRa to Gray conversion",
"[image_conversion]") {
556 SECTION(
"Image 1x16 (SSE41 aligned=true)")
558 unsigned int h = 1, w = 16;
560 common_tools::fill(rgba_ref);
565 std::vector<unsigned char> bgra;
566 common_tools::RGBaToBGRa(rgba_ref, bgra);
572 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
573 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
575 SECTION(
"Image 1x17 (SSE41 aligned=false)")
577 unsigned int h = 1, w = 17;
579 common_tools::fill(rgba_ref);
584 std::vector<unsigned char> bgra;
585 common_tools::RGBaToBGRa(rgba_ref, bgra);
591 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
592 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
594 SECTION(
"Image 1x32 (AVX2 aligned=true)")
596 unsigned int h = 1, w = 32;
598 common_tools::fill(rgba_ref);
603 std::vector<unsigned char> bgra;
604 common_tools::RGBaToBGRa(rgba_ref, bgra);
610 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
611 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
613 SECTION(
"Image 1x33 (AVX2 aligned=false)")
615 unsigned int h = 1, w = 33;
617 common_tools::fill(rgba_ref);
622 std::vector<unsigned char> bgra;
623 common_tools::RGBaToBGRa(rgba_ref, bgra);
629 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
630 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
632 SECTION(
"Image 4x64 (general aligned = true")
634 unsigned int h = 4, w = 64;
636 common_tools::fill(rgba_ref);
641 std::vector<unsigned char> bgra;
642 common_tools::RGBaToBGRa(rgba_ref, bgra);
648 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
649 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
651 SECTION(
"Image 5x65 (general aligned = false")
653 unsigned int h = 5, w = 65;
655 common_tools::fill(rgba_ref);
660 std::vector<unsigned char> bgra;
661 common_tools::RGBaToBGRa(rgba_ref, bgra);
667 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
668 std::cout <<
"BGRa to Gray conversion, mean error: " << error << std::endl;
672 TEST_CASE(
"BGRa to RGBa conversion",
"[image_conversion]") {
673 SECTION(
"Image 1x16 (SSE41 aligned=true)")
675 unsigned int h = 1, w = 16;
677 common_tools::fill(rgba_ref);
679 std::vector<unsigned char> bgra_ref;
680 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
683 vpImageConvert::BGRaToRGBa(bgra_ref.data(),
reinterpret_cast<unsigned char*
>(rgba.bitmap), rgba.getWidth(), rgba.getHeight());
685 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
686 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
688 SECTION(
"Image 1x17 (SSE41 aligned=false)")
690 unsigned int h = 1, w = 17;
692 common_tools::fill(rgba_ref);
694 std::vector<unsigned char> bgra_ref;
695 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
698 vpImageConvert::BGRaToRGBa(bgra_ref.data(),
reinterpret_cast<unsigned char*
>(rgba.bitmap), rgba.getWidth(), rgba.getHeight());
700 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
701 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
703 SECTION(
"Image 1x32 (AVX2 aligned=true)")
705 unsigned int h = 1, w = 32;
707 common_tools::fill(rgba_ref);
709 std::vector<unsigned char> bgra_ref;
710 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
713 vpImageConvert::BGRaToRGBa(bgra_ref.data(),
reinterpret_cast<unsigned char*
>(rgba.bitmap), rgba.getWidth(), rgba.getHeight());
715 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
716 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
718 SECTION(
"Image 1x33 (AVX2 aligned=false)")
720 unsigned int h = 1, w = 33;
722 common_tools::fill(rgba_ref);
724 std::vector<unsigned char> bgra_ref;
725 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
728 vpImageConvert::BGRaToRGBa(bgra_ref.data(),
reinterpret_cast<unsigned char*
>(rgba.bitmap), rgba.getWidth(), rgba.getHeight());
730 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
731 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
733 SECTION(
"Image 4x64 (general aligned = true")
735 unsigned int h = 4, w = 64;
737 common_tools::fill(rgba_ref);
739 std::vector<unsigned char> bgra_ref;
740 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
743 vpImageConvert::BGRaToRGBa(bgra_ref.data(),
reinterpret_cast<unsigned char*
>(rgba.bitmap), rgba.getWidth(), rgba.getHeight());
745 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
746 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
748 SECTION(
"Image 5x65 (general aligned = false")
750 unsigned int h = 5, w = 65;
752 common_tools::fill(rgba_ref);
754 std::vector<unsigned char> bgra_ref;
755 common_tools::RGBaToBGRa(rgba_ref, bgra_ref);
758 vpImageConvert::BGRaToRGBa(bgra_ref.data(),
reinterpret_cast<unsigned char*
>(rgba.bitmap), rgba.getWidth(), rgba.getHeight());
760 CHECK(common_tools::almostEqual(rgba_ref, rgba, maxMeanPixelError, error));
761 std::cout <<
"BGRa to RGBa conversion, mean error: " << error << std::endl;
765 TEST_CASE(
"Split <==> Merge conversion",
"[image_conversion]") {
767 common_tools::fill(rgba_ref);
775 CHECK((rgba == rgba_ref));
778 #if VISP_HAVE_OPENCV_VERSION >= 0x020100 779 TEST_CASE(
"OpenCV Mat <==> vpImage conversion",
"[image_conversion]") {
780 SECTION(
"CV_8UC3 to vpRGBa")
782 cv::Mat img(height, width, CV_8UC3);
783 common_tools::fill(img);
786 common_tools::BGRToRGBaRef(img.data, reinterpret_cast<unsigned char*>(rgba_ref.bitmap), img.cols, img.rows,
false);
790 CHECK((rgba_ref == rgba));
793 SECTION(
"CV_8UC1 to vpRGBa")
795 cv::Mat img(height, width, CV_8UC1);
796 common_tools::fill(img);
799 common_tools::grayToRGBaRef(img.data, reinterpret_cast<unsigned char*>(rgba_ref.bitmap), height*width);
803 CHECK((rgba_ref == rgba));
806 SECTION(
"CV_8UC3 to unsigned char")
808 cv::Mat img(height, width, CV_8UC3);
809 common_tools::fill(img);
812 common_tools::BGRToGrayRef(img.data, gray_ref.
bitmap, img.cols, img.rows,
false);
817 CHECK(common_tools::almostEqual(gray_ref, gray, maxMeanPixelError, error));
818 std::cout <<
"BGR to Gray conversion, mean error: " << error << std::endl;
821 SECTION(
"CV_8UC1 to unsigned char")
823 cv::Mat img(height, width, CV_8UC1);
824 common_tools::fill(img);
832 for (
int i = 0; i < img.rows; i++) {
833 for (
int j = 0; j < img.cols; j++) {
834 REQUIRE(img.at<uchar>(i, j) == gray[i][j]);
841 void col2im(
const std::vector<uint8_t>& buffer,
vpImage<uint8_t>& I_Bayer_8U)
843 for (
unsigned int i = 0; i < I_Bayer_8U.
getHeight(); i++) {
844 for (
unsigned int j = 0; j < I_Bayer_8U.
getWidth(); j++) {
845 I_Bayer_8U[i][j] = buffer[j*I_Bayer_8U.
getHeight() + i];
852 for (
unsigned int i = 0; i < I_Bayer_16U.
getHeight(); i++) {
853 for (
unsigned int j = 0; j < I_Bayer_16U.
getWidth(); j++) {
854 I_Bayer_16U[i][j] = buffer[j*I_Bayer_16U.
getHeight() + i];
861 for (
unsigned int i = 0; i < I_RGBA_8U.
getHeight(); i++) {
862 for (
unsigned int j = 0; j < I_RGBA_8U.
getWidth(); j++) {
863 I_RGBA_8U[i][j] =
vpRGBa(vpMath::saturate<unsigned char>(I_RGBA_16U[0][(i*I_RGBA_8U.
getWidth() + j)*4 + 0] / (
float)divisor),
864 vpMath::saturate<unsigned char>(I_RGBA_16U[0][(i*I_RGBA_8U.
getWidth() + j)*4 + 1] / (
float)divisor),
865 vpMath::saturate<unsigned char>(I_RGBA_16U[0][(i*I_RGBA_8U.
getWidth() + j)*4 + 2] / (
float)divisor));
873 for (
unsigned int i = 0; i < I_RGBA_8U.
getHeight(); i++) {
874 for (
unsigned int j = 0; j < I_RGBA_8U.
getWidth(); j++) {
875 vpColVector err = I_RGBA_8U[i][j] - I_RGBA_8U_ref[i][j];
881 return 10*std::log10(255*255 / mse);
884 void readBinaryFile(
const std::string& filename, std::vector<uint16_t>& buffer)
886 std::FILE* f = std::fopen(filename.c_str(),
"rb");
887 size_t sread = std::fread(&buffer[0],
sizeof buffer[0], buffer.size(), f);
888 REQUIRE(sread == buffer.size());
890 #ifdef VISP_BIG_ENDIAN 891 std::vector<uint16_t> tmp = buffer;
892 for (
size_t i = 0; i < tmp.size(); i++) {
899 TEST_CASE(
"Bayer conversion",
"[image_conversion]") {
906 const double min_PSNR_bilinear = 21, min_PSNR_Malvar = 24;
910 std::vector<uint16_t> buffer(height*width);
917 readBinaryFile(filename, buffer);
919 col2im(buffer, I_Bayer_16U);
925 convertTo(I_RGBA_16U, I_RGBA_8U);
926 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
927 std::cout <<
"16-bit - BGGR - Bilinear - PSNR: " << PSNR << std::endl;
928 CHECK(PSNR >= min_PSNR_bilinear);
935 convertTo(I_RGBA_16U, I_RGBA_8U);
936 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
937 std::cout <<
"16-bit - BGGR - Malvar - PSNR: " << PSNR << std::endl;
938 CHECK(PSNR >= min_PSNR_Malvar);
945 readBinaryFile(filename, buffer);
947 col2im(buffer, I_Bayer_16U);
953 convertTo(I_RGBA_16U, I_RGBA_8U);
954 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
955 std::cout <<
"16-bit - GBRG - Bilinear - PSNR: " << PSNR << std::endl;
956 CHECK(PSNR >= min_PSNR_bilinear);
963 convertTo(I_RGBA_16U, I_RGBA_8U);
964 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
965 std::cout <<
"16-bit - GBRG - Malvar - PSNR: " << PSNR << std::endl;
966 CHECK(PSNR >= min_PSNR_Malvar);
973 readBinaryFile(filename, buffer);
975 col2im(buffer, I_Bayer_16U);
981 convertTo(I_RGBA_16U, I_RGBA_8U);
982 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
983 std::cout <<
"16-bit - GRBG - Bilinear - PSNR: " << PSNR << std::endl;
984 CHECK(PSNR >= min_PSNR_bilinear);
991 convertTo(I_RGBA_16U, I_RGBA_8U);
992 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
993 std::cout <<
"16-bit - GRBG - Malvar - PSNR: " << PSNR << std::endl;
994 CHECK(PSNR >= min_PSNR_Malvar);
1001 readBinaryFile(filename, buffer);
1003 col2im(buffer, I_Bayer_16U);
1009 convertTo(I_RGBA_16U, I_RGBA_8U);
1010 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1011 std::cout <<
"16-bit - RGGB - Bilinear - PSNR: " << PSNR << std::endl;
1012 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 - RGGB - Malvar - PSNR: " << PSNR << std::endl;
1022 CHECK(PSNR >= min_PSNR_Malvar);
1029 std::vector<uint8_t> buffer(height*width);
1037 std::FILE* f = std::fopen(filename.c_str(),
"rb");
1038 size_t sread = std::fread(&buffer[0],
sizeof buffer[0], buffer.size(), f);
1039 REQUIRE(sread == buffer.size());
1041 col2im(buffer, I_Bayer_8U);
1047 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1048 std::cout <<
"8-bit - BGGR - Bilinear - PSNR: " << PSNR << std::endl;
1049 CHECK(PSNR >= min_PSNR_bilinear);
1056 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1057 std::cout <<
"8-bit - BGGR - Malvar - PSNR: " << PSNR << std::endl;
1058 CHECK(PSNR >= min_PSNR_Malvar);
1067 std::FILE* f = std::fopen(filename.c_str(),
"rb");
1068 size_t sread = std::fread(&buffer[0],
sizeof buffer[0], buffer.size(), f);
1069 REQUIRE(sread == buffer.size());
1071 col2im(buffer, I_Bayer_8U);
1077 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1078 std::cout <<
"8-bit - GBRG - Bilinear - PSNR: " << PSNR << std::endl;
1079 CHECK(PSNR >= min_PSNR_bilinear);
1086 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1087 std::cout <<
"8-bit - GBRG - Malvar - PSNR: " << PSNR << std::endl;
1088 CHECK(PSNR >= min_PSNR_Malvar);
1097 std::FILE* f = std::fopen(filename.c_str(),
"rb");
1098 size_t sread = std::fread(&buffer[0],
sizeof buffer[0], buffer.size(), f);
1099 REQUIRE(sread == buffer.size());
1101 col2im(buffer, I_Bayer_8U);
1107 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1108 std::cout <<
"8-bit - GRBG - Bilinear - PSNR: " << PSNR << std::endl;
1109 CHECK(PSNR >= min_PSNR_bilinear);
1116 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1117 std::cout <<
"8-bit - GRBG - Malvar - PSNR: " << PSNR << std::endl;
1118 CHECK(PSNR >= min_PSNR_Malvar);
1127 std::FILE* f = std::fopen(filename.c_str(),
"rb");
1128 size_t sread = std::fread(&buffer[0],
sizeof buffer[0], buffer.size(), f);
1129 REQUIRE(sread == buffer.size());
1131 col2im(buffer, I_Bayer_8U);
1137 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1138 std::cout <<
"8-bit - RGGB - Bilinear - PSNR: " << PSNR << std::endl;
1139 CHECK(PSNR >= min_PSNR_bilinear);
1146 double PSNR = computePSNR(I_RGBA_8U, I_RGBA_8U_ref);
1147 std::cout <<
"8-bit - RGGB - Malvar - PSNR: " << PSNR << std::endl;
1148 CHECK(PSNR >= min_PSNR_Malvar);
1155 int main(
int argc,
char *argv[])
1157 Catch::Session session;
1160 session.applyCommandLine(argc, argv);
1162 int numFailed = session.run();
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void demosaicBGGRToRGBaBilinear(const uint8_t *bggr, 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 RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
Type * bitmap
points toward the bitmap
static void BGRaToRGBa(unsigned char *bgra, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
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 demosaicGRBGToRGBaBilinear(const uint8_t *grbg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void RGBToGrey(unsigned char *rgb, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false)
static void demosaicGBRGToRGBaBilinear(const uint8_t *gbrg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static double sqr(double x)
VISP_EXPORT uint16_t swap16bits(uint16_t val)
static void demosaicRGGBToRGBaBilinear(const uint8_t *rggb, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void demosaicGRBGToRGBaMalvar(const uint8_t *grbg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void demosaicBGGRToRGBaMalvar(const uint8_t *bggr, 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 BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
static void BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
unsigned int getHeight() const
Implementation of column vector and the associated operations.
static void RGBaToRGB(unsigned char *rgba, unsigned char *rgb, unsigned int size)
static void demosaicGBRGToRGBaMalvar(const uint8_t *gbrg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
unsigned int getWidth() const