objects.hh 4.04 KB
Newer Older
1
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2
//
3
// This file is part of Olena.
4
//
5
6
7
8
9
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
10
11
12
13
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// 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
21
22
23
24
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License.  This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
25

26
27
#ifndef SCRIBO_PRIMITIVE_EXTRACT_OBJECTS_HH
# define SCRIBO_PRIMITIVE_EXTRACT_OBJECTS_HH
28

29
/// \file
30
31
32
33
34
35
36
///
/// Extract objects in a binary image.


# include <mln/core/concept/neighborhood.hh>
# include <mln/core/site_set/box.hh>

37
38
39
# include <mln/accu/shape/bbox.hh>

# include <mln/labeling/blobs_and_compute.hh>
40
41
42
43
44
45
# include <mln/labeling/compute.hh>

# include <mln/util/array.hh>

# include <mln/debug/println.hh>

46
47
# include <scribo/core/object_image.hh>

48
#include <mln/accu/shape/bbox.hh>
49
50
51
#include <mln/accu/center.hh>


52
53
54
namespace scribo
{

55
  namespace primitive
56
57
  {

58
    namespace extract
59
60
61
62
63
64
    {

      using namespace mln;

      /// Extract objects in a binary image.
      ///
65
66
      /// \param[in]	 input	  A binary image. Objects are must be set
      ///                         to 'true'
67
68
69
70
71
72
73
74
      ///			  and background to 'false'.
      /// \param[in]	 nbh	  A neighborhood to be used for labeling.
      /// \param[in,out] nobjects Will store the numbers of objects found.
      ///
      /// \return An image of labeled objects.
      //
      template <typename I, typename N, typename V>
      inline
75
      object_image(mln_ch_value(I,V))
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
      objects(const Image<I>& input,
	      const Neighborhood<N>& nbh, V& nobjects);


# ifndef MLN_INCLUDE_ONLY


      namespace internal
      {

        template <typename I, typename N, typename V>
        inline
	void
        objects_tests(const Image<I>& input,
		      const Neighborhood<N>& nbh, V& nobjects)
	{
	  mlc_equal(mln_value(I),bool)::check();
	  mlc_is_a(V, mln::value::Symbolic)::check();
	  mln_precondition(exact(input).is_valid());
	  mln_precondition(exact(nbh).is_valid());
	  (void) input;
	  (void) nbh;
	  (void) nobjects;
	}


102
      } // end of namespace scribo::primitive::extract::internal
103
104
105
106


      template <typename I, typename N, typename V>
      inline
107
      object_image(mln_ch_value(I,V))
108
109
110
111
112
113
114
      objects(const Image<I>& input,
	      const Neighborhood<N>& nbh, V& nobjects)
      {
	trace::entering("scribo::objects");

	internal::objects_tests(input, nbh, nobjects);

115
116
117
118
119
120
	typedef mln_ch_value(I,V) L;
	typedef accu::shape::bbox<mln_psite(I)> accu_bbox;

	util::couple<L, util::array<mln_box(I)> >
	  results = labeling::blobs_and_compute(input, nbh, nobjects,
						accu_bbox());
121

122
123
124
125
126
127
	// FIXME: enable mass centers computation and maybe merge this
	// computation with blobs computation above.
	util::array<mln_result(accu::center<mln_site(I)>)>
	  mass_centers;
 	mass_centers = labeling::compute(accu::meta::center(),
					 results.first(), nobjects);
128
	object_image(L)
129
	  output(results.first(), nobjects, results.second(), mass_centers);
130
131
132
133
134
135
136

	trace::exiting("scribo::objects");
	return output;
      }

# endif // ! MLN_INCLUDE_ONLY

137
    } // end of namespace scribo::primitive::extract
138

139
  } // end of namespace scribo::primitive
140
141
142
143

} // end of namespace scribo


144
#endif // ! SCRIBO_PRIMITIVE_EXTRACT_OBJECTS_HH