00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #include <mln/core/image/image2d.hh>
00027 #include <mln/core/image/dmorph/sub_image.hh>
00028 
00029 
00030 #include <mln/data/fill.hh>
00031 #include <mln/debug/println.hh>
00032 #include <mln/core/alias/w_window2d_int.hh>
00033 #include <mln/core/alias/w_window2d_float.hh>
00034 
00035 #include <mln/make/win_chamfer.hh>
00036 #include <mln/geom/chamfer.hh>
00037 #include <mln/data/compare.hh>
00038 
00039 #include <mln/opt/at.hh>
00040 
00041 
00042 int main()
00043 {
00044   using namespace mln;
00045   unsigned max = 51;
00046 
00047   image2d<bool> ima(9, 9);
00048 
00049   {
00050     data::fill(ima, false);
00051     opt::at(ima, 4,4) = true;
00052     const w_window2d_int& w_win = make::mk_chamfer_3x3_int<2, 0> ();
00053     image2d<unsigned> out = geom::chamfer(ima, w_win, max);
00054     unsigned r[9][9] =
00055       {
00056         {16, 14, 12, 10,  8, 10, 12, 14, 16},
00057         {14, 12, 10,  8,  6,  8, 10, 12, 14},
00058         {12, 10,  8,  6,  4,  6,  8, 10, 12},
00059         {10,  8,  6,  4,  2,  4,  6,  8, 10},
00060         { 8,  6,  4,  2,  0,  2,  4,  6,  8},
00061         {10,  8,  6,  4,  2,  4,  6,  8, 10},
00062         {12, 10,  8,  6,  4,  6,  8, 10, 12},
00063         {14, 12, 10,  8,  6,  8, 10, 12, 14},
00064         {16, 14, 12, 10,  8, 10, 12, 14, 16}
00065       };
00066 
00067     image2d<unsigned> ref (make::image(r));
00068     mln_assertion (out == ref);
00069   }
00070 
00071   {
00072     data::fill(ima, false);
00073     opt::at(ima, 4,4) = true;
00074     const w_window2d_int& w_win = make::mk_chamfer_3x3_int<2, 3> ();
00075     image2d<unsigned> out = geom::chamfer(ima, w_win, max);
00076 
00077     unsigned r[9][9] =
00078       {
00079         {12, 11, 10, 9, 8, 9, 10, 11, 12},
00080         {11,  9,  8, 7, 6, 7,  8,  9, 11},
00081         {10,  8,  6, 5, 4, 5,  6,  8, 10},
00082         { 9,  7,  5, 3, 2, 3,  5,  7,  9},
00083         { 8,  6,  4, 2, 0, 2,  4,  6,  8},
00084         { 9,  7,  5, 3, 2, 3,  5,  7,  9},
00085         {10,  8,  6, 5, 4, 5,  6,  8, 10},
00086         {11,  9,  8, 7, 6, 7,  8,  9, 11},
00087         {12, 11, 10, 9, 8, 9, 10, 11, 12}
00088       };
00089 
00090     image2d<unsigned> ref (make::image(r));
00091     mln_assertion (out == ref);
00092   }
00093 
00094   {
00095     data::fill(ima, false);
00096     opt::at(ima, 4,4) = true;
00097     const w_window2d_int& w_win = make::mk_chamfer_5x5_int<4, 6, 9> ();
00098     image2d<unsigned> out = geom::chamfer(ima, w_win, max);
00099     image2d<unsigned>::fwd_piter p(out.domain());
00100     for_all(p)
00101       out(p) = out(p) / 2;
00102 
00103     unsigned r[9][9] =
00104       {
00105         {12, 10, 9, 8, 8, 8, 9, 10, 12},
00106         {10,  9, 7, 6, 6, 6, 7,  9, 10},
00107         { 9,  7, 6, 4, 4, 4, 6,  7,  9},
00108         { 8,  6, 4, 3, 2, 3, 4,  6,  8},
00109         { 8,  6, 4, 2, 0, 2, 4,  6,  8},
00110         { 8,  6, 4, 3, 2, 3, 4,  6,  8},
00111         { 9,  7, 6, 4, 4, 4, 6,  7,  9},
00112         {10,  9, 7, 6, 6, 6, 7,  9, 10},
00113         {12, 10, 9, 8, 8, 8, 9, 10, 12}
00114       };
00115 
00116     image2d<unsigned> ref (make::image(r));
00117     mln_assertion (out == ref);
00118 
00119   }
00120 
00121 }