test_image.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling,
  14. // Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistribution's of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. //
  22. // * Redistribution's in binary form must reproduce the above copyright notice,
  23. // this list of conditions and the following disclaimer in the documentation
  24. // and/or other materials provided with the distribution.
  25. //
  26. // * The name of the copyright holders may not be used to endorse or promote products
  27. // derived from this software without specific prior written permission.
  28. //
  29. // This software is provided by the copyright holders and contributors "as is" and
  30. // any express or implied warranties, including, but not limited to, the implied
  31. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  32. // In no event shall the Intel Corporation or contributors be liable for any direct,
  33. // indirect, incidental, special, exemplary, or consequential damages
  34. // (including, but not limited to, procurement of substitute goods or services;
  35. // loss of use, data, or profits; or business interruption) however caused
  36. // and on any theory of liability, whether in contract, strict liability,
  37. // or tort (including negligence or otherwise) arising in any way out of
  38. // the use of this software, even if advised of the possibility of such damage.
  39. //
  40. //M*/
  41. #include "test_precomp.hpp"
  42. namespace opencv_test { namespace {
  43. TEST(fuzzy_image, inpainting)
  44. {
  45. string folder = string(cvtest::TS::ptr()->get_data_path()) + "fuzzy/";
  46. Mat orig = imread(folder + "orig.png");
  47. Mat exp1 = imread(folder + "exp1.png");
  48. Mat exp2 = imread(folder + "exp2.png");
  49. Mat exp3 = imread(folder + "exp3.png");
  50. Mat mask1 = imread(folder + "mask1.png", IMREAD_GRAYSCALE);
  51. Mat mask2 = imread(folder + "mask2.png", IMREAD_GRAYSCALE);
  52. EXPECT_TRUE(!orig.empty() && !exp1.empty() && !exp2.empty() && !exp3.empty() && !mask1.empty() && !mask2.empty());
  53. Mat res1, res2, res3;
  54. ft::inpaint(orig, mask1, res1, 2, ft::LINEAR, ft::ONE_STEP);
  55. ft::inpaint(orig, mask2, res2, 2, ft::LINEAR, ft::MULTI_STEP);
  56. ft::inpaint(orig, mask2, res3, 2, ft::LINEAR, ft::ITERATIVE);
  57. res1.convertTo(res1, CV_8UC3);
  58. res2.convertTo(res2, CV_8UC3);
  59. res3.convertTo(res3, CV_8UC3);
  60. double n1 = cvtest::norm(exp1, res1, NORM_INF);
  61. double n2 = cvtest::norm(exp2, res2, NORM_INF);
  62. double n3 = cvtest::norm(exp3, res3, NORM_INF);
  63. EXPECT_LE(n1, 1);
  64. EXPECT_LE(n2, 1);
  65. EXPECT_LE(n3, 1);
  66. }
  67. TEST(fuzzy_image, filtering)
  68. {
  69. string folder = string(cvtest::TS::ptr()->get_data_path()) + "fuzzy/";
  70. Mat orig = imread(folder + "orig.png");
  71. Mat exp4 = imread(folder + "exp4.png");
  72. EXPECT_TRUE(!orig.empty() && !exp4.empty());
  73. Mat kernel;
  74. ft::createKernel(ft::LINEAR, 20, kernel, 3);
  75. Mat res4;
  76. ft::filter(orig, kernel, res4);
  77. res4.convertTo(res4, CV_8UC3);
  78. double n1 = cvtest::norm(exp4, res4, NORM_INF);
  79. EXPECT_LE(n1, 1);
  80. }
  81. TEST(fuzzy_image, kernel)
  82. {
  83. Mat kernel1;
  84. ft::createKernel(ft::LINEAR, 2, kernel1, 1);
  85. Mat vectorA = (Mat_<float>(1, 5) << 0, 0.5, 1, 0.5, 0);
  86. Mat vectorB = (Mat_<float>(5, 1) << 0, 0.5, 1, 0.5, 0);
  87. Mat kernel2;
  88. ft::createKernel(vectorA, vectorB, kernel2, 1);
  89. double diff = cvtest::norm(kernel1, kernel2, NORM_INF);
  90. EXPECT_DOUBLE_EQ(diff, 0);
  91. }
  92. }} // namespace