It seems ESIEE's mail server is preventing me from sending this
message today. So I'm sending it by hand. Hope it won't look too
much ugly, given the fact I'm sending it with Apple Mail (no troll
intended).
Hope ESIEE's mail server will return to a sound behavior soon, too...
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add a new test on WST-based segmentation on a line graph image.
* tests/core/lena_line_graph_image_wst.cc: Rename and move...
* tests/morpho/lena_line_graph_image_wst1.cc: ...here.
Add more documentation.
Remove dead code.
* tests/morpho/lena_line_graph_image_wst2.cc: New test.
Based on tests/morpho/lena_line_graph_image_wst1.cc.
* tests/core/Makefile.am (check_PROGRAMS): Remove
lena_line_graph_image_wst.
(lena_line_graph_image_wst_SOURCES)
(lena_line_graph_image_wst_CXXFLAGS):
Remove.
* tests/morpho/Makefile.am (check_PROGRAMS): Add
lena_line_graph_image_wst1 and lena_line_graph_image_wst2.
(CXXFLAGS_SPEED): New.
Use it...
(meyer_wst_long_CXXFLAGS): ...here.
(lena_line_graph_image_wst1_SOURCES)
(lena_line_graph_image_wst1_CXXFLAGS)
(lena_line_graph_image_wst2_SOURCES)
(lena_line_graph_image_wst2_CXXFLAGS):
New.
* mln/core/line_graph_image.hh: More FIXME.
* tests/morpho/hit_or_miss.cc, tests/morpho/meyer_wst_long.cc:
Remove unnecessary #include's.
mln/core/line_graph_image.hh | 4 +
tests/core/Makefile.am | 5 -
tests/morpho/Makefile.am | 13 +++-
tests/morpho/hit_or_miss.cc | 1
tests/morpho/lena_line_graph_image_wst1.cc | 28 ++++++---
tests/morpho/lena_line_graph_image_wst2.cc | 84 +++++++++++++++++++
+---------
tests/morpho/meyer_wst_long.cc | 2
7 files changed, 94 insertions(+), 43 deletions(-)
Index: tests/morpho/lena_line_graph_image_wst1.cc
--- tests/morpho/lena_line_graph_image_wst1.cc (revision 1736)
+++ tests/morpho/lena_line_graph_image_wst1.cc (working copy)
@@ -25,8 +25,26 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/core/line_graph_image.cc
-/// \brief Tests on the Watershed Transform on a mln::line_graph_image.
+/* FIXME: We should factor as much things as possible between
+ tests/core/lena_line_graph_image_wst1.cc and
+ tests/core/lena_line_graph_image_wst2.cc, starting from conversion
+ routines. */
+
+/** \file tests/core/lena_line_graph_image_wst1.cc
+ \brief Tests on the Watershed Transform (WST) on a
mln::line_graph_image.
+
+ The scenario is as follows:
+ \li load a 2-D, gray-level image from a PGM file;
+ \li compute a morphological gradient of this image;
+ \li simplify the image to reduce the number of local minima;
+ \li convert this 2-D image into a line graph-based one, where
values
+ on edges are computed as the maxmimum of the values on the
nodes
+ adjacent to the edge;
+ \li perform a WST on the line graph image;
+ \li create an 2-D, color output image with height and width double
+ the size the original one, and copy the data of the input image
+ in it, interpolating inter-pixel points;
+ \li print the watershed on lines into that same image, and save
it. */
#include <vector>
@@ -44,7 +62,6 @@
#include <mln/morpho/meyer_wst.hh>
#include <mln/value/int_u8.hh>
-// #include <mln/value/int_u16.hh>
#include <mln/value/rgb8.hh>
#include <mln/literal/black.hh>
#include <mln/literal/colors.hh>
@@ -63,7 +80,6 @@
{
using namespace mln;
using value::int_u8;
-// using value::int_u16;
using value::rgb8;
/*--------.
@@ -72,7 +88,6 @@
typedef int_u8 input_val_t;
image2d<input_val_t> input;
-// io::pgm::load(input, MLN_IMG_DIR "/small.pgm");
io::pgm::load(input, MLN_IMG_DIR "/tiny.pgm");
/* FIXME: Don't compute a gradient on the image2d input. Instead,
@@ -85,7 +100,6 @@
// Simplify the input image.
image2d<input_val_t> work(input.domain());
-// morpho::closing_area(gradient, c4(), 50, work);
morpho::closing_area(gradient, c4(), 10, work);
/*-------------.
@@ -128,7 +142,6 @@
if (work.has(q))
{
g.add_edge(points[p], points[q]);
- // FIXME: Keep this valuation function?
edge_values.push_back(math::max(work(p), work(q)));
}
@@ -183,7 +196,6 @@
}
// Interpolate missing points in OUTPUT.
mln_piter_(output_t) p_out(output.domain());
-// mln_niter_(neighb2d) n_out(c4(), p_out);
for_all(p_out)
{
// Process points on even rows and odd columns
Index: tests/morpho/lena_line_graph_image_wst2.cc
--- tests/morpho/lena_line_graph_image_wst2.cc (revision 1736)
+++ tests/morpho/lena_line_graph_image_wst2.cc (working copy)
@@ -25,8 +25,32 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/core/line_graph_image.cc
-/// \brief Tests on the Watershed Transform on a mln::line_graph_image.
+/* FIXME: We should factor as much things as possible between
+ tests/core/lena_line_graph_image_wst1.cc and
+ tests/core/lena_line_graph_image_wst2.cc, starting from conversion
+ routines. */
+
+/** \file tests/core/lena_line_graph_image_wst2.cc
+ \brief More tests on the Watershed Transform (WST) on a
+ mln::line_graph_image.
+
+
+ The scenario is as follows:
+ \li load a 2-D, gray-level image from a PGM file;
+ \li simplify the image to reduce the number of local minima;
+ \li convert this 2-D image into a line graph-based one, where
values
+ on edges are computed as the absolute value f the difference
+ between the values on the nodes adjacent to the edge, so as to
+ create a (norm of the gradient) ``between the pixels'' of the
+ input image;
+ \li (insert an minima-killer pass here, as soon as it works on
+ graph-based images);
+ \li perform a WST on the line graph image;
+ \li reduce the quantification of the result of the WST;
+ \li create an 2-D, color output image with height and width double
+ the size the original one, and copy the data of the input image
+ in it, interpolating inter-pixel points;
+ \li print the watershed on lines into that same image, and save
it. */
#include <vector>
@@ -42,9 +66,10 @@
#include <mln/morpho/gradient.hh>
#include <mln/morpho/closing_area.hh>
#include <mln/morpho/meyer_wst.hh>
+#include <mln/level/stretch.hh>
#include <mln/value/int_u8.hh>
-// #include <mln/value/int_u16.hh>
+#include <mln/value/int_u16.hh>
#include <mln/value/rgb8.hh>
#include <mln/literal/black.hh>
#include <mln/literal/colors.hh>
@@ -63,7 +88,7 @@
{
using namespace mln;
using value::int_u8;
-// using value::int_u16;
+ using value::int_u16;
using value::rgb8;
/*--------.
@@ -72,21 +97,15 @@
typedef int_u8 input_val_t;
image2d<input_val_t> input;
-// io::pgm::load(input, MLN_IMG_DIR "/small.pgm");
- io::pgm::load(input, MLN_IMG_DIR "/tiny.pgm");
+ io::pgm::load(input, MLN_IMG_DIR "/small.pgm");
- /* FIXME: Don't compute a gradient on the image2d input. Instead,
- have the values of the line graph image /behaves/ as the gradient
- of the input, i.e., edges should hold the absolute difference
- between gray levels.
- */
- image2d<input_val_t> gradient =
- morpho::gradient (input, convert::to_window(c4()));
+ /* FIXME: In fact, we'd probably want to compute the gradient
+ /before/ simplfying the image, but as the area closing doesn't
+ work (yet) on graph images, hence we cannot do this yet. */
// Simplify the input image.
image2d<input_val_t> work(input.domain());
-// morpho::closing_area(gradient, c4(), 50, work);
- morpho::closing_area(gradient, c4(), 10, work);
+ morpho::closing_area(input, c8(), 500, work);
/*-------------.
| Line graph. |
@@ -105,7 +124,7 @@
util::node_id id = 0;
// Nodes.
- std::vector<int> node_values;
+ std::vector<input_val_t> node_values;
mln_fwd_piter_(image2d<input_val_t>) p(work.domain());
for_all (p)
{
@@ -121,26 +140,32 @@
// Edges.
window2d next_c4_win;
next_c4_win.insert(0, 1).insert(1, 0);
- std::vector<int> edge_values;
+ std::vector<input_val_t> edge_values;
mln_fwd_qiter_(window2d) q(next_c4_win, p);
for_all (p)
for_all (q)
if (work.has(q))
{
g.add_edge(points[p], points[q]);
- // FIXME: Keep this valuation function?
- edge_values.push_back(math::max(work(p), work(q)));
+ // The computed value is a kind of norm of the gradient
+ // bewteen P and Q.
+ edge_values.push_back(math::abs(work(p) - work(q)));
}
// Line graph point set.
p_line_graph<point2d> plg(g);
// Line graph image.
- /* FIXME: Shouldn't we use `input_val_t' instead of plain `int' as
value
- type here? */
- typedef line_graph_image<point2d, int> ima_t;
+ typedef line_graph_image<point2d, input_val_t> ima_t;
ima_t lg_ima(plg, node_values, edge_values);
+ /*-----------------.
+ | Simplification. |
+ `-----------------*/
+
+ // FIXME: Adjust the area closing filter, so that we can apply it on
+ // graph images.
+
/*------.
| WST. |
`------*/
@@ -149,11 +174,20 @@
nbh_t nbh;
// Perform a Watershed Transform.
+ typedef int_u16 wst_full_val_t;
+ wst_full_val_t nbasins;
+ typedef line_graph_image<point2d, wst_full_val_t> wst_full_ima_t;
+ wst_full_ima_t wshed_full = morpho::meyer_wst(lg_ima, nbh, nbasins);
+ std::cout << "nbasins = " << nbasins << std::endl;
+
+ // Reduce the value set to 8-bit.
typedef int_u8 wst_val_t;
- wst_val_t nbasins;
typedef line_graph_image<point2d, wst_val_t> wst_ima_t;
- wst_ima_t wshed = morpho::meyer_wst(lg_ima, nbh, nbasins);
- std::cout << "nbasins = " << nbasins << std::endl;
+ // FIXME: Initializations should not be that complicated.
+ wst_ima_t wshed (plg,
+ std::vector<wst_val_t>(node_values.size()),
+ std::vector<wst_val_t>(edge_values.size()));
+ level::stretch(wshed_full, wshed);
/*---------.
| Output. |
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 1736)
+++ tests/core/Makefile.am (working copy)
@@ -10,7 +10,6 @@
initialize \
graph_elt_window \
graph_image \
- lena_line_graph_image_wst \
line_graph_elt_window \
line_graph_image \
line_graph_image_wst \
@@ -52,8 +51,4 @@
t_image_SOURCES = t_image.cc
tr_image_SOURCES = tr_image.cc
-# FIXME: We should isolate this test, as it takes a long time.
-lena_line_graph_image_wst_SOURCES = lena_line_graph_image_wst.cc
-lena_line_graph_image_wst_CXXFLAGS = -O3 -ggdb
-
TESTS = $(check_PROGRAMS)
Index: tests/morpho/Makefile.am
--- tests/morpho/Makefile.am (revision 1736)
+++ tests/morpho/Makefile.am (working copy)
@@ -12,6 +12,8 @@
gradient \
hit_or_miss \
laplacian \
+ lena_line_graph_image_wst1 \
+ lena_line_graph_image_wst2 \
meyer_wst \
meyer_wst_long \
opening_area \
@@ -33,8 +35,15 @@
thinning_SOURCES = thinning.cc
meyer_wst_SOURCES = meyer_wst.cc
-# FIXME: We should isolate this test, as it takes a long time.
+
+# FIXME: We should isolate those tests, as they take a long time to
+# execute.
+CXXFLAGS_SPEED = -O3 -ggdb
+lena_line_graph_image_wst1_SOURCES = lena_line_graph_image_wst1.cc
+lena_line_graph_image_wst1_CXXFLAGS = $(CXXFLAGS_SPEED)
+lena_line_graph_image_wst2_SOURCES = lena_line_graph_image_wst2.cc
+lena_line_graph_image_wst2_CXXFLAGS = $(CXXFLAGS_SPEED)
meyer_wst_long_SOURCES = meyer_wst_long.cc
-meyer_wst_long_CXXFLAGS = -O3 -ggdb
+meyer_wst_long_CXXFLAGS = $(CXXFLAGS_SPEED)
TESTS = $(check_PROGRAMS)
Index: mln/core/line_graph_image.hh
--- mln/core/line_graph_image.hh (revision 1736)
+++ mln/core/line_graph_image.hh (working copy)
@@ -191,6 +191,10 @@
| Initialization. |
`-----------------*/
+ /* FIXME: We should check the expected behavior of init_ here. As
+ far as I (Roland) can recall, it was not meant to initialize
+ data/values. We should probably just create vectors of values of
+ the same size, not copy the values. */
template <typename P, typename V>
inline
void init_(tag::image_t,
Index: tests/morpho/hit_or_miss.cc
--- tests/morpho/hit_or_miss.cc (revision 1736)
+++ tests/morpho/hit_or_miss.cc (working copy)
@@ -41,7 +41,6 @@
#include <mln/io/pbm/load.hh>
#include <mln/io/pbm/save.hh>
#include <mln/level/fill.hh>
-#include <mln/level/stretch.hh>
#include <mln/morpho/hit_or_miss.hh>
Index: tests/morpho/meyer_wst_long.cc
--- tests/morpho/meyer_wst_long.cc (revision 1736)
+++ tests/morpho/meyer_wst_long.cc (working copy)
@@ -35,8 +35,6 @@
#include <mln/core/window2d.hh>
#include <mln/core/neighb2d.hh>
-#include <mln/level/stretch.hh>
-
#include <mln/value/int_u8.hh>
#include <mln/value/int_u16.hh>
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-02-18 Michel Pellegrin <pellegrin(a)lrde.epita.fr>
Work on conditional inheritance done.
* sandbox/pellegrin/cond_inheritance: Folder containing my work.
* sandbox/pellegrin/cond_inheritance/Makefile: Compile the test.
* sandbox/pellegrin/cond_inheritance/concept: New.
* sandbox/pellegrin/cond_inheritance/concept/point_set.hh: New.
* sandbox/pellegrin/cond_inheritance/internal: New.
* sandbox/pellegrin/cond_inheritance/internal/multi_set.hh: New.
* sandbox/pellegrin/cond_inheritance/internal/point_set_base.hh: New.
* sandbox/pellegrin/cond_inheritance/internal/uni_set.hh: New.
* sandbox/pellegrin/cond_inheritance/p_array.hh: Definition of a
p_array.
* sandbox/pellegrin/cond_inheritance/p_set.hh: Definition of a p_set.
* sandbox/pellegrin/cond_inheritance/test_cond_inherit.cc: Test file.
---
Makefile | 26 ++++++++++++
concept/point_set.hh | 72 +++++++++++++++++++++++++++++++++
internal/multi_set.hh | 72 +++++++++++++++++++++++++++++++++
internal/point_set_base.hh | 97 +++++++++++++++++++++++++++++++++++++++++++++
internal/uni_set.hh | 70 ++++++++++++++++++++++++++++++++
p_array.hh | 72 +++++++++++++++++++++++++++++++++
p_set.hh | 72 +++++++++++++++++++++++++++++++++
test_cond_inherit.cc | 61 ++++++++++++++++++++++++++++
8 files changed, 542 insertions(+)
Index: trunk/milena/sandbox/pellegrin/cond_inheritance/test_cond_inherit.cc
===================================================================
--- trunk/milena/sandbox/pellegrin/cond_inheritance/test_cond_inherit.cc (revision 0)
+++ trunk/milena/sandbox/pellegrin/cond_inheritance/test_cond_inherit.cc (revision 1736)
@@ -0,0 +1,61 @@
+// 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 sandbox/pellegrin/cond_inheritance/test_cond_inherit.cc
+ *
+ * \brief test my work on conditional inheritance.
+ */
+
+#include <iostream>
+#include <string>
+#include <mln/core/image2d.hh>
+#include <mln/io/pgm/load.hh>
+
+#include "p_set.hh"
+#include "p_array.hh"
+
+
+int main ()
+{
+ //const std::string file ("../../../img/lena.pgm");
+ //mln::image2d<mln::value::int_u8> I = mln::io::pgm::load (file);
+ //mln::image2d<mln::value::int_u8>::fwd_piter p (I.domain ());
+
+ //for_all (p)
+ //{
+ //}
+ std::cout << __FILE__ << ": construction d'un objet p_array<int>"
+ << std::endl;
+ mln::p_array<int> int_array;
+
+ std::cout << '\n' << __FILE__ << ": construction d'un objet p_set<int>"
+ << std::endl;
+ mln::p_set<int> int_set;
+
+ std::cout << "\nEnd of test on conditional inheritance" << std::endl;
+}
+
Index: trunk/milena/sandbox/pellegrin/cond_inheritance/p_set.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/cond_inheritance/p_set.hh (revision 0)
+++ trunk/milena/sandbox/pellegrin/cond_inheritance/p_set.hh (revision 1736)
@@ -0,0 +1,72 @@
+// 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 P_SET_HH
+# define P_SET_HH
+
+/*! \file sandbox/pellegrin/cond_inheritance/p_set.hh
+ *
+ * \brief Definition of p_set class.
+ */
+
+# include "internal/point_set_base.hh"
+
+
+namespace mln
+{
+
+ /*! \brief Point set class.
+ *
+ * This is a mathematical uni-set of points. The
+ * parameter \p P shall be a Point type.
+ *
+ * \todo All.
+ */
+ template <typename E>
+ class p_set: public internal::point_set_base<p_set<E>, E>
+ {
+ public:
+ p_set ();
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ inline
+ p_set<E>::p_set ()
+ {
+ std::cout << " " << __FILE__ << ": constructeur mln::p_set<E>"
+ << std::endl;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! P_SET_HH
Index: trunk/milena/sandbox/pellegrin/cond_inheritance/concept/point_set.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/cond_inheritance/concept/point_set.hh (revision 0)
+++ trunk/milena/sandbox/pellegrin/cond_inheritance/concept/point_set.hh (revision 1736)
@@ -0,0 +1,72 @@
+// 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 POINT_SET_HH
+# define POINT_SET_HH
+
+/*! \file sandbox/pellegrin/cond_inheritance/concept/point_set.hh
+ *
+ * \brief Definition of point_set class.
+ */
+
+# include <iostream>
+# include <vector>
+
+
+namespace mln
+{
+ namespace concept
+ {
+ /*! \brief Point set class.
+ */
+ template <typename E>
+ class point_set
+ {
+ std::vector<E> data;
+ protected:
+ point_set ();
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ inline
+ point_set<E>::point_set ()
+ {
+ std::cout << " " << __FILE__
+ << ": constructeur mln::concept::point_set<E>" << std::endl;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace concept
+
+} // end of namespace mln
+
+
+#endif // ! POINT_SET_HH
Index: trunk/milena/sandbox/pellegrin/cond_inheritance/p_array.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/cond_inheritance/p_array.hh (revision 0)
+++ trunk/milena/sandbox/pellegrin/cond_inheritance/p_array.hh (revision 1736)
@@ -0,0 +1,72 @@
+// 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 P_ARRAY_HH
+# define P_ARRAY_HH
+
+/*! \file sandbox/pellegrin/cond_inheritance/p_array.hh
+ *
+ * \brief Definition of p_array class.
+ */
+
+# include "internal/point_set_base.hh"
+
+
+namespace mln
+{
+
+ /*! \brief Point set class.
+ *
+ * This is a mathematical multi-set of points. The
+ * parameter \p P shall be a Point type.
+ *
+ * \todo All.
+ */
+ template <typename E>
+ class p_array : public internal::point_set_base<p_array<E>, E>
+ {
+ public:
+ p_array ();
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ inline
+ p_array<E>::p_array ()
+ {
+ std::cout << " " << __FILE__ << ": constructeur mln::p_array<E>"
+ << std::endl;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! P_ARRAY_HH
Index: trunk/milena/sandbox/pellegrin/cond_inheritance/internal/multi_set.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/cond_inheritance/internal/multi_set.hh (revision 0)
+++ trunk/milena/sandbox/pellegrin/cond_inheritance/internal/multi_set.hh (revision 1736)
@@ -0,0 +1,72 @@
+// 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 MULTI_SET_HH
+# define MULTI_SET_HH
+
+/*! \file sandbox/pellegrin/cond_inheritance/internal/multi_set.hh
+ *
+ * \brief Definition of multi_set class.
+ */
+
+# include <iostream>
+
+# include "concept/point_set.hh"
+
+
+namespace mln
+{
+ namespace internal
+ {
+ /*! \brief Multi set class.
+ */
+ template <typename E>
+ class multi_set: public concept::point_set<E>
+ {
+ protected:
+ multi_set ();
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ inline
+ multi_set<E>::multi_set ()
+ {
+ std::cout << " " << __FILE__
+ << ": constructeur mln::internal::multi_set<E>" << std::endl;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace internal
+
+} // end of namespace mln
+
+
+#endif // ! MULTI_SET_HH
Index: trunk/milena/sandbox/pellegrin/cond_inheritance/internal/uni_set.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/cond_inheritance/internal/uni_set.hh (revision 0)
+++ trunk/milena/sandbox/pellegrin/cond_inheritance/internal/uni_set.hh (revision 1736)
@@ -0,0 +1,70 @@
+// 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 UNI_SET_HH
+# define UNI_SET_HH
+
+/*! \file sandbox/pellegrin/cond_inheritance/internal/uni_set.hh
+ *
+ * \brief Definition of uni_set class.
+ */
+
+# include "concept/point_set.hh"
+
+
+namespace mln
+{
+ namespace internal
+ {
+ /*! \brief Uni set class.
+ */
+ template <typename E>
+ class uni_set: public concept::point_set<E>
+ {
+ protected:
+ uni_set ();
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ inline
+ uni_set<E>::uni_set ()
+ {
+ std::cout << " " << __FILE__
+ << ": constructeur mln::internal::uni_set<E>" << std::endl;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace internal
+
+} // end of namespace mln
+
+
+#endif // ! UNI_SET_HH
Index: trunk/milena/sandbox/pellegrin/cond_inheritance/internal/point_set_base.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/cond_inheritance/internal/point_set_base.hh (revision 0)
+++ trunk/milena/sandbox/pellegrin/cond_inheritance/internal/point_set_base.hh (revision 1736)
@@ -0,0 +1,97 @@
+// 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 POINT_SET_BASE_HH
+# define POINT_SET_BASE_HH
+
+/*! \file sandbox/pellegrin/cond_inheritance/internal/point_set_base.hh
+ *
+ * \brief Definition of point_set_base class.
+ */
+
+# include "internal/uni_set.hh"
+# include "internal/multi_set.hh"
+
+
+namespace mln
+{
+ // fwd declaration
+ template <typename E>
+ class p_set;
+ template <typename E>
+ class p_array;
+
+ namespace internal
+ {
+ /*! \brief Point set base class.
+ */
+ template <typename T, typename E>
+ class point_set_base;
+
+ template <typename E>
+ class point_set_base<p_set<E>, E>: public uni_set<E>
+ {
+ protected:
+ point_set_base ();
+ };
+
+ template <typename E>
+ class point_set_base<p_array<E>, E>: public multi_set<E>
+ {
+ protected:
+ point_set_base ();
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ inline
+ point_set_base<p_set<E>, E>::point_set_base ()
+ {
+ std::cout << " " << __FILE__
+ << ": constructeur mln::internal::point_set_base<p_set<E>, E>"
+ << std::endl;
+ }
+
+ template <typename E>
+ inline
+ point_set_base<p_array<E>, E>::point_set_base ()
+ {
+ std::cout << " " << __FILE__
+ << ": constructeur "
+ "mln::internal::point_set_base<p_array<E>, E>"
+ << std::endl;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace internal
+
+} // end of namespace mln
+
+#endif // ! POINT_SET_BASE_HH
Index: trunk/milena/sandbox/pellegrin/cond_inheritance/Makefile
===================================================================
--- trunk/milena/sandbox/pellegrin/cond_inheritance/Makefile (revision 0)
+++ trunk/milena/sandbox/pellegrin/cond_inheritance/Makefile (revision 1736)
@@ -0,0 +1,26 @@
+All_warnings = -ansi -pedantic -Wabi -Wctor-dtor-privacy -Wnon-virtual-dtor \
+ -Wreorder -Weffc++ -Wno-deprecated -Wstrict-null-sentinel \
+ -Wno-non-template-friend -Wold-style-cast -Woverloaded-virtual \
+ -Wno-pmf-conversions -Wsign-promo -fsyntax-only-pedantic-errors \
+ -w -Wextra -Wall -Waddress -Waggregate-return -Wno-attributes \
+ -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion \
+ -Wno-deprecated-declarations -Wdisabled-optimization -Wno-div-by-zero \
+ -Wno-endif-labels -Werror -Wfatal-errors -Wfloat-equal -Wformat \
+ -Wformat=2 -Wno-format-extra-args -Wformat-nonliteral \
+ -Wformat-security -Wformat-y2k -Wimplicit -Wimport -Wno-import \
+ -Winit-self -Winline -Wno-invalid-offsetof -Winvalid-pch \
+ -Wlarger-than-1 -Wunsafe-loop-optimizations -Wlong-long \
+ -Wmissing-braces -Wmissing-field-initializers \
+ -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \
+ -Wno-multichar -Wno-overflow -Woverlength-strings -Wpacked -Wpadded \
+ -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type \
+ -Wsequence-point -Wshadow -Wsign-compare -Wstack-protector \
+ -Wstrict-aliasing -Wstrict-overflow -Wswitch -Wswitch-default \
+ -Wswitch-enum -Wsystem-headers -Wtrigraphs -Wundef -Wuninitialized \
+ -Wunknown-pragmas -Wno-pragmas -Wunreachable-code -Wunused \
+ -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value \
+ -Wunused-variable -Wvariadic-macros -Wvolatile-register-var \
+ -Wwrite-strings \
+
+all:
+ g++-4.2 -ansi -pedantic -I../../.. -I. test_cond_inherit.cc -o test
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Binarization.
* mln/level/threshold.hh: Remove.
* mln/fun/v2b: New directory : value to bool function.
* mln/fun/v2b/threshold.hh: value to bool threshold.
* mln/fun/v2v/threshold.hh: Remove.
* mln/binarization: New directory.
* mln/binarization/includes.hh: include for binarization.
* mln/binarization/binarization.hh: generic binarization (v2b for now).
* mln/binarization/thresholding.hh: thresholding.
* mln/io/pnm/save.hh: Comments for dummy (me) users who try to save binary as pgm.
* tests/binarization: New test directory.
* tests/binarization/thresholding.cc: New test file.
mln/binarization/binarization.hh | 106 +++++++++++++++++++++++++++++++++++++
mln/binarization/includes.hh | 43 +++++++++++++++
mln/binarization/thresholding.hh | 89 +++++++++++++++++++++++++++++++
mln/fun/v2b/threshold.hh | 90 +++++++++++++++++++++++++++++++
mln/io/pnm/save.hh | 2
tests/binarization/thresholding.cc | 54 ++++++++++++++++++
6 files changed, 384 insertions(+)
Index: tests/binarization/thresholding.cc
--- tests/binarization/thresholding.cc (revision 0)
+++ tests/binarization/thresholding.cc (revision 0)
@@ -0,0 +1,54 @@
+// Copyright (C) 2007, 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.
+
+/*! \file tests/binarization/thresholding.cc
+ *
+ * \brief Test on mln::binarization::thresholding
+ */
+
+
+#include <mln/core/image2d.hh>
+#include <mln/binarization/thresholding.hh>
+#include <mln/level/all.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pbm/save.hh>
+
+//#include "tests/data.hh"
+
+int main(int argc, char **)
+{
+ using namespace mln;
+ using value::int_u8;
+
+ typedef image2d<int_u8> I;
+
+ I lena;
+ io::pgm::load(lena, "../../img/lena.pgm");
+
+ io::pbm::save(binarization::thresholding(lena, argc), "out1.pgm");
+}
Index: tests/morpho/gradient.cc
Index: mln/fun/v2b/threshold.hh
--- mln/fun/v2b/threshold.hh (revision 0)
+++ mln/fun/v2b/threshold.hh (revision 0)
@@ -0,0 +1,90 @@
+// Copyright (C) 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_FUN_V2B_THRESHOLD_HH
+# define MLN_FUN_V2B_THRESHOLD_HH
+
+/*! \file mln/fun/v2b/threshold.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace v2b
+ {
+
+ /*!
+ *\brief Threshold function.
+ * f(v) = (v >= threshold).
+ *
+ */
+ template <typename V>
+ struct threshold : public Function_v2b< threshold<V> >
+ {
+ typedef bool result;
+ bool operator()(const V& v) const;
+
+ threshold(const V& a);
+ V a;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ inline
+ threshold<V>::threshold(const V& a)
+ : a(a)
+ {
+ }
+
+ template <typename V>
+ inline
+ bool
+ threshold<V>::operator()(const V& v) const
+ {
+ return (v >= a);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::v2b
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_V2B_THRESHOLD_HH
Index: mln/binarization/includes.hh
--- mln/binarization/includes.hh (revision 0)
+++ mln/binarization/includes.hh (revision 0)
@@ -0,0 +1,43 @@
+// Copyright (C) 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_BINARIZATION_INCLUDES_HH
+# define MLN_BINARIZATION_INCLUDES_HH
+
+/*! \file mln/binarization/includes.hh
+ *
+ * \brief Basic list of includes for all files in mln/binarization/.
+ */
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/window.hh>
+# include <mln/core/concept/neighborhood.hh>
+
+# include <mln/metal/has_neighborhood.hh>
+
+#endif // ! MLN_BINARIZATION_INCLUDES_HH
Index: mln/binarization/binarization.hh
--- mln/binarization/binarization.hh (revision 0)
+++ mln/binarization/binarization.hh (revision 0)
@@ -0,0 +1,106 @@
+// Copyright (C) 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_BINARIZATION_BINARIZATION_HH
+# define MLN_BINARIZATION_BINARIZATION_HH
+
+/*! \file mln/binarization/threshold.hh
+ *
+ * \brief Threshold the contents of an image into another binary one.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/level/transform.hh>
+
+
+namespace mln
+{
+
+ namespace binarization
+ {
+
+ /*! Thresholds the values of \p input so that they can be stored in
+ * the \p output binary image.
+ *
+ * \param[in] input The input image.
+ * \param[in] fun The thresholding function, from value(I) to bool.
+ *
+ * for_all(p), output(p) = fun(p)
+ *
+ */
+ template <typename I, typename F>
+ inline
+ mln_concrete_ch_value(I, bool)
+ binarization(const Image<I>& input, const Function_v2b<F>& fun);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I, typename F>
+ inline
+ mln_concrete_ch_value(I, bool)
+ binarization_(const I& input, const Function_v2b<F>& fun)
+ {
+ trace::entering("binarization::impl::binarization_");
+ mln_concrete_ch_value(I, bool) output(input.domain());
+
+ level::transform(input, fun, output);
+
+ trace::exiting("binarization::impl::binarization_");
+ return output;
+ }
+
+ } // end of namespace mln::binarization::impl
+
+
+ template <typename I, typename F>
+ inline
+ mln_concrete_ch_value(I, bool)
+ binarization(const Image<I>& input, const Function_v2b<F>& fun)
+ {
+ trace::entering("binarization::binarization");
+ mln_precondition(exact(input).has_data());
+ mlc_is(mln_trait_value_nature(mln_value(I)),
+ trait::value::nature::scalar)::check();
+
+ mln_concrete_ch_value(I, bool) output(exact(input).domain());
+ output = impl::binarization_(exact(input), fun);
+
+ trace::exiting("binarization::binarization");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::binarization
+
+} // end of namespace mln
+
+
+#endif // ! MLN_BINARIZATION_THRESHOLDING_HH
Index: mln/binarization/thresholding.hh
--- mln/binarization/thresholding.hh (revision 0)
+++ mln/binarization/thresholding.hh (revision 0)
@@ -0,0 +1,89 @@
+// Copyright (C) 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_BINARIZATION_THRESHOLDING_HH
+# define MLN_BINARIZATION_THRESHOLDING_HH
+
+/*! \file mln/binarization/thresholding.hh
+ *
+ * \brief Threshold the contents of an image into another binary one.
+ */
+
+# include <mln/binarization/binarization.hh>
+# include <mln/fun/v2b/threshold.hh>
+
+
+namespace mln
+{
+
+ namespace binarization
+ {
+
+ /*! Thresholds the values of \p input so that they can be stored in
+ * the \p output binary image.
+ *
+ * \param[in] input The input image.
+ * \param[in] threshold The threshold.
+ *
+ * If input(p) is greater or equal than the threshold, the
+ * value in the output image in the same point will be TRUE, else FALSE.
+ *
+ */
+ template <typename I>
+ mln_concrete_ch_value(I, bool)
+ thresholding(const Image<I>& input, const mln_value(I) threshold);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ inline
+ mln_concrete_ch_value(I, bool)
+ thresholding(const Image<I>& input, const mln_value(I) threshold)
+ {
+ trace::entering("binarization::thresholding");
+ mln_precondition(exact(input).has_data());
+ mlc_is(mln_trait_value_nature(mln_value(I)),
+ trait::value::nature::scalar)::check();
+
+ mln_concrete_ch_value(I, bool) output(exact(input).domain());
+
+ fun::v2b::threshold< mln_value(I) > f(threshold);
+ output = binarization::binarization(exact(input), f);
+
+ trace::exiting("binarization::thresholding");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::binarization
+
+} // end of namespace mln
+
+
+#endif // ! MLN_BINARIZATION_THRESHOLDING_HH
Index: mln/io/pnm/save.hh
--- mln/io/pnm/save.hh (revision 1734)
+++ mln/io/pnm/save.hh (working copy)
@@ -102,6 +102,8 @@
void write_value(std::ofstream& file,
const V& v)
{
+ // if V is not a struct you are probably trying to write binary images
+ // use pbm files for binary images
typedef typename V::enc E;
E c = v.to_enc();
https://svn.lrde.epita.fr/svn/oln/trunk/milena
I know I should probably move the tests related to the WST to
tests/morpho. Please recall this to me if I forget to do it. TIA.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add a test applying a full WST-based segmentation chain on a line
graph.
* tests/core/lena_line_graph_image_wst.cc: New test.
* tests/core/graph_image_wst.cc: Fix Doxygen header.
* tests/core/Makefile.am (check_PROGRAMS): Add
lena_line_graph_image_wst.
(lena_line_graph_image_wst_SOURCES)
(lena_line_graph_image_wst_CXXFLAGS):
New.
* tests/morpho/Makefile.am (meyer_wst_long_CXXFLAGS): Append
-ggdb.
core/Makefile.am | 5
core/graph_image_wst.cc | 4
core/lena_line_graph_image_wst.cc | 249 ++++++++++++++++++++++++++++++++++++++
morpho/Makefile.am | 2
4 files changed, 257 insertions(+), 3 deletions(-)
Index: tests/core/lena_line_graph_image_wst.cc
--- tests/core/lena_line_graph_image_wst.cc (revision 0)
+++ tests/core/lena_line_graph_image_wst.cc (revision 0)
@@ -0,0 +1,249 @@
+// 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.
+
+/// \file tests/core/line_graph_image.cc
+/// \brief Tests on the Watershed Transform on a mln::line_graph_image.
+
+#include <vector>
+
+#include <mln/core/image2d.hh>
+#include <mln/core/point2d.hh>
+#include <mln/core/window2d.hh>
+#include <mln/core/neighb2d.hh>
+
+#include <mln/core/line_graph_image.hh>
+#include <mln/core/line_graph_elt_neighborhood.hh>
+#include <mln/core/line_graph_neighborhood_piter.hh>
+
+#include <mln/morpho/gradient.hh>
+#include <mln/morpho/closing_area.hh>
+#include <mln/morpho/meyer_wst.hh>
+
+#include <mln/value/int_u8.hh>
+// #include <mln/value/int_u16.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/literal/black.hh>
+#include <mln/literal/colors.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/ppm/save.hh>
+
+#include <mln/math/max.hh>
+#include <mln/math/abs.hh>
+
+#include "tests/data.hh"
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+// using value::int_u16;
+ using value::rgb8;
+
+ /*--------.
+ | Input. |
+ `--------*/
+
+ typedef int_u8 input_val_t;
+ image2d<input_val_t> input;
+// io::pgm::load(input, MLN_IMG_DIR "/small.pgm");
+ io::pgm::load(input, MLN_IMG_DIR "/tiny.pgm");
+
+ /* FIXME: Don't compute a gradient on the image2d input. Instead,
+ have the values of the line graph image /behaves/ as the gradient
+ of the input, i.e., edges should hold the absolute difference
+ between gray levels.
+ */
+ image2d<input_val_t> gradient =
+ morpho::gradient (input, convert::to_window(c4()));
+
+ // Simplify the input image.
+ image2d<input_val_t> work(input.domain());
+// morpho::closing_area(gradient, c4(), 50, work);
+ morpho::closing_area(gradient, c4(), 10, work);
+
+ /*-------------.
+ | Line graph. |
+ `-------------*/
+
+ // FIXME: Inlined conversion, to be reifed into a routine.
+
+ util::graph<point2d> g;
+
+ // Points.
+ /* FIXME: The need for such a structure during the conversion
+ exhibits the lack of a service from util::graph (or a another,
+ missing tool) regarding the retrieval of node ids from
+ points. */
+ std::map<point2d, util::node_id> points;
+ util::node_id id = 0;
+
+ // Nodes.
+ std::vector<int> node_values;
+ mln_fwd_piter_(image2d<input_val_t>) p(work.domain());
+ for_all (p)
+ {
+ g.add_node (p);
+ node_values.push_back (work(p));
+ /* FIXME: ``Guessing'' the id of the point just being inserted
+ is bad. utill:graph<N,E>::add_node should return this
+ id. */
+ points[p] = id;
+ ++id;
+ }
+
+ // Edges.
+ window2d next_c4_win;
+ next_c4_win.insert(0, 1).insert(1, 0);
+ std::vector<int> edge_values;
+ mln_fwd_qiter_(window2d) q(next_c4_win, p);
+ for_all (p)
+ for_all (q)
+ if (work.has(q))
+ {
+ g.add_edge(points[p], points[q]);
+ // FIXME: Keep this valuation function?
+ edge_values.push_back(math::max(work(p), work(q)));
+ }
+
+ // Line graph point set.
+ p_line_graph<point2d> plg(g);
+
+ // Line graph image.
+ /* FIXME: Shouldn't we use `input_val_t' instead of plain `int' as value
+ type here? */
+ typedef line_graph_image<point2d, int> ima_t;
+ ima_t lg_ima(plg, node_values, edge_values);
+
+ /*------.
+ | WST. |
+ `------*/
+
+ typedef line_graph_elt_neighborhood<point2d> nbh_t;
+ nbh_t nbh;
+
+ // Perform a Watershed Transform.
+ typedef int_u8 wst_val_t;
+ wst_val_t nbasins;
+ typedef line_graph_image<point2d, wst_val_t> wst_ima_t;
+ wst_ima_t wshed = morpho::meyer_wst(lg_ima, nbh, nbasins);
+ std::cout << "nbasins = " << nbasins << std::endl;
+
+ /*---------.
+ | Output. |
+ `---------*/
+
+ // FIXME: Inlined conversion, to be reifed into a routine.
+
+ // Save the result in gray levels (data) + color (wshed).
+
+ // Data.
+ typedef rgb8 output_val_t;
+ typedef image2d<output_val_t> output_t;
+ point2d output_pmin = input.domain().pmin();
+ point2d output_pmax(input.domain().pmax()[0] * 2,
+ input.domain().pmax()[1] * 2);
+ output_t output(box2d(output_pmin, output_pmax));
+ level::fill(output, literal::black);
+ // Reuse the piter on INPUT.
+ for_all(p)
+ {
+ // Equivalent of P in OUTPUT.
+ point2d q(p[0] * 2, p[1] * 2);
+ input_val_t v = input(p);
+ /* FIXME: Use a conversion function from input_val_t to
+ output_val_t instead of an explicit construction. */
+ output(q) = output_val_t(v, v, v);
+ }
+ // Interpolate missing points in OUTPUT.
+ mln_piter_(output_t) p_out(output.domain());
+// mln_niter_(neighb2d) n_out(c4(), p_out);
+ for_all(p_out)
+ {
+ // Process points on even rows and odd columns
+ if (p_out[0] % 2 == 0 && p_out[1] % 2 == 1)
+ output(p_out) = (output(p_out + left) + output(p_out + right)) / 2;
+ // Process points on odd rows and even columns
+ if (p_out[0] % 2 == 1 && p_out[1] % 2 == 0)
+ output(p_out) = (output(p_out + up) + output(p_out + down)) / 2;
+ // Process points on odd rows and odd columns
+ if (p_out[0] % 2 == 1 && p_out[1] % 2 == 1)
+ output(p_out) =
+ (output(p_out + make::dpoint2d(-1, -1)) +
+ output(p_out + make::dpoint2d(-1, +1)) +
+ output(p_out + make::dpoint2d(+1, -1)) +
+ output(p_out + make::dpoint2d(+1, +1))) / 4;
+ }
+ // Draw the watershed.
+ /* FIXME: We should draw the watershed on another image and
+ superimpose it on OUTPUT instead of drawing it directly into
+ OUTPUT. */
+ mln_piter_(wst_ima_t) pw(wshed.domain());
+ for_all(pw)
+ {
+ if (wshed(pw) == 0)
+ {
+ mln_point_(wst_ima_t) pp(pw);
+ // Equivalent of the line (edge) PP in OUTPUT.
+ int row1 = pp.first()[0] * 2;
+ int col1 = pp.first()[1] * 2;
+ int row2 = pp.second()[0] * 2;
+ int col2 = pp.second()[1] * 2;
+ point2d q((row1 + row2) / 2, (col1 + col2) / 2);
+ // Print the watershed in red.
+ output(q) = literal::red;
+ }
+ }
+ // Fill the holes, so that the watershed looks connected.
+ /* FIXME: This approach is bad: it creates thick lines of watershed.
+ We should probably solve this when we ``paint'' the watershed
+ over the ``doubled'' image.
+
+ A better approach is probably to iterate over the set of nodes,
+ and ``connect'' edges according to patterns (vertically or
+ horizontally connected egdes member of the watershed, etc.). */
+ // Reuse the piter on OUTPUT.
+ for_all (p_out)
+ // Only handle points on odd rows and columns.
+ if (p_out[0] % 2 == 1 && p_out[1] % 2 == 1)
+ {
+ // Count the number of adjacent watershed points. If there are
+ // two or more, consider, create a watershed point.
+ /* FIXME: Iterating over a c4 window would be more elegant, of
+ course. */
+ unsigned nwsheds =
+ (output.has(p_out + up ) && output(p_out + up ) == literal::red) +
+ (output.has(p_out + down ) && output(p_out + down ) == literal::red) +
+ (output.has(p_out + left ) && output(p_out + right) == literal::red) +
+ (output.has(p_out + right) && output(p_out + left ) == literal::red);
+ if (nwsheds >= 2)
+ output(p_out) = literal::red;
+ }
+ io::ppm::save(output, "out.ppm");
+}
Index: tests/core/graph_image_wst.cc
--- tests/core/graph_image_wst.cc (revision 1719)
+++ tests/core/graph_image_wst.cc (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/core/graph_image.cc
-/// \brief Tests on mln::graph_image.
+/// \file tests/core/graph_image_wst.cc
+/// \brief Tests on the Watershed Transform on a mln::graph_image.
#include <vector>
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 1731)
+++ tests/core/Makefile.am (working copy)
@@ -10,6 +10,7 @@
initialize \
graph_elt_window \
graph_image \
+ lena_line_graph_image_wst \
line_graph_elt_window \
line_graph_image \
line_graph_image_wst \
@@ -51,4 +52,8 @@
t_image_SOURCES = t_image.cc
tr_image_SOURCES = tr_image.cc
+# FIXME: We should isolate this test, as it takes a long time.
+lena_line_graph_image_wst_SOURCES = lena_line_graph_image_wst.cc
+lena_line_graph_image_wst_CXXFLAGS = -O3 -ggdb
+
TESTS = $(check_PROGRAMS)
Index: tests/morpho/Makefile.am
--- tests/morpho/Makefile.am (revision 1731)
+++ tests/morpho/Makefile.am (working copy)
@@ -35,6 +35,6 @@
meyer_wst_SOURCES = meyer_wst.cc
# FIXME: We should isolate this test, as it takes a long time.
meyer_wst_long_SOURCES = meyer_wst_long.cc
-meyer_wst_long_CXXFLAGS = -O3
+meyer_wst_long_CXXFLAGS = -O3 -ggdb
TESTS = $(check_PROGRAMS)