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/alias/neighb2d.hh>
00028 #include <mln/core/var.hh>
00029 #include <mln/value/int_u8.hh>
00030
00031 #include <mln/make/dual_neighb.hh>
00032 #include <mln/topo/is_simple_2d.hh>
00033 #include <mln/morpho/skeleton_constrained.hh>
00034
00035 #include <mln/io/pbm/load.hh>
00036 #include <mln/io/pbm/save.hh>
00037 #include <mln/data/fill.hh>
00038
00039 #include <mln/pw/value.hh>
00040 #include <mln/core/image/dmorph/image_if.hh>
00041 #include <mln/extension/adjust_duplicate.hh>
00042
00043 #include <mln/logical/not.hh>
00044 #include <mln/arith/revert.hh>
00045 #include <mln/transform/distance_geodesic.hh>
00046
00047 #include <mln/data/compare.hh>
00048
00049 #include "tests/data.hh"
00050
00051
00052 namespace mln
00053 {
00054
00055 template <typename N>
00056 void show_connectivity_numbers(const image2d<bool>& ima,
00057 const N& nbh)
00058 {
00059 extension::adjust_duplicate(ima, nbh);
00060
00061 image2d<unsigned> when_true(ima.domain()), when_false(ima.domain());
00062 mln_piter(box2d) p(ima.domain());
00063 for_all(p)
00064 {
00065 when_true(p) = connectivity_number_2d(ima, nbh.foreground(), p, true);
00066 when_false(p) = connectivity_number_2d(ima, nbh.background(), p, false);
00067 }
00068 }
00069
00070 }
00071
00072
00073 bool skl_ref_[22][18] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
00074 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
00075 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
00076 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
00077 { 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 1, 1, 0 } };
00095
00096 int main()
00097 {
00098 using namespace mln;
00099 using value::int_u8;
00100
00101 border::thickness = 1;
00102
00103 image2d<bool> pic;
00104 io::pbm::load(pic, MLN_IMG_DIR "/tiny.pbm");
00105
00106 typedef neighb<win::multiple_size<2u, window<dpoint<grid::square, short int> >,
00107 pw::value_<image2d<bool> > > > nbh_t;
00108 nbh_t nbh = make::dual_neighb(pic, c4(), c8());
00109
00110 show_connectivity_numbers(pic, nbh);
00111
00112
00113 image2d<bool> K(pic.domain());
00114 data::fill(K, false);
00115
00116
00117 image2d<int_u8> dmap = transform::distance_geodesic(logical::not_(pic),
00118 nbh.foreground(),
00119 mln_max(int_u8));
00120 dmap = arith::revert(dmap);
00121
00122 image2d<bool> skl = morpho::skeleton_constrained(pic,
00123 nbh, is_simple_2d_t(),
00124 K, dmap);
00125 image2d<bool> skl_ref = make::image(skl_ref_);
00126 mln_assertion(skl == skl_ref);
00127 }