$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
image3d-skel-with-end-points.cc
1 // Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
29 
30 #include <fstream>
31 
32 #include <mln/core/image/image3d.hh>
33 #include <mln/core/alias/neighb3d.hh>
34 #include <mln/make/box3d.hh>
35 
36 #include <mln/core/image/vmorph/fun_image.hh>
37 #include <mln/fun/v2b/lnot.hh>
38 
39 #include <mln/border/fill.hh>
40 
41 #include <mln/labeling/blobs.hh>
42 
43 #include <mln/topo/skeleton/breadth_first_thinning.hh>
44 
45 #include <mln/topo/is_simple_point3d.hh>
46 #include <mln/topo/detach_point.hh>
47 #include <mln/topo/is_not_end_point.hh>
48 
49 #include "apps/data.hh"
50 
51 #include "image3d-skel.hh"
52 
53 
54 // FIXME: Have this program take a 3D image as input (instead of
55 // hard-coding it here).
56 
57 int main()
58 {
59  using namespace mln;
60 
61  typedef image3d<bool> I;
62  typedef neighb3d N;
63 
65 
66 // I whole_input = load_pgm_3d(MLN_IMG_DIR "/bunny.pgm");
67 // // FIXME: Work on a small image in a first time, then process the
68 // // whole image.
69 // I input = subsampling_3d(whole_input, 4);
70 
71  // Input image.
72  //
73  // Use a smaller half-length than the default one (100) as this
74  // program does not use the fast version of the simple 3D point
75  // criterion.
76  I input = make_triple_torus(20);
77 
78  std::cerr << input.domain() << std::endl;
79  save_raw_3d(input, "image3d-skel-with-end-points-input.raw");
80  save_vtk_polyhedrons(input, "image3d-skel-with-end-points-input.vtk");
81 
82  // FIXME: Debug.
83  unsigned n_fg_comps;
84  labeling::blobs(input, c26(), n_fg_comps);
85  unsigned n_bg_comps;
86  labeling::blobs((fun::v2b::lnot<bool>() << input), c6(), n_bg_comps);
87  std::cerr << "n_fg_comps = " << n_fg_comps << std::endl;
88  std::cerr << "n_bg_comps = " << n_bg_comps << std::endl;
89 
90  // FIXME: Use a dual neighborhood instead?
91 
92  // Foreground neighborhood.
93  N nbh_fg = c26();
94  // Background neighborhood.
95  N nbh_bg = c6();
96 
97  // Simplicity criterion functor.
98  topo::is_simple_point3d<I, N> is_simple(nbh_fg, nbh_bg);
99  // Simple point detach procedure.
100  topo::detach_point<I> detach;
101  // Constraint: do not remove end points.
102  /* FIXME: This criterion is static, e.g. it is attached to INPUT
103  (fixed), not OUTPUT (changing during the thinning). This is not
104  as good as a dynamic critertion (attached to OUTPUT). Maybe it
105  is time to introduce/use `breadth_first_thinning_inplace'. */
106  topo::is_not_end_point<I, N> constraint(c6(), input);
107 
108  I output = topo::skeleton::breadth_first_thinning(input, nbh_fg,
109  is_simple,
110  detach,
111  constraint);
112  save_raw_3d(output, "image3d-skel-with-end-points-skel.raw");
113  save_vtk_polyhedrons(output, "image3d-skel-with-end-points-skel.vtk");
114 }