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();