MCPcopy Create free account
hub / github.com/davisking/dlib / test_filtering2

Function test_filtering2

dlib/test/image.cpp:942–1027  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

940 }
941
942 void test_filtering2(int nr, int nc, dlib::rand& rnd)
943 {
944 print_spinner();
945 dlog << LINFO << "test_filtering2(): " << nr << " " << nc;
946 array2d<float> img(302,301);
947 for (long r = 0; r < img.nr(); ++r)
948 {
949 for (long c = 0; c < img.nc(); ++c)
950 {
951 img[r][c] = rnd.get_random_gaussian();
952 }
953 }
954 matrix<float> filt = matrix_cast<float>(randm(nr,nc,rnd));
955
956 matrix<float> out = xcorr_same(mat(img),filt);
957 matrix<float> out2 = subm(conv(mat(img),flip(filt)), filt.nr()/2, filt.nc()/2, img.nr(), img.nc());
958 // make sure xcorr_same does exactly what the docs say it should.
959 DLIB_TEST(max(abs(out-out2)) < 1e-7);
960
961 // Now compare the filtering functions to xcorr_same to make sure everything does
962 // filtering in the same way.
963 array2d<float> imout(img.nr(), img.nc());
964 assign_all_pixels(imout, 10);
965 rectangle rect = spatially_filter_image(img, imout, filt);
966 border_enumerator be(get_rect(imout),rect);
967 while (be.move_next())
968 {
969 DLIB_TEST(imout[be.element().y()][be.element().x()] == 0);
970 }
971 DLIB_TEST_MSG(max(abs(subm(mat(imout),rect) - subm(out,rect))) < 1e-5, max(abs(subm(mat(imout),rect) - subm(out,rect))));
972
973
974 assign_all_pixels(imout, 10);
975 out = 10;
976 rect = spatially_filter_image(img, imout, filt,2,true,true);
977 be = border_enumerator(get_rect(imout),rect);
978 while (be.move_next())
979 {
980 DLIB_TEST(imout[be.element().y()][be.element().x()] == 10);
981 }
982 out += abs(xcorr_same(mat(img),filt)/2);
983 DLIB_TEST(max(abs(subm(mat(imout),rect) - subm(out,rect))) < 1e-7);
984
985
986 assign_all_pixels(imout, -10);
987 out = -10;
988 rect = spatially_filter_image(img, imout, filt,2,false,true);
989 be = border_enumerator(get_rect(imout),rect);
990 while (be.move_next())
991 {
992 DLIB_TEST(imout[be.element().y()][be.element().x()] == -10);
993 }
994 out += xcorr_same(mat(img),filt)/2;
995 DLIB_TEST_MSG(max(abs(subm(mat(imout),rect) - subm(out,rect))) < 1e-5, max(abs(subm(mat(imout),rect) - subm(out,rect))));
996
997
998
999

Callers 1

perform_testMethod · 0.85

Calls 15

print_spinnerFunction · 0.85
xcorr_sameFunction · 0.85
submFunction · 0.85
convFunction · 0.85
flipFunction · 0.85
absFunction · 0.85
assign_all_pixelsFunction · 0.85
spatially_filter_imageFunction · 0.85
get_rectFunction · 0.85
tmpFunction · 0.85
get_random_gaussianMethod · 0.80

Tested by

no test coverage detected