$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
image3d-skel-unconstrained.cc
1 // Copyright (C) 2011, 2012, 2013 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
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 
48 #include <mln/util/timer.hh>
49 
50 #include "apps/data.hh"
51 
52 #include "image3d-skel.hh"
53 
54 
55 // FIXME: Have this program take a 3D image as input (instead of
56 // hard-coding it here).
57 
58 int main()
59 {
60  using namespace mln;
61 
62  typedef image3d<bool> I;
63  typedef neighb3d N;
64 
66 
67 // I whole_input = load_pgm_3d(MLN_IMG_DIR "/bunny.pgm");
68 // // FIXME: Work on a small image in a first time, then process the
69 // // whole image.
70 // I input = subsampling_3d(whole_input, 4);
71 
72  // Input image.
73  //
74  // Use a smaller half-length than the default one (100) as this
75  // program does not use the fast version of the simple 3D point
76  // criterion.
77  I input = make_triple_torus(20);
78  std::cout
79  << input.nslis() << " x " << input.nrows() << " x " << input.ncols()
80  << " = " << input.nslis() * input.nrows() * input.ncols() << " voxels"
81  << std::endl;
82 
83  std::cerr << input.domain() << std::endl;
84  save_raw_3d(input, "image3d-skel-unconstrained-input.raw");
85  save_vtk_polyhedrons(input, "image3d-skel-unconstrained-input.vtk");
86 
87  // FIXME: Use a dual neighborhood instead?
88 
89  // Foreground neighborhood.
90  N nbh_fg = c26();
91  // Background neighborhood.
92  N nbh_bg = c6();
93 
94  // Simplicity criterion functor.
95  topo::is_simple_point3d<I, N> is_simple(nbh_fg, nbh_bg);
96  // Simple point detach procedure.
97  topo::detach_point<I> detach;
98 
99  util::timer t;
100  t.start();
101  I output = topo::skeleton::breadth_first_thinning(input, nbh_fg,
102  is_simple,
103  detach);
104  t.stop();
105  std::cout << t.read() << " s" << std::endl;
106 
107  save_raw_3d(output, "image3d-skel-unconstrained-skel.raw");
108  save_vtk_polyhedrons(output, "image3d-skel-unconstrained-skel.vtk");
109 }