* mln/data/compute_in_inner_border.hh,
* tests/data/compute_in_inner_border.cc: New.
* tests/data/Makefile.am: New target.
---
milena/ChangeLog | 9 +
milena/mln/data/compute_in_inner_border.hh | 184 ++++++++++++++++++++
milena/tests/data/Makefile.am | 2 +
.../compute_in_inner_border.cc} | 28 ++--
4 files changed, 211 insertions(+), 12 deletions(-)
create mode 100644 milena/mln/data/compute_in_inner_border.hh
copy milena/tests/{core/image/vmorph/fun_image.cc => data/compute_in_inner_border.cc}
(75%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 5b58c66..2413cb2 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,14 @@
2012-10-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add data::compute_in_inner_border.
+
+ * mln/data/compute_in_inner_border.hh,
+ * tests/data/compute_in_inner_border.cc: New.
+
+ * tests/data/Makefile.am: New target.
+
+2012-10-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* mln/world/kn/safe_cast.hh: Add more conversions.
2012-10-23 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/milena/mln/data/compute_in_inner_border.hh
b/milena/mln/data/compute_in_inner_border.hh
new file mode 100644
index 0000000..20e8a37
--- /dev/null
+++ b/milena/mln/data/compute_in_inner_border.hh
@@ -0,0 +1,184 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// 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,
+// 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_DATA_COMPUTE_IN_INNER_BORDER_HH
+# define MLN_DATA_COMPUTE_IN_INNER_BORDER_HH
+
+/// \file
+///
+/// Compute an accumulator onto the inner border pixel values.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/accumulator.hh>
+# include <mln/geom/nrows.hh>
+# include <mln/geom/ncols.hh>
+
+namespace mln
+{
+
+ namespace data
+ {
+
+ /// Compute an accumulator onto the inner border pixel values of
+ /// the image \p input. Be ware that the given accumulator won't
+ /// be modified and won't store any result.
+ ///
+ /// \param[in] a An accumulator.
+ /// \param[in] input The input image.
+ /// \param[in] inner_border_thickness The inner border thickness
+ /// considered.
+ /// \return The accumulator result.
+ ///
+ /// It fully relies on data::update.
+ //
+ template <typename A, typename I>
+ mln_result(A)
+ compute_in_inner_border(const Accumulator<A>& a, const Image<I>&
input,
+ unsigned inner_border_thickness);
+
+
+ /// Compute an accumulator onto the inner border pixel values of
+ /// the image \p input.
+ ///
+ /// \param[in, out] a An accumulator.
+ /// \param[in] input The input image.
+ /// \param[in] inner_border_thickness The inner border thickness
+ /// considered.
+ /// \return The accumulator result.
+ ///
+ /// It fully relies on data::update.
+ //
+ template <typename A, typename I>
+ mln_result(A)
+ compute_in_inner_border(Accumulator<A>& a, const Image<I>&
input,
+ unsigned inner_border_thickness);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename A, typename I>
+ mln_result(A)
+ compute_in_inner_border(const Accumulator<A>& a_, const Image<I>&
input,
+ unsigned inner_border_thickness)
+ {
+ (void) a_;
+ A a;
+ return compute_in_inner_border(a, input, inner_border_thickness);
+ }
+
+
+ template <typename A, typename I>
+ mln_result(A)
+ compute_in_inner_border(Accumulator<A>& a_, const Image<I>&
input_,
+ unsigned inner_border_thickness)
+ {
+ trace::entering("mln::data::compute_in_inner_border");
+ mln_precondition(exact(input_).is_valid());
+ mln_precondition(inner_border_thickness > 0);
+ mln_precondition(geom::nrows(input_) >= inner_border_thickness);
+ mln_precondition(geom::ncols(input_) >= inner_border_thickness);
+
+ A a = exact(a_);
+ const I& input = exact(input_);
+
+ a.init();
+
+ unsigned inner_border_thickness_1 = inner_border_thickness - 1;
+ unsigned nrows_1 = geom::nrows(input) - 1;
+ unsigned ncols_1 = geom::ncols(input) - 1;
+
+ typedef mln_box(I) B;
+
+ /*
+ .--------------------.
+ | b_top |<------ Image domain
+ |--------------------|
+ | | | |
+ |b| |b|
+ | | | |
+ |l| |r|
+ |e| |i|
+ |f| |g|
+ |t| |h|
+ | | |t|
+ |--------------------|
+ | b_bot |
+ .--------------------.
+
+ */
+ B b_top = B(input.domain().pmin(),
+ input.domain().pmin()
+ + inner_border_thickness_1 * down
+ + ncols_1 * right);
+ mln_piter(I) p_top(b_top);
+
+ B b_bot = B(input.domain().pmax()
+ + inner_border_thickness_1 * up
+ + ncols_1 * left,
+ input.domain().pmax());
+ mln_piter(I) p_bot(b_bot);
+
+ B b_left = B(input.domain().pmin()
+ + inner_border_thickness * down,
+ input.domain().pmin()
+ + inner_border_thickness_1 * right
+ + (nrows_1 - inner_border_thickness) * down);
+ mln_piter(I) p_left(b_left);
+
+ B b_right = B(input.domain().pmax()
+ + inner_border_thickness_1 * left
+ + (nrows_1 - inner_border_thickness) * up,
+ input.domain().pmax()
+ + inner_border_thickness * up);
+ mln_piter(I) p_right(b_right);
+
+ mln_assertion(b_right.nsites() == b_left.nsites());
+ mln_assertion(b_top.nsites() == b_bot.nsites());
+
+ for_all_2(p_top, p_bot)
+ {
+ a.take(input(p_top));
+ a.take(input(p_bot));
+ }
+
+ for_all_2(p_left, p_right)
+ {
+ a.take(input(p_left));
+ a.take(input(p_right));
+ }
+
+ trace::exiting("mln::data::compute_in_inner_border");
+ return a;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::data
+
+} // end of namespace mln
+
+#endif // ! MLN_DATA_COMPUTE_IN_INNER_BORDER_HH
diff --git a/milena/tests/data/Makefile.am b/milena/tests/data/Makefile.am
index 4b04dfb..38eaa30 100644
--- a/milena/tests/data/Makefile.am
+++ b/milena/tests/data/Makefile.am
@@ -24,6 +24,7 @@ check_PROGRAMS = \
compare \
compute \
compute_in_window \
+ compute_in_inner_border \
convert \
fill \
fill_with_image \
@@ -47,6 +48,7 @@ apply_SOURCES = apply.cc
compare_SOURCES = compare.cc
compute_SOURCES = compute.cc
compute_in_window_SOURCES = compute_in_window.cc
+compute_in_inner_border_SOURCES = compute_in_inner_border.cc
convert_SOURCES = convert.cc
fill_SOURCES = fill.cc
fill_with_image_SOURCES = fill_with_image.cc
diff --git a/milena/tests/core/image/vmorph/fun_image.cc
b/milena/tests/data/compute_in_inner_border.cc
similarity index 75%
copy from milena/tests/core/image/vmorph/fun_image.cc
copy to milena/tests/data/compute_in_inner_border.cc
index 673c391..da73bd2 100644
--- a/milena/tests/core/image/vmorph/fun_image.cc
+++ b/milena/tests/data/compute_in_inner_border.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,24 +24,28 @@
// executable file might be covered by the GNU General Public License.
#include <mln/core/image/image2d.hh>
-#include <mln/core/image/vmorph/fun_image.hh>
-#include <mln/data/compare.hh>
+#include <mln/data/compute_in_inner_border.hh>
#include <mln/debug/iota.hh>
-#include <mln/fun/v2v/inc.hh>
-
-
+#include <mln/accu/stat/mean.hh>
int main()
{
using namespace mln;
-
- image2d<int> ima(2, 2);
+ image2d<int> ima(10, 10);
debug::iota(ima);
- int vals[] = { 2, 3,
- 4, 5 };
+ {
+ accu::stat::mean<int> m;
+ float mean = data::compute_in_inner_border(m, ima, 1);
+ mln_assertion(mean == 50.5);
+ }
+
+ {
+ accu::stat::mean<int> m;
+ float mean = data::compute_in_inner_border(m, ima, 2);
+ mln_assertion(mean == 50.5);
+ }
+
- fun::v2v::inc<int> f;
- mln_assertion((f << ima) == make::image2d(vals));
}
--
1.7.2.5