URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-01-15 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
* mln/draw/box.hh: New, Add a routine to draw a box.
---
box.hh | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 100 insertions(+)
Index: trunk/milena/mln/draw/box.hh
===================================================================
--- trunk/milena/mln/draw/box.hh (revision 0)
+++ trunk/milena/mln/draw/box.hh (revision 1663)
@@ -0,0 +1,100 @@
+// Copyright (C) 2007,2008 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_DRAW_BOX_HH
+# define MLN_DRAW_BOX_HH
+
+/*! \file mln/draw/box.hh
+ *
+ * \brief Draw a box in an image.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/box2d.hh>
+# include <mln/level/paste.hh>
+# include <mln/draw/line.hh>
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
+
+
+namespace mln
+{
+
+ namespace draw
+ {
+
+ /*! Draw a box at value \p v in image \p ima
+ *
+ * \param[in,out] ima The image to be drawn.
+ * \param[in] b the boxto draw.
+ * \param[in] v The value to assign to all drawn pixels.
+ *
+ * \pre \p ima has to be initialized.
+ * \pre \p ima has \p beg.
+ * \pre \p ima has \p end.
+ *
+ */
+ template <typename I, typename B>
+ void box(Image<I>& ima,
+ const Box<B>& b,
+ const mln_value(I)& v);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename B>
+ inline
+ void box(Image<I>& ima,
+ const Box<B>& b,
+ const mln_value(I)& v)
+ {
+ mln_precondition(exact(ima).has_data());
+
+ mln_point(I) pmin = exact(b).pmin();
+ mln_point(I) pmax = exact(b).pmax();
+
+ mln_precondition(exact(ima).has(pmin) && exact(ima).has(pmax));
+
+ mln_point(I) p1 (pmin[0], pmin[1]);
+ mln_point(I) p2 (pmax[0], pmin[1]);
+ mln_point(I) p3 (pmin[0], pmax[1]);
+ mln_point(I) p4 (pmax[0], pmax[1]);
+
+ draw::line (ima, p1, p2, v);
+ draw::line (ima, p2, p4, v);
+ draw::line (ima, p4, p3, v);
+ draw::line (ima, p3, p1, v);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::draw
+
+} // end of namespace mln
+
+
+#endif // ! MLN_DRAW_BOX_HH
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-01-15 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add util::lemmings.
* mln/util/lemmings.hh: New.
* tests/util/Makefile.am: Add the following test.
* tests/util/lemmings.cc: New.
---
mln/util/lemmings.hh | 128 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/util/Makefile.am | 2
tests/util/lemmings.cc | 74 ++++++++++++++++++++++++++++
3 files changed, 204 insertions(+)
Index: trunk/milena/tests/util/lemmings.cc
===================================================================
--- trunk/milena/tests/util/lemmings.cc (revision 0)
+++ trunk/milena/tests/util/lemmings.cc (revision 1664)
@@ -0,0 +1,74 @@
+// 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/util/lemmings.cc
+ *
+ * \brief test of mln::util::lemmings
+ *
+ */
+
+#include <mln/util/lemmings.hh>
+#include <mln/core/image2d.hh>
+
+int main ()
+{
+ using namespace mln;
+
+ typedef image2d<int> I;
+
+ int vals[4][4] = {{2, 2, 6, 6},
+ {2, 2, 6, 6},
+ {3, 3, 4, 4},
+ {3, 3, 4, 4}};
+
+ I ima = make::image2d<int>(vals);
+
+ mln_point_(I) pt1(1, 0);
+ mln_point_(I) pt2(0, 2);
+ mln_point_(I) pt3(2, 3);
+ mln_point_(I) pt4(3, 1);
+ mln_point_(I) pt5(1, 1);
+
+ mln_value_(I) vl1 = ima(pt1);
+ mln_value_(I) vl2 = ima(pt2);
+ mln_value_(I) vl3 = ima(pt3);
+ mln_value_(I) vl4 = ima(pt4);
+ mln_value_(I) vl5 = ima(pt5);
+
+ mln_point_(I) ptl1 = util::lemmings(ima, ima.domain(), pt1, right, vl1);
+ mln_point_(I) ptl2 = util::lemmings(ima, ima.domain(), pt2, down, vl2);
+ mln_point_(I) ptl3 = util::lemmings(ima, ima.domain(), pt3, left, vl3);
+ mln_point_(I) ptl4 = util::lemmings(ima, ima.domain(), pt4, up, vl4);
+ mln_point_(I) ptl5 = util::lemmings(ima, ima.domain(), pt5, up, vl5);
+
+ mln_assertion(ptl1 == point2d(1, 2));
+ mln_assertion(ptl2 == point2d(2, 2));
+ mln_assertion(ptl3 == point2d(2, 1));
+ mln_assertion(ptl4 == point2d(1, 1));
+ mln_assertion(ptl5 == point2d(-1, 1));
+}
Index: trunk/milena/tests/util/Makefile.am
===================================================================
--- trunk/milena/tests/util/Makefile.am (revision 1663)
+++ trunk/milena/tests/util/Makefile.am (revision 1664)
@@ -9,6 +9,7 @@
eat \
graph \
lazy_set \
+ lemmings \
ordpair \
tree \
tree_fast \
@@ -21,6 +22,7 @@
eat_SOURCES = eat.cc
graph_SOURCES = graph.cc
lazy_set_SOURCES = lazy_set.cc
+lemmings_SOURCES = lemmings.cc
ordpair_SOURCES = ordpair.cc
tree_SOURCES = tree.cc
tree_fast_SOURCES = tree_fast.cc
Index: trunk/milena/mln/util/lemmings.hh
===================================================================
--- trunk/milena/mln/util/lemmings.hh (revision 0)
+++ trunk/milena/mln/util/lemmings.hh (revision 1664)
@@ -0,0 +1,128 @@
+// 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_UTIL_LEMMINGS_HH
+# define MLN_UTIL_LEMMINGS_HH
+
+/*! \file mln/util/lemmings.hh
+ *
+ * \brief Definition of an "lemmings" object.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/set/is_subset_of.hh>
+
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ /*! \brief Lemmings tool.
+ *
+ */
+ template <typename I>
+ struct lemmings_ : public Object< lemmings_<I> >
+ {
+ lemmings_(const Image<I>& ima, const mln_pset(I)& domain,
+ const mln_point(I)& pt, const mln_dpoint(I)& dpt,
+ const mln_value(I)& val);
+
+ mln_point(I) operator()();
+
+ const I& ima_;
+ const mln_pset(I)& domain_;
+ mln_point(I) pt_;
+ const mln_dpoint(I)& dpt_;
+ const mln_value(I)& val_;
+ };
+
+ /*! \brief Launch a lemmings on an image.
+ **
+ ** A lemmings is the point \p pt that you put on an image \p ima
+ ** . This point will move through the image using the delta-point
+ ** \p dpt while consider his value on the given image.
+ **
+ ** @return The first point that is not in the domain \p domain or
+ ** which value on the given image is different to the value \p
+ ** val.
+ **
+ ** \pre The domain \p domain must be contained in the domain of \p
+ ** ima.
+ */
+ template <typename I>
+ mln_point(I)
+ lemmings(const Image<I>& ima, const mln_pset(I)& domain,
+ const mln_point(I)& pt, const mln_dpoint(I)& dpt,
+ const mln_value(I)& val);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // lemmings
+
+ template <typename I>
+ inline
+ lemmings_<I>::lemmings_(const Image<I>& ima, const mln_pset(I)& domain,
+ const mln_point(I)& pt, const mln_dpoint(I)& dpt,
+ const mln_value(I)& val)
+ : ima_(exact(ima)),
+ domain_(domain),
+ pt_(pt),
+ dpt_(dpt),
+ val_(val)
+ {
+ mln_precondition(set::is_subset_of(domain, ima_.domain()));
+ }
+
+ template <typename I>
+ mln_point(I)
+ lemmings_<I>::operator()()
+ {
+ while (domain_.has(pt_) && ima_(pt_) == val_)
+ pt_ += dpt_;
+ return pt_;
+ }
+
+ template <typename I>
+ mln_point(I)
+ lemmings(const Image<I>& ima, const mln_pset(I)& domain,
+ const mln_point(I)& pt, const mln_dpoint(I)& dpt,
+ const mln_value(I)& val)
+ {
+ lemmings_<I> lm(ima, domain, pt, dpt, val);
+ return lm();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+
+#endif // ! MLN_UTIL_LEMMINGS_HH
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Speed up execution times of tests on the median operators.
* tests/tests.mk (LONG_TESTS_CXXFLAGS): New.
Set to -O3.
* tests/level/approx/Makefile.am, tests/level/naive/Makefile.am
(median_CXXFLAGS): New.
Set to $(LONG_TESTS_CXXFLAGS).
level/approx/Makefile.am | 10 ++++++++++
level/naive/Makefile.am | 10 ++++++++++
tests.mk | 8 ++++++--
3 files changed, 26 insertions(+), 2 deletions(-)
Index: tests/tests.mk
--- tests/tests.mk (revision 1658)
+++ tests/tests.mk (working copy)
@@ -8,7 +8,11 @@
#
# AM_CXXFLAGS = $(CXXFLAGS_STRICT) $(CXXFLAGS_DEBUG)
#
-# when oln.m4 is available in the distribution, instead of using the
-# hand-made TESTS_CXXFLAGS.
+# when oln.m4 (or just a part of it) is available in the distribution,
+# instead of using the hand-made TESTS_CXXFLAGS.
TESTS_CXXFLAGS = @TESTS_CXXFLAGS@
AM_CXXFLAGS = $(TESTS_CXXFLAGS)
+
+# FIXME: Likewise, we should compute these values at configure time.
+# Hard-code them for the moment.
+LONG_TESTS_CXXFLAGS = -O3
Index: tests/level/approx/Makefile.am
--- tests/level/approx/Makefile.am (revision 1658)
+++ tests/level/approx/Makefile.am (working copy)
@@ -6,5 +6,15 @@
median
median_SOURCES = median.cc
+# FIXME: The current median test is way too long to run. Break it
+# into two tests: a fast one, executed during `make check', compiled
+# with no optimization, using a small kernel and a small image; and a
+# second one, run during `make check-full', using a big kernel on a
+# normal image (e.g. Lena) and full optimization (`-O3').
+#
+# For the moment, we just have the second test. We run it during
+# target `check', but we shall move it to target `check-full' as soon
+# as a smaller and faster test is written.
+median_CXXFLAGS = $(LONG_TESTS_CXXFLAGS)
TESTS = $(check_PROGRAMS)
Index: tests/level/naive/Makefile.am
--- tests/level/naive/Makefile.am (revision 1658)
+++ tests/level/naive/Makefile.am (working copy)
@@ -6,5 +6,15 @@
median
median_SOURCES = median.cc
+# FIXME: The current median test is way too long to run. Break it
+# into two tests: a fast one, executed during `make check', compiled
+# with no optimization, using a small kernel and a small image; and a
+# second one, run during `make check-full', using a big kernel on a
+# normal image (e.g. Lena) and full optimization (`-O3').
+#
+# For the moment, we just have the second test. We run it during
+# target `check', but we shall move it to target `check-full' as soon
+# as a smaller and faster test is written.
+median_CXXFLAGS = $(LONG_TESTS_CXXFLAGS)
TESTS = $(check_PROGRAMS)
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-01-11 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add extract array example.
* sandbox/duhamel/extract_array.cc: New example of extract array.
---
extract_array.cc | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 149 insertions(+)
Index: trunk/milena/sandbox/duhamel/extract_array.cc
===================================================================
--- trunk/milena/sandbox/duhamel/extract_array.cc (revision 0)
+++ trunk/milena/sandbox/duhamel/extract_array.cc (revision 1656)
@@ -0,0 +1,149 @@
+// Copyright (C) 2007, 2008 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.
+
+# include <string>
+# include <mln/core/image2d.hh>
+# include <mln/io/pbm/load.hh>
+# include <mln/debug/println.hh>
+# include <mln/logical/not.hh>
+# include <mln/logical/or.hh>
+# include <mln/io/pbm/save.hh>
+# include <mln/io/pbm/load.hh>
+# include <mln/io/ppm/save.hh>
+# include <mln/io/pgm/save.hh>
+
+# include <mln/morpho/erosion.hh>
+# include <mln/morpho/dilation.hh>
+# include <mln/make/w_window2d.hh>
+# include <mln/win/rectangle2d.hh>
+# include <mln/win/vline2d.hh>
+# include <mln/win/hline2d.hh>
+# include <mln/level/fill.hh>
+# include <mln/literal/all.hh>
+# include <mln/value/rgb8.hh>
+
+
+using namespace mln;
+
+template <typename I, typename W>
+mln_concrete(I)
+pseudo(const I& input, const W& win, const float ratio)
+{
+ I output = clone (input);
+ unsigned ko = win.length () - (unsigned)(ratio * win.length ());
+ std::cout << "ko : " << ko << std::endl;
+ mln_pixter(const I) p(input);
+ mln_pixter(I) p_out(output);
+ mln_qixter(const I, W) q(p, win);
+
+ for_all_2(p, p_out)
+ {
+ unsigned cpt = 0;
+
+ for_all(q)
+ {
+ if (! q.val ())
+ {
+ if (++cpt > ko)
+ break;
+ }
+ }
+ p_out.val() = (cpt <= ko);
+ }
+ return output;
+}
+
+template <typename I, typename J>
+void
+draw_array(I input, J image_bool)
+{
+ mln_piter(I) p (input.domain ());
+
+ for_all(p)
+ {
+ if (image_bool(p))
+ input(p) = literal::red;
+ }
+}
+
+
+int
+main(int argc, char** argv)
+{
+ using value::int_u8;
+ using value::rgb8;
+
+ typedef point2d P;
+ typedef image2d<bool> I;
+ typedef image2d<unsigned> I_LABEL;
+ typedef image2d<value::rgb8> O;
+
+ if (argc != 3)
+ {
+ std::cerr << "Usage : " << argv[0]
+ << " input.pbm output" << std::endl;
+ exit(1);
+ }
+
+ std::string path_input = argv[1];
+ std::string path_output = argv[2];
+
+
+ I input = io::pbm::load (path_input);
+ O output (input.domain ());
+
+ /// Inversion video.
+ I inv_image = logical::not_(input);
+
+
+ mln_piter_(I) p (input.domain());
+
+ for_all(p)
+ {
+ if (inv_image(p))
+ output(p) = literal::black;
+ else
+ output(p) = literal::white;
+ }
+
+
+ /// Extract horizontal axis of array.
+ win::hline2d h_line(51);
+ I h_axis_image = pseudo(inv_image, h_line, 0.7);
+ h_axis_image = morpho::erosion(h_axis_image, h_line);
+ draw_array(output, h_axis_image);
+
+ /// Extract vertical axis of array.
+ win::vline2d v_line(11);
+ I v_axis_image = pseudo(inv_image, v_line, 0.75);
+ v_axis_image = morpho::erosion(v_axis_image, v_line);
+ draw_array(output, v_axis_image);
+
+ io::ppm::save (output, path_output + ".ppm");
+ std::cout << path_output + ".ppm generated" << std::endl;
+}
+