https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Géraud <thierry.geraud(a)lrde.epita.fr>
Add morpho elementary gradient and test.
* doc/tutorial/examples/sub_image.cc: Use an IP operator.
* mln/accu/pair.hh (first, second): Fix return type.
* mln/morpho/gradient_elementary.hh: New.
doc/tutorial/examples/sub_image.cc | 3
mln/accu/pair.hh | 8 +-
mln/morpho/gradient_elementary.hh | 125 +++++++++++++++++++++++++++++++++++++
3 files changed, 132 insertions(+), 4 deletions(-)
Index: doc/tutorial/examples/sub_image.cc
--- doc/tutorial/examples/sub_image.cc (revision 2084)
+++ doc/tutorial/examples/sub_image.cc (working copy)
@@ -1,9 +1,11 @@
# include <mln/core/image2d.hh>
+# include <mln/core/neighb2d.hh>
# include <mln/core/sub_image.hh>
# include <mln/debug/iota.hh>
# include <mln/debug/println.hh>
+# include <mln/morpho/gradient_elementary.hh>
int main()
@@ -17,6 +19,7 @@
sub_image<I, box2d> sub(ima, box2d(2,3));
debug::println(sub);
+ debug::println(morpho::gradient_elementary(sub, c4()));
trait::image::print(sub);
}
Index: mln/accu/pair.hh
--- mln/accu/pair.hh (revision 2084)
+++ mln/accu/pair.hh (working copy)
@@ -75,8 +75,8 @@
result to_result() const;
void get_result(result_1& r1, result_2& r2) const;
- result_1 first() const;
- result_2 second() const;
+ mln_result(A1) first() const;
+ mln_result(A2) second() const;
protected:
@@ -166,7 +166,7 @@
template <typename A1, typename A2, typename T>
inline
- result_1
+ mln_result(A1)
pair_<A1,A2,T>::first()const
{
return a1_.to_result();
@@ -174,7 +174,7 @@
template <typename A1, typename A2, typename T>
inline
- result_2
+ mln_result(A2)
pair_<A1,A2,T>::second() const
{
return a2_.to_result();
Index: mln/morpho/gradient_elementary.hh
--- mln/morpho/gradient_elementary.hh (revision 0)
+++ mln/morpho/gradient_elementary.hh (revision 0)
@@ -0,0 +1,125 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// 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
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// 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.
+
+#ifndef MLN_MORPHO_GRADIENT_ELEMENTARY_HH
+# define MLN_MORPHO_GRADIENT_ELEMENTARY_HH
+
+/// \file mln/morpho/gradient_elementary.hh
+/// \brief Morphological elementary gradient.
+///
+/// \todo Write specific code.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/accu/min_max.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ /// Morphological elementary gradient.
+ ///
+ /// \param[in] input The image to be dilated.
+ /// \param[in] nbh The neighborhood to consider.
+ ///
+ /// The structuring element is the neighborhood + the center site.
+ ///
+ /// \{
+ template <typename I, typename N>
+ mln_concrete(I)
+ gradient_elementary(const Image<I>& input, const Neighborhood<N>&
nbh);
+ /// \}
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ namespace generic
+ {
+
+ template <typename I, typename N>
+ mln_concrete(I)
+ gradient_elementary_(const mln::trait::image::kind::any&,
+ const I& input, const N& nbh)
+ {
+ trace::entering("morpho::impl::generic::gradient_elementary_");
+
+ mln_concrete(I) output;
+ initialize(output, input);
+
+ accu::min_max_<mln_value(I)> m;
+ mln_piter(I) p(input.domain());
+ mln_niter(N) n(nbh, p);
+ for_all(p)
+ {
+ m.take_as_init(input(p));
+ for_all(n) if (input.has(n))
+ m.take(input(n));
+ output(p) = m.second() - m.first();
+ }
+
+ trace::exiting("morpho::impl::generic::gradient_elementary_");
+ return output;
+
+ }
+
+ } // end of namespace mln::internal::generic
+
+ } // end of namespace mln::internal
+
+
+ template <typename I, typename N>
+ mln_concrete(I)
+ gradient_elementary(const Image<I>& input_, const
Neighborhood<N>& nbh_)
+ {
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+
+ trace::entering("morpho::gradient_elementary");
+ mln_precondition(input.has_data());
+ // FIXME: mln_precondition(! nbh.is_empty());
+
+ mln_concrete(I) output =
impl::generic::gradient_elementary_(mln_trait_image_kind(I)(),
+ input, nbh);
+
+ trace::exiting("morpho::gradient_elementary");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_GRADIENT_ELEMENTARY_HH