test_f0.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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_f0, components)
  44. {
  45. float arI[16][16] =
  46. {
  47. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  48. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  49. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  50. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  51. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  52. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  53. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  54. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  55. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  56. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  57. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  58. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  59. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  60. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  61. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  62. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 }
  63. };
  64. Mat I = Mat(16, 16, CV_32F, arI);
  65. float arDemandedComp[9][9] =
  66. {
  67. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  68. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  69. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  70. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  71. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  72. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  73. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  74. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  75. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 }
  76. };
  77. Mat demandedComp = Mat(9, 9, CV_32F, arDemandedComp);
  78. Mat kernel;
  79. ft::createKernel(ft::LINEAR, 2, kernel, 1);
  80. Mat f0comp;
  81. ft::FT02D_components(I, kernel, f0comp);
  82. double n1 = cvtest::norm(demandedComp, f0comp, NORM_INF);
  83. EXPECT_DOUBLE_EQ(n1, 0);
  84. }
  85. TEST(fuzzy_f0, inversion)
  86. {
  87. float arDemandedO[16][16] =
  88. {
  89. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  90. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  91. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  92. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  93. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  94. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  95. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  96. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  97. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  98. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  99. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  100. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  101. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  102. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  103. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  104. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 }
  105. };
  106. Mat demandedO = Mat(16, 16, CV_32F, arDemandedO);
  107. float arComp[9][9] =
  108. {
  109. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  110. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  111. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  112. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  113. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  114. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  115. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  116. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 },
  117. { 0, 2.5, 33.75, 80.25, 127, 173.75, 220.75, 252.25, 255 }
  118. };
  119. Mat comp = Mat(9, 9, CV_32F, arComp);
  120. Mat kernel;
  121. ft::createKernel(ft::LINEAR, 2, kernel, 1);
  122. Mat O;
  123. ft::FT02D_inverseFT(comp, kernel, O, 16, 16);
  124. double n1 = cvtest::norm(demandedO, O, NORM_INF);
  125. EXPECT_DOUBLE_EQ(n1, 0);
  126. }
  127. TEST(fuzzy_f0, process)
  128. {
  129. float arI[16][16] =
  130. {
  131. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  132. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  133. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  134. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  135. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  136. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  137. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  138. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  139. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  140. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  141. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  142. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  143. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  144. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  145. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 },
  146. { 0, 0, 0, 10, 34, 57, 80, 104, 127, 150, 174, 197, 221, 244, 255, 255 }
  147. };
  148. Mat I = Mat(16, 16, CV_32F, arI);
  149. float arDemandedO[16][16] =
  150. {
  151. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  152. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  153. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  154. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  155. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  156. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  157. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  158. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  159. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  160. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  161. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  162. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  163. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  164. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  165. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 },
  166. { 0, 1.25, 2.5, 18.125, 33.75, 57, 80.25, 103.625, 127, 150.375, 173.75, 197.25, 220.75, 236.5, 252.25, 253.625 }
  167. };
  168. Mat demandedO = Mat(16, 16, CV_32F, arDemandedO);
  169. Mat kernel;
  170. ft::createKernel(ft::LINEAR, 2, kernel, 1);
  171. Mat O;
  172. ft::FT02D_process(I, kernel, O);
  173. double n1 = cvtest::norm(demandedO, O, NORM_INF);
  174. EXPECT_DOUBLE_EQ(n1, 0);
  175. }
  176. TEST(fuzzy_f0, FL_process)
  177. {
  178. string folder = string(cvtest::TS::ptr()->get_data_path()) + "fuzzy/";
  179. Mat orig = imread(folder + "orig.png");
  180. Mat exp5 = imread(folder + "exp5.png");
  181. EXPECT_TRUE(!orig.empty() && !exp5.empty());
  182. Mat res5;
  183. ft::FT02D_FL_process(orig, 5, res5);
  184. res5.convertTo(res5, CV_8UC3);
  185. double n1 = cvtest::norm(exp5, res5, NORM_INF);
  186. EXPECT_LE(n1, 1);
  187. }
  188. TEST(fuzzy_f0, FL_process_float)
  189. {
  190. string folder = string(cvtest::TS::ptr()->get_data_path()) + "fuzzy/";
  191. Mat orig = imread(folder + "orig.png");
  192. Mat exp6 = imread(folder + "exp6.png");
  193. EXPECT_TRUE(!orig.empty() && !exp6.empty());
  194. Mat res6;
  195. ft::FT02D_FL_process_float(orig, 5, res6);
  196. res6.convertTo(res6, CV_8UC3);
  197. double n1 = cvtest::norm(exp6, res6, NORM_INF);
  198. EXPECT_LE(n1, 1);
  199. }
  200. }} // namespace