URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-08 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Update color for image_if and subimage.
* color_sub.cc,
* color_sub.hh: Update, uncomment FIXME when level::paste ready.
Update chamfer.
* canvas_chamfer.hh: New.
* chamfer.cc,
* chamfer.hh: Update.
---
canvas_chamfer.hh | 98 ++++++++++++++++++++++++++
chamfer.cc | 27 +------
chamfer.hh | 197 ++++++++++++++++++++++++------------------------------
color_sub.cc | 8 +-
color_sub.hh | 19 ++---
5 files changed, 207 insertions(+), 142 deletions(-)
Index: trunk/milena/sandbox/duhamel/color_sub.cc
===================================================================
--- trunk/milena/sandbox/duhamel/color_sub.cc (revision 1265)
+++ trunk/milena/sandbox/duhamel/color_sub.cc (revision 1266)
@@ -54,10 +54,10 @@
{
using namespace mln;
- image2d_b<value::int_u8> ima(3,3);
+
+ image2d_b<value::int_u8> ima(10,10);
debug::iota(ima);
- std::cout << ima.domain() << std::endl;
- image2d_b<value::rgb8> out = color(inplace (ima | 6));
+ image2d_b<value::rgb8> out = color(inplace (ima | 50));
io::ppm::save(out, "out.ppm");
- debug::println(out);
+ // debug::println(out);
}
Index: trunk/milena/sandbox/duhamel/chamfer.cc
===================================================================
--- trunk/milena/sandbox/duhamel/chamfer.cc (revision 1265)
+++ trunk/milena/sandbox/duhamel/chamfer.cc (revision 1266)
@@ -1,34 +1,17 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/sub_image.hh>
#include <mln/core/image_if_value.hh>
-#include <mln/core/neighb2d.hh>
#include <mln/core/inplace.hh>
-#include <mln/value/int_u8.hh>
#include <mln/level/fill.hh>
-#include <mln/level/stretch.hh>
-#include <mln/io/pbm/load.hh>
-#include <mln/io/pgm/save.hh>
-#include <mln/io/pgm/save.hh>
-#include <mln/io/pgm/save.hh>
-#include <mln/core/mesh_image.hh>
-# include <mln/labeling/base.hh>
# include <mln/debug/println.hh>
-# include <mln/core/window2d.hh>
# include <mln/core/w_window2d_int.hh>
-# include <mln/convert/to_window.hh>
-# include <mln/core/concept/dpoint.hh>
-# include <mln/core/concept/neighborhood.hh>
-# include <mln/core/window.hh>
-# include <mln/pw/image.hh>
-# include <mln/pw/cst.hh>
-# include <mln/metal/is_a.hh>
-
+# include <mln/core/w_window2d_float.hh>
# include <mln/core/image_if_interval.hh>
+# include "win_chamfer.hh"
#include "chamfer.hh"
-
int main()
{
using namespace mln;
@@ -40,7 +23,7 @@
level::fill(ima, false);
ima.at(4,4) = true;
const w_window2d_int& w_win = win_chamfer::mk_chamfer_3x3_int<2, 0> ();
- image2d_b<unsigned> out = chamfer(ima, w_win, max);
+ image2d_b<unsigned> out = geom::chamfer(ima, w_win, max);
debug::println(out | value::interval(0, 8));
}
@@ -48,7 +31,7 @@
level::fill(ima, false);
ima.at(4,4) = true;
const w_window2d_int& w_win = win_chamfer::mk_chamfer_3x3_int<2, 3> ();
- image2d_b<unsigned> out = chamfer(ima, w_win, max);
+ image2d_b<unsigned> out = geom::chamfer(ima, w_win, max);
debug::println(out | value::interval(0, 8));
}
@@ -56,7 +39,7 @@
level::fill(ima, false);
ima.at(4,4) = true;
const w_window2d_int& w_win = win_chamfer::mk_chamfer_5x5_int<4, 6, 9> ();
- image2d_b<unsigned> out = chamfer(ima, w_win, max);
+ image2d_b<unsigned> out = geom::chamfer(ima, w_win, max);
image2d_b<unsigned>::fwd_piter p(out.domain());
for_all(p)
out(p) = out(p) / 2;
Index: trunk/milena/sandbox/duhamel/canvas_chamfer.hh
===================================================================
--- trunk/milena/sandbox/duhamel/canvas_chamfer.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/canvas_chamfer.hh (revision 1266)
@@ -0,0 +1,98 @@
+// 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_CANVAS_CHAMFER_HH
+# define MLN_CANVAS_CHAMFER_HH
+
+/*! \file mln/canvas/chamfer.hh
+ *
+ * \brief Connected component chamfer of the object part in a binary
+ * image.
+ */
+
+namespace mln
+{
+ namespace canvas
+ {
+
+ template <typename F>
+ struct chamfer
+ {
+ F& f;
+
+ typedef typename F::I I;
+ typedef typename F::W W;
+ typedef mln_point(I) point;
+
+ chamfer(F& f)
+ : f(f)
+ {
+ run();
+ }
+
+ void run()
+ {
+ /// Init.
+ {
+ f.init();
+ }
+
+ /// Fwd pass.
+ {
+ mln_fwd_piter(I) p(f.input.domain());
+ mln_qiter(W) q(f.win, p);
+
+ for_all(p) if (f.handles (p))
+ for_all(q) if (f.input.has(q))
+ if (f.output(q) != f.max
+ && f.output(q) + q.w() < f.output(p))
+ f.output(p) = f.output(q) + q.w();
+ }
+
+ /// Bkd pass.
+ {
+ W w_win_b = geom::sym(f.win);
+
+ mln_bkd_piter(I) p(f.input.domain());
+ mln_qiter(W) q(w_win_b, p);
+
+ for_all(p) if (f.handles (p))
+ for_all(q) if (f.input.has(q))
+ if (f.output(q) != f.max
+ && f.output(q) + q.w() < f.output(p))
+ f.output(p) = f.output(q) + q.w();
+ f.status = true;
+ }
+
+ }
+ };
+
+ } // end of mln::canvas
+
+} // end of mln
+
+#endif // ! MLN_CANVAS_CHAMFER_HH
Index: trunk/milena/sandbox/duhamel/color_sub.hh
===================================================================
--- trunk/milena/sandbox/duhamel/color_sub.hh (revision 1265)
+++ trunk/milena/sandbox/duhamel/color_sub.hh (revision 1266)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/sub_image.hh
+/*! \file ?/sub_image.hh
*
* \brief .
*/
@@ -34,30 +34,31 @@
#include <mln/core/image2d_b.hh>
#include <mln/value/rgb8.hh>
#include <mln/level/fill.hh>
+#include <mln/level/paste.hh>
+
+
+#include <mln/trait/image_from_mesh.hh>
namespace mln
{
+
template <typename I>
- mln_ch_value (I, value::rgb8)
+ typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret
color (const Image<I>& input_)
{
const I& input = exact (input_);
- mln_ch_value(I, value::rgb8) output;
- initialize(output, input);
-
- // image2d_b<value::rgb8> output(ima.domain ().bbox ());
-
+ image2d_b<value::rgb8> output(input.domain().bbox());
level::fill (output, value::rgb8(255, 0, 0));
+// /// FIXME by :
+// level::paste(input, output);
{
mln_piter(I) p (input.domain ());
for_all (p)
- {
output(p) = value::rgb8(input(p));
}
- }
return output;
}
}
Index: trunk/milena/sandbox/duhamel/chamfer.hh
===================================================================
--- trunk/milena/sandbox/duhamel/chamfer.hh (revision 1265)
+++ trunk/milena/sandbox/duhamel/chamfer.hh (revision 1266)
@@ -1,143 +1,126 @@
-# include <mln/core/image2d_b.hh>
-# include <mln/core/sub_image.hh>
-# include <mln/core/image_if_value.hh>
-# include <mln/core/neighb2d.hh>
-# include <mln/core/inplace.hh>
+// 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_CHAMFER_HH
+# define MLN_GEOM_CHAMFER_HH
+
+/*! \file mln/geom/chamfer.hh
+ *
+ * \brief Connected component chamfer of the image objects.
+ */
-# include <mln/value/int_u8.hh>
# include <mln/level/fill.hh>
-# include <mln/level/stretch.hh>
-# include <mln/io/pbm/load.hh>
-# include <mln/io/pgm/save.hh>
-# include <mln/io/pgm/save.hh>
-# include <mln/io/pgm/save.hh>
-# include <mln/core/mesh_image.hh>
-# include <mln/labeling/base.hh>
-# include <mln/debug/println.hh>
-# include <mln/core/window2d.hh>
# include <mln/core/w_window2d_int.hh>
# include <mln/core/w_window2d_float.hh>
-# include <mln/convert/to_window.hh>
-# include <mln/core/concept/dpoint.hh>
-# include <mln/core/concept/neighborhood.hh>
-# include <mln/core/window.hh>
-# include <mln/pw/image.hh>
-# include <mln/pw/cst.hh>
-# include <mln/metal/is_a.hh>
-
-# include <mln/core/image_if_interval.hh>
-# include <mln/core/dpoint2d.hh>
-# include <math.h>
+
+# include "canvas_chamfer.hh"
namespace mln
{
- namespace win_chamfer
- {
- template<int d10, int d11>
- const w_window2d_int
- mk_chamfer_3x3_int()
+ namespace geom
{
- int ws[] = { d11, d10, d11,
- d10, 0, 0,
- 0, 0, 0 };
- return (make::w_window2d(ws));
- }
- template<int d10, int d11, int d21>
- const w_window2d_int
- mk_chamfer_5x5_int()
- {
- int ws[] = { 0, d21, 0, d21, 0,
- d21, d11, d10, d11, d21,
- 0, d10, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0 };
+ template <typename I, typename W>
+ mln_ch_value( I, unsigned )
+ chamfer(const Image<I>& input_, const W& w_win_,
+ unsigned max = mln_max(unsigned));
+
- return (make::w_window2d(ws));
- }
+# ifndef MLN_INCLUDE_ONLY
- const w_window2d_float
- mk_chamfer_3x3_float(float d10, float d11)
+ namespace impl
{
- float ws[] = { d11, d10, d11,
- d10, 0, 0,
- 0, 0, 0 };
- return (make::w_window2d(ws));
- }
+ // Functors.
- const w_window2d_float
- mk_chamfer_5x5_float(float d10, float d11, float d21)
+ template <typename I_, typename W_>
+ struct chamfer_t
{
- float ws[] = { 0, d21, 0, d21, 0,
- d21, d11, d10, d11, d21,
- 0, d10, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0 };
+ typedef I_ I;
+ typedef W_ W;
+ typedef mln_point(I_) P;
- return (make::w_window2d(ws));
- }
+ // requirements from mln::canvas::chamfer:
- const w_window2d_float
- mk_chamfer_exact()
- {
- float r2 = sqrt(2);
- float ws[] = { r2, 1, r2,
- 1, 0, 0,
- 0, 0, 0 };
+ const I& input;
+ const W& win;
- return (make::w_window2d(ws));
- }
+ mln_ch_value(I_, unsigned) output;
+ bool status;
+ unsigned max;
+
+ void init() { initialize(output, exact(input));
+ level::fill(inplace(output | (input | true).domain()), 0);
+ level::fill(inplace(output | (input | false).domain()), max); }
+ bool handles(const P& p) const { return input(p) == false; }
+
+ // end of requirements
+
+ chamfer_t(const I_& input, const W_& win, unsigned max)
+ : input (input),
+ win (win),
+ max (max)
+ {}
+ };
- } // end of mln::win_chamfer
+ // Routines.
template <typename I, typename W>
mln_ch_value(I, unsigned)
- chamfer(const Image<I>& input_, const Weighted_Window<W>& w_win_,
+ chamfer_(const Image<I>& input_, const W& w_win_,
unsigned max = mln_max(unsigned))
{
- const I& input = exact(input_);
- const W& w_win = exact(w_win_);
+ typedef chamfer_t<I, W> F;
- mln_ch_value(I, unsigned) output;
- initialize(output, input);
-
- /// Init.
- {
- level::fill(inplace(output | (input | true).domain()), 0);
- level::fill(inplace(output | (input | false).domain()), max);
+ F f(exact(input_), exact(w_win_), max);
+ canvas::chamfer<F> run(f);
+ return f.output;
}
- /// Fwd pass.
- {
- mln_fwd_piter(I) p(input.domain());
- mln_qiter(W) q(w_win, p);
+ } // end of namespace mln::geom::impl
- for_all(p) if (input(p) == false)
- for_all(q) if (input.has(q))
- if (output(q) != max
- && output(q) + q.w() < output(p))
- output(p) = output(q) + q.w();
- }
-
- /// Bkd pass.
- {
+#endif // !MLN_INCLUDE_ONLY
- W w_win_b = geom::sym(w_win);
- mln_bkd_piter(I) p(input.domain());
- mln_qiter(W) q(w_win_b, p);
+ // Facade.
- for_all(p) if (input(p) == false)
- for_all(q) if (input.has(q))
- if (output(q) != max
- && output(q) + q.w() < output(p))
- output(p) = output(q) + q.w();
+ template <typename I, typename W>
+ mln_ch_value(I, unsigned)
+ chamfer(const Image<I>& input_, const W& w_win_,
+ unsigned max = mln_max(unsigned))
+ {
+ return impl::chamfer_(exact (input_), exact(w_win_), max);
}
- return output;
- }
-} // end of mln
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+#endif // !MLN_GEOM_CHAMFER_HH
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-08 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Fix line for -O3 -DNDEBUG compilation.
* mln/core/win/line.hh: Fix.
* sandbox/nivault/dyn_line.hh: Line with dynamic direction.
* sandbox/nivault/tests/pouet.cc: Test for the file above.
---
mln/core/win/line.hh | 9 +-
sandbox/nivault/dyn_line.hh | 183 +++++++++++++++++++++++++++++++++++++++++
sandbox/nivault/tests/pouet.cc | 49 ++++++++++
3 files changed, 237 insertions(+), 4 deletions(-)
Index: trunk/milena/mln/core/win/line.hh
===================================================================
--- trunk/milena/mln/core/win/line.hh (revision 1264)
+++ trunk/milena/mln/core/win/line.hh (revision 1265)
@@ -125,12 +125,13 @@
{
mln_precondition(i < M::dim);
mln_precondition(length % 2 == 1);
- const int dcol = length / 2;
- for (int col = - dcol; col <= dcol; ++col)
+ const int dc = length / 2;
+ for (int c = - dc; c <= dc; ++c)
{
dpoint n;
- n[i] = col;
- insert(n);
+ n.set_all(0);
+ n[i] = c;
+ this->insert(n);
}
}
Index: trunk/milena/sandbox/nivault/dyn_line.hh
===================================================================
--- trunk/milena/sandbox/nivault/dyn_line.hh (revision 0)
+++ trunk/milena/sandbox/nivault/dyn_line.hh (revision 1265)
@@ -0,0 +1,183 @@
+// 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_CORE_WIN_DYN_LINE_HH
+# define MLN_CORE_WIN_DYN_LINE_HH
+
+/*! \file mln/core/win/dyn_line.hh
+ *
+ * \brief Definition of the mln::win::dyn_line window.
+ */
+
+# include <mln/core/concept/window.hh>
+# include <mln/core/internal/dpoints_base.hh>
+# include <mln/core/dpoint.hh>
+# include <mln/core/dpoints_piter.hh>
+
+
+namespace mln
+{
+
+ namespace win
+ {
+
+ template <typename M, typename C>
+ struct dyn_line : public Window< dyn_line<M,C> >,
+ public internal::dpoints_base_<dpoint_<M, C>, point_<M, C> >
+ {
+ /// Point associated type.
+ typedef point_<M, int> point;
+
+ /// Dpoint associated type.
+ typedef dpoint_<M, int> dpoint;
+
+ /// Point_Iterator type to browse a dyn_line forward
+ typedef dpoints_fwd_piter<dpoint> fwd_qiter;
+
+ /// Point_Iterator type to browse a dyn_line backward
+ typedef dpoints_bkd_piter<dpoint> bkd_qiter;
+
+ /// Same as fwd_qiter
+ typedef fwd_qiter qiter;
+
+ /*! \brief Constructor.
+ *
+ * \param[in] length Length of the dyn_line.
+ *
+ * \pre \p length is odd.
+ */
+ dyn_line(unsigned length, unsigned direction);
+
+ /*! \brief Test if the window is centered.
+ *
+ * \return True.
+ */
+ bool is_centered() const;
+
+ /*! \brief Test if the window is symmetric.
+ *
+ * \return true.
+ */
+ bool is_symmetric() const;
+
+ /*! \brief Give the dyn_line length, that is, its width.
+ */
+ unsigned length() const;
+
+ /*! \brief Give the maximum coordinate gap between the window
+ * center and a window point.
+ */
+ unsigned delta() const;
+
+ /// Apply a central symmetry to the target window.
+ dyn_line<M,C>& sym();
+
+ protected:
+ unsigned length_;
+ };
+
+
+ /*! \brief Print an dyn_line window \p win into the output
+ * stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] win An dyn_line window.
+ *
+ * \return The modified output stream \p ostr.
+ *
+ * \relates mln::win::dyn_line
+ */
+ template <typename M, typename C>
+ std::ostream& operator<<(std::ostream& ostr, const dyn_line<M,C>& win);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename M, typename C>
+ dyn_line<M,C>::dyn_line(unsigned length, unsigned i)
+ : length_(length)
+ {
+ mln_precondition(i < M::dim);
+ mln_precondition(length % 2 == 1);
+ const int dc = length / 2;
+ for (int c = - dc; c <= dc; ++c)
+ {
+ dpoint n;
+ n.set_all(0);
+ n[i] = c;
+ this->insert(n);
+ }
+ }
+
+ template <typename M, typename C>
+ bool dyn_line<M,C>::is_centered() const
+ {
+ return true;
+ }
+
+ template <typename M, typename C>
+ bool dyn_line<M,C>::is_symmetric() const
+ {
+ return true;
+ }
+
+ template <typename M, typename C>
+ unsigned dyn_line<M,C>::length() const
+ {
+ return length_;
+ }
+
+ template <typename M, typename C>
+ unsigned dyn_line<M,C>::delta() const
+ {
+ return length_ / 2;
+ }
+
+ template <typename M, typename C>
+ dyn_line<M,C>& dyn_line<M,C>::sym()
+ {
+ return *this;
+ }
+
+ template <typename M, typename C>
+ std::ostream& operator<<(std::ostream& ostr, const dyn_line<M,C>& win)
+ {
+ ostr << "[dyn_line: length=" << win.length() << ']';
+ return ostr;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::win
+
+} // end of namespace mln
+
+
+
+#endif // ! MLN_CORE_WIN_DYN_LINE_HH
Index: trunk/milena/sandbox/nivault/tests/pouet.cc
===================================================================
--- trunk/milena/sandbox/nivault/tests/pouet.cc (revision 0)
+++ trunk/milena/sandbox/nivault/tests/pouet.cc (revision 1265)
@@ -0,0 +1,49 @@
+#include <mln/morpho/includes.hh>
+
+#include <mln/core/win/dyn_line.hh>
+#include <mln/core/win/hline2d.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/core/image2d_b.hh>
+
+#include <mln/level/paste.hh>
+
+#include <iostream>
+
+using namespace mln;
+
+
+template <typename W>
+void erosion_on_function(const image2d_b<value::int_u8>& input, const Window<W>& win_, image2d_b<value::int_u8>& output)
+{
+ const W& win = exact(win_);
+
+ accu::min_<value::int_u8> min;
+
+ mln_piter(image2d_b<value::int_u8>) p(input.domain());
+ mln_qiter(W) q(win, p);
+ for_all(p)
+ {
+ min.init();
+ for_all(q) if (input.has(q))
+ min.take(input(q));
+ output(p) = min.to_result();
+ }
+}
+
+
+int main()
+{
+// win::dyn_line<grid::square, int> h(17, 1);
+ win::hline2d h(17);
+
+ image2d_b<value::int_u8> lena = io::pgm::load("../../../img/lena.pgm");
+ image2d_b<value::int_u8> out(lena.domain());
+
+ erosion_on_function(lena, h, out);
+ //level::paste(lena, out);
+ io::pgm::save(out, "out.pgm");
+}
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-05 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add test for chamfer.
* chamfer.cc: Test for chamfer.
---
chamfer.cc | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
Index: trunk/milena/tests/chamfer.cc
===================================================================
--- trunk/milena/tests/chamfer.cc (revision 0)
+++ trunk/milena/tests/chamfer.cc (revision 1261)
@@ -0,0 +1,81 @@
+// 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/chamfer.cc
+ *
+ * \brief Tests on all files in mln/geom/chamfer.hh .
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/image_if_value.hh>
+#include <mln/core/inplace.hh>
+
+#include <mln/level/fill.hh>
+# include <mln/debug/println.hh>
+# include <mln/core/w_window2d_int.hh>
+# include <mln/core/w_window2d_float.hh>
+# include <mln/core/image_if_interval.hh>
+
+# include <mln/make/win_chamfer.hh>
+# include <mln/geom/chamfer.hh>
+
+int main()
+{
+ using namespace mln;
+ unsigned max = 51;
+
+ image2d_b<bool> ima(9, 9);
+
+ {
+ level::fill(ima, false);
+ ima.at(4,4) = true;
+ const w_window2d_int& w_win = win_chamfer::mk_chamfer_3x3_int<2, 0> ();
+ image2d_b<unsigned> out = geom::chamfer(ima, w_win, max);
+ debug::println(out | value::interval(0, 8));
+ }
+
+ {
+ level::fill(ima, false);
+ ima.at(4,4) = true;
+ const w_window2d_int& w_win = win_chamfer::mk_chamfer_3x3_int<2, 3> ();
+ image2d_b<unsigned> out = geom::chamfer(ima, w_win, max);
+ debug::println(out | value::interval(0, 8));
+ }
+
+ {
+ level::fill(ima, false);
+ ima.at(4,4) = true;
+ const w_window2d_int& w_win = win_chamfer::mk_chamfer_5x5_int<4, 6, 9> ();
+ image2d_b<unsigned> out = geom::chamfer(ima, w_win, max);
+ image2d_b<unsigned>::fwd_piter p(out.domain());
+ for_all(p)
+ out(p) = out(p) / 2;
+ debug::println(out | value::interval(0, 8));
+ }
+
+}
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-05 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add canvas for chamfer.
* canvas/chamfer.hh: New canvas for chamfer.
* geom/chamfer.hh: New.
* make/win_chamfer.hh: New.
---
canvas/chamfer.hh | 98 ++++++++++++++++++++++++++++++++++++++++
geom/chamfer.hh | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++
make/win_chamfer.hh | 69 ++++++++++++++++++++++++++++
3 files changed, 293 insertions(+)
Index: trunk/milena/mln/make/win_chamfer.hh
===================================================================
--- trunk/milena/mln/make/win_chamfer.hh (revision 0)
+++ trunk/milena/mln/make/win_chamfer.hh (revision 1260)
@@ -0,0 +1,69 @@
+# include <mln/core/w_window2d_int.hh>
+# include <mln/core/w_window2d_float.hh>
+# include <math.h>
+
+namespace mln
+{
+ namespace win_chamfer
+ {
+
+ template<int d10, int d11>
+ const w_window2d_int
+ mk_chamfer_3x3_int()
+ {
+ int ws[] = { d11, d10, d11,
+ d10, 0, 0,
+ 0, 0, 0 };
+
+ return (make::w_window2d(ws));
+ }
+
+ template<int d10, int d11, int d21>
+ const w_window2d_int
+ mk_chamfer_5x5_int()
+ {
+ int ws[] = { 0, d21, 0, d21, 0,
+ d21, d11, d10, d11, d21,
+ 0, d10, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0 };
+
+ return (make::w_window2d(ws));
+ }
+
+ const w_window2d_float
+ mk_chamfer_3x3_float(float d10, float d11)
+ {
+ float ws[] = { d11, d10, d11,
+ d10, 0, 0,
+ 0, 0, 0 };
+
+ return (make::w_window2d(ws));
+ }
+
+ const w_window2d_float
+ mk_chamfer_5x5_float(float d10, float d11, float d21)
+ {
+ float ws[] = { 0, d21, 0, d21, 0,
+ d21, d11, d10, d11, d21,
+ 0, d10, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0 };
+
+ return (make::w_window2d(ws));
+ }
+
+ const w_window2d_float
+ mk_chamfer_exact()
+ {
+ float r2 = sqrt(2);
+ float ws[] = { r2, 1, r2,
+ 1, 0, 0,
+ 0, 0, 0 };
+
+ return (make::w_window2d(ws));
+ }
+
+ } // end of mln::win_chamfer
+
+} // end of mln
Index: trunk/milena/mln/geom/chamfer.hh
===================================================================
--- trunk/milena/mln/geom/chamfer.hh (revision 0)
+++ trunk/milena/mln/geom/chamfer.hh (revision 1260)
@@ -0,0 +1,126 @@
+// 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_CHAMFER_HH
+# define MLN_GEOM_CHAMFER_HH
+
+/*! \file mln/geom/chamfer.hh
+ *
+ * \brief Connected component chamfer of the image objects.
+ */
+
+# include <mln/level/fill.hh>
+# include <mln/core/w_window2d_int.hh>
+# include <mln/core/w_window2d_float.hh>
+
+# include <mln/canvas/chamfer.hh>
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+
+ template <typename I, typename W>
+ mln_ch_value( I, unsigned )
+ chamfer(const Image<I>& input_, const W& w_win_,
+ unsigned max = mln_max(unsigned));
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Functors.
+
+ template <typename I_, typename W_>
+ struct chamfer_t
+ {
+ typedef I_ I;
+ typedef W_ W;
+ typedef mln_point(I_) P;
+
+ // requirements from mln::canvas::chamfer:
+
+ const I& input;
+ const W& win;
+
+ mln_ch_value(I_, unsigned) output;
+ bool status;
+ unsigned max;
+
+ void init() { initialize(output, exact(input));
+ level::fill(inplace(output | (input | true).domain()), 0);
+ level::fill(inplace(output | (input | false).domain()), max); }
+ bool handles(const P& p) const { return input(p) == false; }
+
+ // end of requirements
+
+ chamfer_t(const I_& input, const W_& win, unsigned max)
+ : input (input),
+ win (win),
+ max (max)
+ {}
+ };
+
+ // Routines.
+
+ template <typename I, typename W>
+ mln_ch_value(I, unsigned)
+ chamfer_(const Image<I>& input_, const W& w_win_,
+ unsigned max = mln_max(unsigned))
+ {
+ typedef chamfer_t<I, W> F;
+
+ F f(exact(input_), exact(w_win_), max);
+ canvas::chamfer<F> run(f);
+ return f.output;
+ }
+
+ } // end of namespace mln::geom::impl
+
+#endif // !MLN_INCLUDE_ONLY
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ mln_ch_value(I, unsigned)
+ chamfer(const Image<I>& input_, const W& w_win_,
+ unsigned max = mln_max(unsigned))
+ {
+ return impl::chamfer_(exact (input_), exact(w_win_), max);
+ }
+
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+#endif // !MLN_GEOM_CHAMFER_HH
Index: trunk/milena/mln/canvas/chamfer.hh
===================================================================
--- trunk/milena/mln/canvas/chamfer.hh (revision 0)
+++ trunk/milena/mln/canvas/chamfer.hh (revision 1260)
@@ -0,0 +1,98 @@
+// 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_CANVAS_CHAMFER_HH
+# define MLN_CANVAS_CHAMFER_HH
+
+/*! \file mln/canvas/chamfer.hh
+ *
+ * \brief Connected component chamfer of the object part in a binary
+ * image.
+ */
+
+namespace mln
+{
+ namespace canvas
+ {
+
+ template <typename F>
+ struct chamfer
+ {
+ F& f;
+
+ typedef typename F::I I;
+ typedef typename F::W W;
+ typedef mln_point(I) point;
+
+ chamfer(F& f)
+ : f(f)
+ {
+ run();
+ }
+
+ void run()
+ {
+ /// Init.
+ {
+ f.init();
+ }
+
+ /// Fwd pass.
+ {
+ mln_fwd_piter(I) p(f.input.domain());
+ mln_qiter(W) q(f.win, p);
+
+ for_all(p) if (f.handles (p))
+ for_all(q) if (f.input.has(q))
+ if (f.output(q) != f.max
+ && f.output(q) + q.w() < f.output(p))
+ f.output(p) = f.output(q) + q.w();
+ }
+
+ /// Bkd pass.
+ {
+ W w_win_b = geom::sym(f.win);
+
+ mln_bkd_piter(I) p(f.input.domain());
+ mln_qiter(W) q(w_win_b, p);
+
+ for_all(p) if (f.handles (p))
+ for_all(q) if (f.input.has(q))
+ if (f.output(q) != f.max
+ && f.output(q) + q.w() < f.output(p))
+ f.output(p) = f.output(q) + q.w();
+ f.status = true;
+ }
+
+ }
+ };
+
+ } // end of mln::canvas
+
+} // end of mln
+
+#endif // ! MLN_CANVAS_CHAMFER_HH