$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
recorder-bft.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 
42 
43 /* FIXME: Modernize this program as soon as patches from the
44  mesh-segm-skel branch have been merged into the current branch. */
45 
46 #include <string>
47 
48 #include <mln/core/image/image2d.hh>
49 #include <mln/core/alias/neighb2d.hh>
50 
51 #include <mln/win/multiple_size.hh>
52 #include <mln/make/dual_neighb.hh>
53 
54 #include <mln/data/compare.hh>
55 
56 #include <mln/topo/skeleton/breadth_first_thinning.hh>
57 
58 #include <mln/topo/detach_point.hh>
59 
60 #include <mln/test/predicate.hh>
61 #include <mln/pw/value.hh>
62 
63 #include <mln/labeling/colorize.hh>
64 
65 #include <mln/io/pbm/load.hh>
66 #include <mln/io/pbm/save.hh>
67 
68 #include "apps/morphers/recorder.hh"
69 /* FIXME: Temporarily reuse an old file from apps/generic-skel instead
70  of newer files integrated into the library (but not merged in). */
71 #include "apps/morphers/image2d-skel.hh"
72 
73 #include "apps/data.hh"
74 
75 
76 int main()
77 {
78  using namespace mln;
79 
80  typedef image2d<bool> I;
81  I picasso = io::pbm::load(MLN_IMG_DIR "/tiny.pbm");
82  // Attach recorder to input image.
84  J picasso_rec = record(picasso);
85 
86  // Dual neighborhood.
88  N nbh = make::dual_neighb(picasso, c4(), c8());
89  // Simplicity criterion functor.
90  ::is_simple_2d<J, N> is_simple(nbh);
91  // Simple point detach procedure.
92  topo::detach_point<J> detach;
93  // Constraint.
94  ::is_not_end_point<J, neighb2d> constraint(c4(), picasso_rec);
95 
96  J bft_rec = topo::skeleton::breadth_first_thinning(picasso_rec, nbh,
97  is_simple, detach,
98  constraint);
99 
100  // Dump recorded frames.
101  /* FIXME: Hand-made (it partly duplicates ppm::save() (or more
102  precisely pbm::save()) for decorated_image's). We should be able
103  to process sequences of images. */
104  bool output_initialized_p = false;
105  for (size_t i = 0; i < bft_rec.decoration().sequence.size(); ++i)
106  {
107  I frame = bft_rec.decoration().sequence[i];
108 
109  // Skip frames until the inital image has been seen.
110  if (frame == picasso)
111  output_initialized_p = true;
112  if (!output_initialized_p)
113  continue;
114 
115  std::stringstream s;
116  s << std::setfill ('0') << std::setw (6) << i;
117  io::pbm::save(frame, std::string("picasso-bft") + s.str() + ".pbm");
118  }
119 }