1 // This is mul/mfpf/tests/test_dp_snake.cxx
2 //=======================================================================
3 //
4 //  Copyright: (C) 2007 The University of Manchester
5 //
6 //=======================================================================
7 #include <iostream>
8 #include "testlib/testlib_test.h"
9 //:
10 // \file
11 // \author Tim Cootes
12 // \brief test mfpf_dp_snake
13 
14 #ifdef _MSC_VER
15 #  include "vcl_msvc_warnings.h"
16 #endif
17 #include <mfpf/mfpf_dp_snake.h>
18 #include <mfpf/mfpf_edge_finder.h>
19 #include "vgl/vgl_point_2d.h"
20 #include <vil/algo/vil_gauss_filter.h>
21 
test_dp_snake()22 void test_dp_snake()
23 {
24   std::cout << "***********************\n"
25            << " Testing mfpf_dp_snake\n"
26            << "***********************\n";
27 
28   // Create image containing disk
29   unsigned ni = 29;
30   double c = 0.5*ni;
31   double r2 = 7.5*7.5;
32 
33   vil_image_view<float> im(ni,ni);
34   im.fill(0.0f);
35   for (unsigned j=0;j<ni;++j)
36     for (unsigned i=0;i<ni;++i)
37     {
38        double dx=i-c, dy=j-c;
39        double dr2 = dx*dx+dy*dy;
40        if (dr2<=r2) im(i,j)=100.0f;
41     }
42 
43   vimt_image_2d_of<float> image;
44   vil_gauss_filter_2d(im,image.image(),0.1,3);
45 
46   // Set up snake as small offset circle
47   mfpf_dp_snake dp_snake;
48   mfpf_edge_finder edge_finder;
49   edge_finder.set_search_area(7,0);
50   dp_snake.set_to_circle(edge_finder,
51                          20, vgl_point_2d<double>(11,9),6);
52 
53   std::cout<<"Initial Snake: "<<dp_snake<<std::endl;
54 
55   for (unsigned i=0;i<10;++i)
56   {
57     double move = dp_snake.update_step(image);
58 
59     std::cout<<i<<") "<<dp_snake<<std::endl
60             <<"Mean move = "<<move<<std::endl;
61   }
62 
63 //  dp_snake.search(image);
64 
65 //  std::cout<<"After search. Snake: "<<dp_snake<<std::endl;
66 }
67 
68 TESTMAIN(test_dp_snake);
69