URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-11-22 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Review seeds2tiling and fix chamfer.
* mln/geom/seeds2tiling.hh: Add doc and tracing, fix typo and
update code.
* mln/geom/seeds2tiling_with_chamfer.hh: Remove ...
* mln/geom/seeds2tiling_roundness.hh: ... rename it and like
seeds2tiling.
* mln/geom/chamfer.hh,
* mln/canvas/chamfer.hh: Fix headers.
Tests
* tests/seed2tiling.cc: Update tests.
* tests/geom/seed2tiling.cc,
* tests/geom/seed2tiling_roundness.cc: New unit tests for these
algorithms.
---
mln/geom/chamfer.hh | 4 -
mln/geom/seeds2tiling.hh | 30 +++++++
mln/geom/seeds2tiling_roundness.hh | 144 ++++++++++++++++++++++++++++++++++++
tests/geom/seed2tiling.cc | 85 +++++++++++++++++++++
tests/geom/seed2tiling_roundness.cc | 90 ++++++++++++++++++++++
tests/seed2tiling.cc | 6 -
6 files changed, 355 insertions(+), 4 deletions(-)
Index: trunk/milena/tests/geom/seed2tiling_roundness.cc
===================================================================
--- trunk/milena/tests/geom/seed2tiling_roundness.cc (revision 0)
+++ trunk/milena/tests/geom/seed2tiling_roundness.cc (revision 1513)
@@ -0,0 +1,90 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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.
+
+/*! \file tests/geom/seed2tiling_roundness.cc
+ *
+ * \brief Tests on mln::geom::seed2tiling_roundness.
+ */
+
+# include <mln/core/image2d.hh>
+# include <mln/core/neighb2d.hh>
+# include <mln/core/w_window2d_int.hh>
+# include <mln/make/win_chamfer.hh>
+# include <mln/geom/seeds2tiling_roundness.hh>
+# include <mln/level/compare.hh>
+# include <mln/debug/println.hh>
+
+int main()
+{
+ using namespace mln;
+ unsigned max = 2048;
+ const w_window2d_int& w_win = make::mk_chamfer_3x3_int<2,3> ();
+
+ unsigned vs [16][16] = {
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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ima (make::image2d(vs));
+ image2d<unsigned> out = geom::seeds2tiling_roundness(ima, w_win, max, c4());
+ image2d<unsigned> ref (make::image2d(ws));
+
+ mln_assertion (ref == out);
+}
Index: trunk/milena/tests/geom/seed2tiling.cc
===================================================================
--- trunk/milena/tests/geom/seed2tiling.cc (revision 0)
+++ trunk/milena/tests/geom/seed2tiling.cc (revision 1513)
@@ -0,0 +1,85 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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.
+
+/*! \file tests/geom/seed2tiling.cc
+ *
+ * \brief Tests on mln::geom::seed2tiling.
+ */
+
+
+# include <mln/core/image2d.hh>
+# include <mln/core/neighb2d.hh>
+# include <mln/geom/seeds2tiling.hh>
+# include <mln/level/compare.hh>
+
+int main()
+{
+ using namespace mln;
+
+ unsigned vs [16][16] = {
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0,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2 ,2 ,2 ,2 ,2 ,2 ,2 ,2},
+ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,2 ,2 ,2 ,2 ,2 ,2 ,2},
+ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,2 ,2 ,2 ,2 ,2 ,2},
+ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,3 ,3 ,3 ,3 ,3 ,3},
+ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,3 ,3 ,3 ,3 ,3 ,3},
+ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,3 ,3 ,3 ,3 ,3 ,3 ,3},
+ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3},
+ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3},
+ {1 ,1 ,1 ,1 ,1 ,1 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3},
+ {1 ,1 ,1 ,1 ,1 ,1 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3},
+ {1 ,1 ,1 ,1 ,1 ,1 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3}
+ };
+
+ image2d<unsigned> ima (make::image2d(vs));
+ image2d<unsigned> out = geom::seeds2tiling(ima, c4());
+ image2d<unsigned> ref (make::image2d(ws));
+ mln_assertion (ref == out);
+}
Index: trunk/milena/tests/seed2tiling.cc
===================================================================
--- trunk/milena/tests/seed2tiling.cc (revision 1512)
+++ trunk/milena/tests/seed2tiling.cc (revision 1513)
@@ -44,7 +44,7 @@
# include <mln/debug/println.hh>
# include <mln/draw/mesh.hh>
# include <mln/geom/seeds2tiling.hh>
-# include <mln/geom/seeds2tiling_with_chamfer.hh>
+# include <mln/geom/seeds2tiling_roundness.hh>
# include <mln/make/voronoi.hh>
#include <mln/core/image2d.hh>
@@ -85,13 +85,13 @@
std::cout << "ima1 generate with seeds2tiling"
<< std::endl;
- inte = geom::seeds2tiling_with_chamfer(lab, w_win, max, c4 ());
+ inte = geom::seeds2tiling_roundness(lab, w_win, max, c4 ());
border::fill(inte, 0);
level::stretch(inte, inte2);
io::pgm::save(inte2, "ima2.pgm");
- std::cout << "ima2 generate with seeds2tiling_with_chamfer"
+ std::cout << "ima2 generate with seeds2tiling_roundness"
<< std::endl;
}
Index: trunk/milena/mln/geom/seeds2tiling_with_chamfer.hh (deleted)
===================================================================
Index: trunk/milena/mln/geom/seeds2tiling_roundness.hh
===================================================================
--- trunk/milena/mln/geom/seeds2tiling_roundness.hh (revision 0)
+++ trunk/milena/mln/geom/seeds2tiling_roundness.hh (revision 1513)
@@ -0,0 +1,144 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_GEOM_SEEDS2TILING_ROUNDNESS_HH
+# define MLN_GEOM_SEEDS2TILING_ROUNDNESS_HH
+
+/*! \file mln/geom/seeds2tiling_roundness.hh
+ *
+ * \brief seeds2tiling with a method which makes tiles more roundness.
+ */
+
+# include <map>
+
+
+# include <mln/core/p_priority_queue_fast.hh>
+# include <mln/core/clone.hh>
+# include <mln/accu/mean.hh>
+# include <mln/estim/min_max.hh>
+# include <mln/metal/vec.hh>
+# include <mln/geom/chamfer.hh>
+
+
+namespace mln
+{
+ namespace geom
+ {
+
+
+ /*! Take a labeled image \p ima_ with seeds and extend them until
+ * creating tiles nore roundness that the primary version.
+ *
+ * \param[in,out] ima The labeled image with seed.
+ * \param[in] win_w The weight window using by geom::chamfer to compute distance.
+ * \param[in] max Unsigned using by geom::chamfer to compute distance.
+ * \param[in] nbh The neighborhood to use on this algorithm.
+ *
+ * \pre \p ima has to be initialized.
+ *
+ */
+ template <typename I, typename N>
+ I
+ seeds2tiling_roundness (Image<I>& ima_, const w_window2d_int& w_win,
unsigned max,
+ const Neighborhood<N>& nbh);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I, typename N>
+ I
+ seeds2tiling_roundness(Image<I>& ima_, const w_window2d_int& w_win,
unsigned max,
+ const Neighborhood<N>& nbh)
+ {
+ trace::entering("geom::impl::seed2tiling_roundness");
+
+ I& ima = exact(ima_);
+ image2d<unsigned> dist = geom::chamfer(ima, w_win, max);
+ I out = clone(ima_);
+ p_priority_queue_fast<mln_psite(I), unsigned> q;
+
+ // Init.
+ {
+ mln_piter(I) p(ima.domain());
+
+ for_all(p)
+ q.push_force(p, max - dist(p));
+ }
+
+
+ // Body: alternative version.
+ {
+ while (! q.is_empty())
+ {
+ mln_psite(I) p = q.front();
+ q.pop();
+ if (out(p) != 0) // p has already been processed so ignore
+ continue;
+ mln_niter(N) n(nbh, p);
+
+ for_all(n) if (ima.has(n))
+ if (out(n) != 0)
+ out(p) = out(n);
+ }
+ }
+
+ trace::exiting("geom::impl::seed2tiling_roundness");
+ return out;
+ }
+
+ } // end of namespace mln::geom::impl
+
+
+ /// Facade
+ template <typename I, typename N>
+ I
+ seeds2tiling_roundness(Image<I>& ima_, const w_window2d_int& w_win,
unsigned max,
+ const Neighborhood<N>& nbh)
+ {
+ trace::entering("geom::seed2tiling_roundness");
+
+ mln_precondition(exact(ima_).has_data());
+ I output = impl::seeds2tiling_roundness(ima_, w_win, max, nbh);
+
+ trace::exiting("geom::seed2tiling_roundness");
+ return output;
+ }
+
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_SEEDS2TILING_ROUNDNESS_HH
Index: trunk/milena/mln/geom/seeds2tiling.hh
===================================================================
--- trunk/milena/mln/geom/seeds2tiling.hh (revision 1512)
+++ trunk/milena/mln/geom/seeds2tiling.hh (revision 1513)
@@ -47,17 +47,30 @@
namespace geom
{
+ /*! Take a labeled image \p ima_ with seeds and extend them
+ * until creating tiles.
+ *
+ * \param[in,out] ima The labeled image with seed.
+ * \param[in] nbh The neighborhood to use on this algorithm.
+ *
+ * \pre \p ima has to be initialized.
+ *
+ */
template <typename I, typename N>
I seeds2tiling (Image<I>& ima_, const Neighborhood<N>& nbh);
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
template <typename I, typename N>
I
seeds2tiling (Image<I>& ima_,
const Neighborhood<N>& nbh)
{
+ trace::entering("geom::impl::seed2tiling");
+
I& ima = exact(ima_);
I out = clone(ima_);
p_queue<mln_psite(I)> q;
@@ -94,9 +107,26 @@
}
}
+ trace::exiting("geom::impl::seed2tiling");
return out;
}
+ } // end of namespace mln::geom::impl
+
+
+ /// Facade
+ template <typename I, typename N>
+ I seeds2tiling(Image<I>& ima_, const Neighborhood<N>& nbh)
+ {
+ trace::entering("geom::seed2tiling");
+
+ mln_precondition(exact(ima_).has_data());
+ I output = impl::seeds2tiling(ima_, nbh);
+
+ trace::exiting("geom::seed2tiling");
+ return output;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/geom/chamfer.hh
===================================================================
--- trunk/milena/mln/geom/chamfer.hh (revision 1512)
+++ trunk/milena/mln/geom/chamfer.hh (revision 1513)
@@ -36,7 +36,9 @@
# include <mln/level/fill.hh>
# include <mln/core/w_window2d_int.hh>
# include <mln/core/w_window2d_float.hh>
-
+# include <mln/core/sub_image.hh>
+# include <mln/core/image_if_value.hh>
+# include <mln/core/inplace.hh>
# include <mln/canvas/chamfer.hh>
namespace mln
Index: trunk/milena/mln/canvas/chamfer.hh
===================================================================