---
milena/ChangeLog | 8 ++
.../sandbox/scribo/{remove_tables.cc => demat.hh} | 110 ++++++++++++--------
milena/sandbox/scribo/main.cc | 45 ++++++++
3 files changed, 119 insertions(+), 44 deletions(-)
rename milena/sandbox/scribo/{remove_tables.cc => demat.hh} (55%)
create mode 100644 milena/sandbox/scribo/main.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index dc4af1c..15c868f 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,13 @@
2008-10-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Use labeling::compute for Scribo.
+ * milena/sandbox/scribo/remove_tables.hh: split in...
+ * milena/sandbox/scribo/demat.hh,
+ * milena/sandbox/scribo/main.cc: ...these two files.
+ Update the code in order to use labeling::compute.
+
+2008-10-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Fix labeling::compute return type.
* milena/mln/labeling/compute.hh: Fix many compilation errors
while taking directly the result type of an accumulator as a template
diff --git a/milena/sandbox/scribo/remove_tables.cc b/milena/sandbox/scribo/demat.hh
similarity index 55%
rename from milena/sandbox/scribo/remove_tables.cc
rename to milena/sandbox/scribo/demat.hh
index 0ee0528..bba9105 100644
--- a/milena/sandbox/scribo/remove_tables.cc
+++ b/milena/sandbox/scribo/demat.hh
@@ -25,10 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file doc/examples/hit_or_miss.cc
- *
- * \brief Test on mln::morpho::hit_or_miss.
- */
+#ifndef DEMAT_HH_
+# define DEMAT_HH_
# include <mln/core/image/image2d.hh>
@@ -57,55 +55,79 @@
# include <mln/convert/to_fun.hh>
# include <mln/geom/bbox.hh>
-void clean_lines(mln::image2d<bool>& in,
- const mln::image2d<bool>& ima,
- unsigned bbox_larger)
-{
- using namespace mln;
- using value::int_u8;
+# include <mln/labeling/compute.hh>
+# include <mln/accu/bbox.hh>
- int_u8 nlabels;
- image2d<int_u8> lbl = labeling::blobs(ima, c4(), nlabels);
+namespace scribo
+{
- for (unsigned i = nlabels; i > 0; --i)
+ namespace internal
{
- level::paste(pw::cst(false)
- | geom::bbox(lbl | (pw::value(lbl) == pw::cst(i))),//.to_larger(bbox_larger),
- in);
- }
-}
-int main(int argc, char*argv[])
-{
- using namespace mln;
- using value::int_u8;
+ void filter_image(mln::image2d<bool>& ima,
+ const mln::image2d<bool>& filter,
+ unsigned bbox_larger)
+ {
+ using namespace mln;
+ using value::int_u8;
+
+ typedef image2d<int_u8> I;
+ typedef mln_accu_with_(accu::meta::bbox, mln_psite_(I)) A;
+ typedef p_array<mlc_unqualif_(A::result)> boxes_t;
+
+ int_u8 nlabels;
+ I lbl = labeling::blobs(filter, c4(), nlabels);
+
+ boxes_t boxes = labeling::compute(accu::meta::bbox(), lbl, nlabels);
+ mln_piter_(boxes_t) p(boxes);
+
+ for_all(p)
+ level::paste(pw::cst(false)
+ | p.to_site().to_larger(bbox_larger),
+ ima);
+ }
- if (argc < 2)
+ void remove_tables(mln::image2d<bool>& in, unsigned h, unsigned w, unsigned n)
+ {
+ using namespace mln;
+
+ // Lignes verticales
+ win::rectangle2d vwin(h, w);
+ image2d<bool> vfilter = morpho::opening(in, vwin);
+ io::pbm::save(vfilter, "./table-vfilter.pbm");
+ filter_image(in, vfilter, n);
+
+ // Lignes horizontales
+ win::rectangle2d hwin(w, h);
+ image2d<bool> hfilter = morpho::opening(in, hwin);
+ io::pbm::save(hfilter, "./table-hfilter.pbm");
+ filter_image(in, hfilter, n);
+ }
+
+ } // end of namespace scribo::internal
+
+
+
+ // Facade
+ void demat(char *argv[])
{
- std::cout << argv[0] << " <image.pgm> <h> <w>" << std::endl;
- return 1;
- }
+ using namespace mln;
+ using value::int_u8;
- image2d<bool> in;
- io::pbm::load(in, argv[1]);
+ //Useful debug variables
+ unsigned h = atoi(argv[2]);
+ unsigned w = atoi(argv[3]);
+ unsigned n = atoi(argv[4]);
- unsigned h = atoi(argv[2]);
- unsigned w = atoi(argv[3]);
- unsigned n = atoi(argv[4]);
+ //Load image
+ image2d<bool> in;
+ io::pbm::load(in, argv[1]);
- // Lignes verticales
- win::rectangle2d vwin(h, w);
- image2d<bool> vout = morpho::opening(in, vwin);
- io::pbm::save(vout, "./vout.pbm");
- clean_lines(in, vout, n);
+ internal::remove_tables(in, h, w, n);
- // Lignes horizontales
- win::rectangle2d hwin(w, h);
- image2d<bool> hout = morpho::opening(in, hwin);
- io::pbm::save(hout, "./hout.pbm");
- clean_lines(in, hout, n);
+ io::pbm::save(in, "./table-filtered.pbm");
+ }
- io::pbm::save(in, "./outt.pbm");
+} // end of namespace scribo
- return 0;
-}
+# endif // ! DEMAT_HH
diff --git a/milena/sandbox/scribo/main.cc b/milena/sandbox/scribo/main.cc
new file mode 100644
index 0000000..d49fee8
--- /dev/null
+++ b/milena/sandbox/scribo/main.cc
@@ -0,0 +1,45 @@
+// 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.
+
+
+#include "demat.hh"
+
+int main(int argc, char*argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc < 2)
+ {
+ std::cout << argv[0] << " <image.pgm> <h> <w> <bbox_larger>" << std::endl;
+ return 1;
+ }
+
+ scribo::demat(argv);
+
+ return 0;
+}
--
1.5.6.5
---
milena/ChangeLog | 7 ++
milena/mln/labeling/compute.hh | 207 +++++++++++++++++++++++++++++++++++++
milena/tests/labeling/Makefile.am | 2 +
milena/tests/labeling/compute.cc | 83 +++++++++++++++
4 files changed, 299 insertions(+), 0 deletions(-)
create mode 100644 milena/mln/labeling/compute.hh
create mode 100644 milena/tests/labeling/compute.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 734d001..9ad63cc 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,12 @@
2008-10-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add labeling::compute.
+ * milena/mln/labeling/compute.hh: do it.
+ * milena/tests/labeling/Makefile.am,
+ * milena/tests/labeling/compute.cc: Add the proper test.
+
+2008-10-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Use geom::bbox instead of bbox().
* milena/mln/geom/max_col.hh,
* milena/mln/geom/max_row.hh,
diff --git a/milena/mln/labeling/compute.hh b/milena/mln/labeling/compute.hh
new file mode 100644
index 0000000..d579c7e
--- /dev/null
+++ b/milena/mln/labeling/compute.hh
@@ -0,0 +1,207 @@
+// 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_LABELING_COMPUTE_HH
+# define MLN_LABELING_COMPUTE_HH
+
+/*! \file mln/labeling/compute.hh
+ *
+ * \brief Compute an accumulator onto image pixel values.
+ */
+
+# include <mln/core/concept/meta_accumulator.hh>
+# include <mln/util/array.hh>
+
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /*! Compute an accumulator onto the pixel values of the image \p input.
+ * for each component of the image \p label.
+ *
+ * \param[in] a An accumulator.
+ * \param[in] input The input image.
+ * \param[in] label The labeled image.
+ * \param[in] input The number of component in \p label.
+ * \return A mln::p_array of accumulator result. One result per component in
+ * \p label.
+ *
+ * It fully relies on labeling::update.
+ */
+ template <typename A, typename I, typename J>
+ p_array<mln_result(A)>
+ compute(const Accumulator<A>& a,
+ const Image<I>& input,
+ const Image<J>& label, mln_value(J) nlabels);
+
+ /*! Compute an accumulator onto the pixel values of the image \p input.
+ * for each component of the image \p label.
+ *
+ * \param[in] a A meta-accumulator.
+ * \param[in] input The input image.
+ * \param[in] label The labeled image.
+ * \param[in] input The number of component in \p label.
+ * \return A mln::p_array of accumulator result. One result per component in
+ * \p label.
+ *
+ * It fully relies on labeling::update.
+ */
+ template <typename A, typename I, typename J>
+ p_array<mln_accu_with(A, mln_value(I))::result>
+ compute(const Meta_Accumulator<A>& a,
+ const Image<I>& input,
+ const Image<J>& label, mln_value(J) nlabels);
+
+ /*! Compute an accumulator onto the sites of each component domain of
+ * \p label.
+ *
+ * \param[in] a An accumulator.
+ * \param[in] label The labeled image.
+ * \param[in] input The number of component in \p label.
+ * \return A mln::p_array of accumulator result. One result per component in
+ * \p label.
+ *
+ * It fully relies on labeling::update.
+ */
+ template <typename A, typename J>
+ p_array<mln_result(A)>
+ compute(const Accumulator<A>& a,
+ const Image<J>& label, mln_value(J) nlabels);
+
+ /*! Compute an accumulator onto the sites of each component domain of
+ * \p label.
+ *
+ * \param[in] a A meta-accumulator.
+ * \param[in] label The labeled image.
+ * \param[in] input The number of component in \p label.
+ * \return A mln::p_array of accumulator result. One result per component in
+ * \p label.
+ *
+ * It fully relies on labeling::update.
+ */
+ template <typename A, typename J>
+ p_array<mln_accu_with(A, mln_psite(J))::result>
+ compute(const Meta_Accumulator<A>& a,
+ const Image<J>& label, mln_value(J) nlabels);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Facades.
+
+ template <typename A, typename I, typename J>
+ inline
+ p_array<mln_result(A)>
+ compute(const Accumulator<A>&,
+ const Image<I>& input_,
+ const Image<J>& label_, mln_value(J) nlabels)
+ {
+ trace::entering("labeling::compute");
+
+ const I& input = exact(input_);
+ const J& label = exact(label_);
+
+ util::array<A> accus;
+ for (mln_value(J) i = 0; i <= nlabels; ++i)
+ accus.append(A());
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ accus[label(p)].take(input(p));
+
+ p_array<mln_result(A)> results;
+ for (unsigned i = 0; i < accus.nelements(); ++i)
+ results.append(accus[i]);
+
+ trace::exiting("labeling::compute");
+ return results;
+ }
+
+ template <typename A, typename I, typename J>
+ inline
+ p_array<mln_accu_with(A, mln_value(I))::result>
+ compute(const Meta_Accumulator<A>&,
+ const Image<I>& input,
+ const Image<J>& label, mln_value(J) nlabels)
+ {
+ mln_accu_with(A, mln_value(I)) accu;
+ return compute(accu, input, label, nlabels);
+ }
+
+
+ template <typename A, typename J>
+ inline
+ p_array<mln_result(A)>
+ compute(const Accumulator<A>& a,
+ const Image<J>& label_, mln_value(J) nlabels)
+ {
+ trace::entering("labeling::compute");
+
+ const J& label = exact(label_);
+
+ util::array<A> accus;
+ for (mln_value(J) i = 0; i <= nlabels; ++i)
+ accus.append(exact(a));
+
+ mln_piter(J) p(label.domain());
+ for_all(p)
+ accus[label(p)].take(p);
+
+ p_array<mln_result(A)> results;
+ for (unsigned i = 0; i < accus.nelements(); ++i)
+ results.append(accus[i]);
+
+ trace::exiting("labeling::compute");
+ return results;
+ }
+
+
+ template <typename A, typename J>
+ inline
+ p_array<mln_accu_with(A, mln_psite(J))::result>
+ compute(const Meta_Accumulator<A>&,
+ const Image<J>& label, mln_value(J) nlabels)
+ {
+ mln_accu_with(A, mln_psite(J)) accu;
+ return compute(accu, label, nlabels);
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_COMPUTE_HH
diff --git a/milena/tests/labeling/Makefile.am b/milena/tests/labeling/Makefile.am
index 212eb15..399a1eb 100644
--- a/milena/tests/labeling/Makefile.am
+++ b/milena/tests/labeling/Makefile.am
@@ -5,6 +5,7 @@ include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
background \
blobs \
+ compute \
flat_zones \
foreground \
level \
@@ -13,6 +14,7 @@ check_PROGRAMS = \
background_SOURCES = background.cc
blobs_SOURCES = blobs.cc
+compute_SOURCES = compute.cc
flat_zones_SOURCES = flat_zones.cc
foreground_SOURCES = foreground.cc
level_SOURCES = level.cc
diff --git a/milena/tests/labeling/compute.cc b/milena/tests/labeling/compute.cc
new file mode 100644
index 0000000..cd36ae3
--- /dev/null
+++ b/milena/tests/labeling/compute.cc
@@ -0,0 +1,83 @@
+// 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.
+
+/*! \file tests/labeling/compute.cc
+ *
+ * \brief Tests on mln::labeling::compute.
+ */
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/labeling/blobs.hh>
+#include <mln/labeling/compute.hh>
+#include <mln/accu/count.hh>
+#include <mln/accu/sum.hh>
+#include <mln/value/int_u8.hh>
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ int_u8 vals[6][5] = {
+ {0, 1, 1, 0, 0},
+ {0, 1, 1, 0, 0},
+ {0, 0, 0, 0, 0},
+ {2, 2, 0, 3, 0},
+ {2, 0, 3, 3, 3},
+ {2, 0, 0, 0, 0}
+ };
+ image2d<int_u8> ima = make::image2d(vals);
+ int_u8 nlabels = 3;
+
+ accu::sum_<int_u8> sum;
+ p_array<float> sums = labeling::compute(sum, ima, ima, nlabels);
+ mln_assertion(sums[0] == 0);
+ mln_assertion(sums[1] == 4);
+ mln_assertion(sums[2] == 8);
+ mln_assertion(sums[3] == 12);
+
+ sums = labeling::compute(accu::meta::sum(), ima, ima, nlabels);
+ mln_assertion(sums[0] == 0);
+ mln_assertion(sums[1] == 4);
+ mln_assertion(sums[2] == 8);
+ mln_assertion(sums[3] == 12);
+
+ accu::count_<mln_site_(image2d<int_u8>)> count;
+ p_array<unsigned int> counts = labeling::compute(count, ima, nlabels);
+ mln_assertion(counts[0] == 18);
+ mln_assertion(counts[1] == 4);
+ mln_assertion(counts[2] == 4);
+ mln_assertion(counts[3] == 4);
+
+ counts = labeling::compute(accu::meta::count(), ima, nlabels);
+ mln_assertion(counts[0] == 18);
+ mln_assertion(counts[1] == 4);
+ mln_assertion(counts[2] == 4);
+ mln_assertion(counts[3] == 4);
+}
+
--
1.5.6.5