test_radon_transform.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "test_precomp.hpp"
  5. namespace opencv_test {namespace {
  6. TEST(RadonTransformTest, output_size)
  7. {
  8. Mat src(Size(256, 256), CV_8U, Scalar(0));
  9. circle(src, Point(128, 128), 64, Scalar(255), FILLED);
  10. Mat radon;
  11. cv::ximgproc::RadonTransform(src, radon);
  12. EXPECT_EQ(363, radon.rows);
  13. EXPECT_EQ(180, radon.cols);
  14. cv::ximgproc::RadonTransform(src, radon, 1, 0, 180, true);
  15. EXPECT_EQ(256, radon.rows);
  16. EXPECT_EQ(180, radon.cols);
  17. }
  18. TEST(RadonTransformTest, output_type)
  19. {
  20. Mat src_int(Size(256, 256), CV_8U, Scalar(0));
  21. circle(src_int, Point(128, 128), 64, Scalar(255), FILLED);
  22. Mat radon, radon_norm;
  23. cv::ximgproc::RadonTransform(src_int, radon);
  24. cv::ximgproc::RadonTransform(src_int, radon_norm, 1, 0, 180, false, true);
  25. EXPECT_EQ(CV_32SC1, radon.type());
  26. EXPECT_EQ(CV_8U, radon_norm.type());
  27. Mat src_float(Size(256, 256), CV_32FC1, Scalar(0));
  28. Mat src_double(Size(256, 256), CV_32FC1, Scalar(0));
  29. cv::ximgproc::RadonTransform(src_float, radon);
  30. cv::ximgproc::RadonTransform(src_float, radon_norm, 1, 0, 180, false, true);
  31. EXPECT_EQ(CV_64FC1, radon.type());
  32. EXPECT_EQ(CV_8U, radon_norm.type());
  33. cv::ximgproc::RadonTransform(src_double, radon);
  34. EXPECT_EQ(CV_64FC1, radon.type());
  35. EXPECT_EQ(CV_8U, radon_norm.type());
  36. }
  37. TEST(RadonTransformTest, accuracy_by_pixel)
  38. {
  39. Mat src(Size(256, 256), CV_8U, Scalar(0));
  40. circle(src, Point(128, 128), 64, Scalar(255), FILLED);
  41. Mat radon;
  42. cv::ximgproc::RadonTransform(src, radon);
  43. ASSERT_EQ(CV_32SC1, radon.type());
  44. EXPECT_EQ(0, radon.at<int>(0, 0));
  45. EXPECT_LT(18000, radon.at<int>(128, 128));
  46. EXPECT_GT(19000, radon.at<int>(128, 128));
  47. }
  48. TEST(RadonTransformTest, accuracy_uchar)
  49. {
  50. Mat src(Size(10, 10), CV_8UC1, Scalar(1));
  51. cv::Mat radon;
  52. ximgproc::RadonTransform(src, radon, 45, 0, 180, false, false);
  53. EXPECT_EQ(100, sum(radon.col(0))[0]);
  54. }
  55. TEST(RadonTransformTest, accuracy_float)
  56. {
  57. Mat src(Size(10, 10), CV_32FC1, Scalar(1.1));
  58. cv::Mat radon;
  59. ximgproc::RadonTransform(src, radon, 45, 0, 180, false, false);
  60. EXPECT_LT(109, sum(radon.col(0))[0]);
  61. EXPECT_GT(111, sum(radon.col(0))[0]);
  62. }
  63. } }