$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
border/equalize.hh
1 // Copyright (C) 2007, 2008, 2009, 2012 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 
27 #ifndef MLN_BORDER_EQUALIZE_HH
28 # define MLN_BORDER_EQUALIZE_HH
29 
36 # include <mln/border/resize.hh>
37 
38 
39 namespace mln
40 {
41 
42  namespace border
43  {
44 
62  template <typename I, typename J>
63  void equalize(const Image<I>& ima1, const Image<J>& ima2,
64  unsigned min_thickness);
65 
66 
67 
68 # ifndef MLN_INCLUDE_ONLY
69 
70  namespace impl
71  {
72 
73  template <typename I, typename J>
74  inline
75  void equalize_(const I& ima1, const J& ima2, unsigned min_thickness)
76  {
77  mln_trace("border::impl::equalize_");
78 
79  unsigned b1 = border::get(ima1), b2 = border::get(ima2);
80 
81  if (! (b1 == b2 && b2 >= min_thickness))
82  // Something has to be done.
83  {
84  if (b1 < min_thickness && b2 < min_thickness)
85  // Both images have to be border-resized.
86  {
87  border::resize(ima1, min_thickness);
88  border::resize(ima2, min_thickness);
89  }
90  else
91  // A single image has to be border-resized with
92  // the other image thickness.
93  if (b1 < min_thickness)
94  {
95  mln_assertion(b2 >= min_thickness);
96  border::resize(ima1, b2);
97  }
98  else
99  {
100  //mln_assertion(b2 < min_thickness); // why ?
101  mln_assertion(b1 >= min_thickness);
102  border::resize(ima2, b1);
103  }
104  }
105 
106  }
107 
108  } // end of namespace mln::border::impl
109 
110 
111  // Facade
112 
113  template <typename I, typename J>
114  inline
115  void equalize(const Image<I>& ima1_, const Image<J>& ima2_,
116  unsigned min_thickness)
117  {
118  mln_trace("border::equalize");
119 
120  //FIXME: check border
121  //mlc_is(mln_trait_image_border(I), trait::image::border::some)::check();
122  //mlc_is(mln_trait_image_border(J), trait::image::border::some)::check();
123  const I& ima1 = exact(ima1_);
124  const J& ima2 = exact(ima2_);
125  mln_precondition(ima1.is_valid() && ima2.is_valid());
126 
127  impl::equalize_(ima1, ima2, min_thickness);
128 
129  mln_postcondition(border::get(ima1) == border::get(ima2) &&
130  border::get(ima1) >= min_thickness &&
131  border::get(ima2) >= min_thickness);
132 
133  }
134 
135 # endif // ! MLN_INCLUDE_ONLY
136 
137  } // end of namespace mln::border
138 
139 } // end of namespace mln
140 
141 
142 #endif // ! MLN_BORDER_EQUALIZE_HH