Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
milena r3572: Test geodesic distance with component tree and try to apply
by Edwin Carlinet 24 Mar '09
by Edwin Carlinet 24 Mar '09
24 Mar '09
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-03-24 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Test geodesic distance with component tree and try to apply.
* mln/morpho/attribute/sharpness.hh: Fix bugs related to
height computation.
* sandbox/edwin/attributes/bbox.hh: Add bbox morpho attribute.
* sandbox/edwin/tree/run.hh: Correct bugs and delete
run_while_treshold which can be computed throught pointwise.
* sandbox/edwin/tree/test.cc: Test file.
---
mln/morpho/attribute/sharpness.hh | 5
sandbox/edwin/attributes/bbox.hh | 203 ++++++++++++++++++++++++++++++++++++++
sandbox/edwin/tree/Makefile | 10 -
sandbox/edwin/tree/configure | 14 ++
sandbox/edwin/tree/run.hh | 67 ------------
sandbox/edwin/tree/test.cc | 143 ++++++++++++++++++++++++--
6 files changed, 362 insertions(+), 80 deletions(-)
Index: trunk/milena/mln/morpho/attribute/sharpness.hh
===================================================================
--- trunk/milena/mln/morpho/attribute/sharpness.hh (revision 3571)
+++ trunk/milena/mln/morpho/attribute/sharpness.hh (revision 3572)
@@ -177,7 +177,10 @@
double
sharpness<I>::to_result() const
{
- return (double)volume_.to_result() / (double)(volume_.area() * height_.to_result());
+ double d = (double) volume_.to_result() /
+ (double)(volume_.area() * (height_.to_result() + 1));
+ mln_postcondition(d >= 0 && d <= 1);
+ return d;
}
template <typename I>
Index: trunk/milena/sandbox/edwin/tree/configure
===================================================================
--- trunk/milena/sandbox/edwin/tree/configure (revision 0)
+++ trunk/milena/sandbox/edwin/tree/configure (revision 3572)
@@ -0,0 +1,14 @@
+#! /bin/bash
+
+
+for arg in "$@"; do
+ if [ "$arg" == "--debug" ]; then
+ debug=1;
+ fi
+done
+
+rm -f makefile.rules
+touch makefile.rules
+if [ "$debug" ]; then
+ echo 'DEBUG=1' > makefile.rules
+fi
\ No newline at end of file
Property changes on: trunk/milena/sandbox/edwin/tree/configure
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/tree/run.hh
===================================================================
--- trunk/milena/sandbox/edwin/tree/run.hh (revision 3571)
+++ trunk/milena/sandbox/edwin/tree/run.hh (revision 3572)
@@ -91,7 +91,7 @@
**
** @param tree Component tree used for propagation.
** @param a Attributed image where values are propagated.
- ** @param accu_ Accumulator to apply on tree.
+ ** @param acc Accumulator to apply on tree.
** @param n The repetition number.
**
** @return Array of propagated nodes.
@@ -104,28 +104,6 @@
Accumulator<ACC>& acc,
unsigned n);
- /**
- ** Apply accumulator \accu on tree nodes value until the value
- ** accumulated by \p acc get lesser than the treshold \p n.
- ** Each time, the result of accumulator is inserted
- ** into the returned array, then ascendant and descendant zero-fill
- ** propagations are performed from the node.
- ** (This function is a shorcut of run_while with a treshold predicate).
- **
- ** @param tree Component tree used for propagation.
- ** @param a Attributed image where values are propagated.
- ** @param accu_ Accumulator to apply on tree.
- ** @param n Treshold.
- **
- ** @return Array of propagated nodes.
- */
- template <typename T, typename A, typename ACC>
- inline
- p_array< mln_psite(A) >
- run_while_treshold(const T& tree,
- Image<A>& a,
- Accumulator<ACC>& acc,
- mln_value(A) n);
# ifndef MLN_INCLUDE_ONLY
@@ -143,16 +121,16 @@
p_array< mln_psite(A) > arr_sites;
util::array< mln_value(A) > arr_values;
- do {
p = morpho::tree::run(tree, a, accu);
- if (a(p) == 0) //there's no more objects.
- break;
+ while (pred(p) && a(p) != 0)
+ {
arr_sites.insert(p);
arr_values.append(a(p));
morpho::tree::propagate_node_to_descendants(p, tree, a, 0);
morpho::tree::propagate_node_to_ancestors(p, tree, a, 0);
a(p) = 0;
- } while (pred(accu.to_result()));
+ p = morpho::tree::run(tree, a, accu);
+ }
for (unsigned i = 0; i < arr_sites.nsites(); i++)
a(arr_sites[i]) = arr_values[i];
return arr_sites;
@@ -178,28 +156,6 @@
unsigned n_;
};
- template <typename I>
- struct treshold : Function_p2b< treshold<I> >
- {
- typedef bool result;
-
- treshold(const Image<I>& ima,
- const mln_value(I)& treshold)
- : ima_ (exact(ima)),
- treshold_ (treshold)
- {
- }
-
- bool operator()(const mln_psite(I)& p) const
- {
- return (ima_(p) > treshold_);
- }
-
- private:
- const I& ima_;
- const mln_value(I) treshold_;
- };
-
} // end of namespace mln::morpho::tree::internal
@@ -231,19 +187,6 @@
return run_while(tree, a, acc, predicate);
}
-
- template <typename T, typename A, typename ACC>
- inline
- p_array< mln_psite(A) >
- run_while_treshold(const T& tree,
- Image<A>& a,
- Accumulator<ACC>& acc,
- mln_value(A) n)
- {
- internal::treshold<A> predicate(a, n);
- return run_while(tree, a, acc, predicate);
- }
-
template <typename T, typename A, typename I>
mln_result(A)
run(const T& tree,
Index: trunk/milena/sandbox/edwin/tree/test.cc
===================================================================
--- trunk/milena/sandbox/edwin/tree/test.cc (revision 3571)
+++ trunk/milena/sandbox/edwin/tree/test.cc (revision 3572)
@@ -1,6 +1,8 @@
/* mln core */
#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image_if.hh>
#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/routine/duplicate.hh>
#include <mln/core/var.hh>
/* Site set */
@@ -15,15 +17,34 @@
#include "accumulator/arg_max.hh"
/* Attributes */
-#include <mln/morpho/attribute/sharpness.hh>
+#include <mln/transform/distance_geodesic.hh>
+#include <mln/morpho/attribute/card.hh>
+#include "../attributes/bbox.hh"
/* io */
-#include <mln/io/pgm/load.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/io/ppm/save.hh>
#include <../../theo/color/change_attributes.hh>
-#include <iostream>
+
+/* data & pw */
+#include <mln/core/concept/function.hh>
+#include <mln/fun/p2v/ternary.hh>
+#include <mln/data/fill.hh>
+#include <mln/data/paste.hh>
+#include <mln/pw/all.hh>
+
+/* labeling */
+#include <mln/value/label.hh>
+#include <mln/labeling/blobs.hh>
+#include <mln/debug/colorize.hh>
+
+/* Draw debug */
+#include <mln/draw/box.hh>
/* std */
#include <string>
+#include <iostream>
bool mydebug = false;
@@ -42,6 +63,35 @@
<< "*********************" << std::endl;
}
+template <typename P2V>
+struct ratio_ : public mln::Function_p2v< ratio_<P2V> >
+{
+ typedef double result;
+
+ ratio_(const P2V& f) :
+ f_ (f)
+ {
+ }
+
+ template <typename P>
+ double operator() (const P& p) const
+ {
+ return (double) (f_(p).len(1)) / (double)(f_(p).len(0));
+ }
+
+protected:
+ const P2V& f_;
+};
+
+template <typename P2V>
+ratio_<P2V> ratio(const mln::Function_p2v<P2V>& f)
+{
+ return ratio_<P2V>(exact(f));
+}
+
+
+
+
int main(int argc, char* argv[])
{
using namespace mln;
@@ -56,8 +106,16 @@
/* Image loadin' */
typedef image2d<int_u8> I;
- I input;
- io::pgm::load(input, argv[1]);
+ image2d<bool> input_;
+ io::pbm::load(input_, argv[1]);
+
+ /* Work on geodesic distance image */
+ I input = transform::distance_geodesic(input_, c8(), mln_max(int_u8));
+
+ if (mydebug)
+ dsp("Distance geodesic");
+
+ io::pgm::save(input, "distance.pgm");
/* Component tree creation */
typedef p_array< mln_site_(I) > S;
@@ -67,20 +125,44 @@
tree_t tree(input, sorted_sites, c4());
/* Compute Attribute On Image */
- typedef morpho::attribute::sharpness<I> accu_t;
- typedef mln_ch_value_(tree_t::function, mln_result_(accu_t)) A;
+ typedef morpho::attribute::bbox<I> bbox_t;
+ typedef mln_ch_value_(I, double) A;
- A a = morpho::tree::compute_attribute_image(accu_t (), tree);
+ mln_VAR(attr_image, morpho::tree::compute_attribute_image(bbox_t (), tree));
+ A a = duplicate(ratio(pw::value(attr_image)) | attr_image.domain());
morpho::tree::propagate_representant(tree, a);
if (mydebug) {
- dsp("Image attribute"); display_tree_attributes(tree, a);
+ dsp("Image sharp attribute"); display_tree_attributes(tree, a);
}
- /* Run max accumulator, looking for 5 objects */
+ /* We don't want little components */
+
+ // So we compute card attribute and we filter big components
+ // FIXME: some attributes are compositions of attributes, here
+ // sharpness can give area so, it would be fine if we could give an
+ // optional extra argument to compute_attribute where the
+ // accumulators image will be stored.
+
+// typedef morpho::attribute::card<I> card_t;
+// typedef mln_ch_value_(tree_t::function, mln_result_(card_t)) B;
+
+// B b = morpho::tree::compute_attribute_image(card_t (), tree);
+// morpho::tree::propagate_representant(tree, b);
+
+// if (mydebug) {
+// dsp("Image card attribute"); display_tree_attributes(tree, b);
+// }
+
+// a = duplicate((fun::p2v::ternary(pw::value(b) > pw::cst(2), pw::value(a), pw::cst(0.0))) | a.domain());
+
+
+ /* Run max accumulator */
accumulator::arg_max<A> argmax(a);
p_array< mln_psite_(A) > obj_array; // Array of object components.
- obj_array = morpho::tree::run_ntimes(tree, a, argmax, 5);
+
+ mln_VAR(predicate, pw::value(a) > pw::cst(0.5));
+ obj_array = morpho::tree::run_while(tree, a, argmax, predicate);
if (mydebug) {
dsp("Run max accumulator, lk 4 5 objs"); display_tree_attributes(tree, a);
@@ -94,5 +176,44 @@
std::cout << c;
}
+ /* Now Back Propagate to component */
+ typedef mln_ch_value_(I, bool) M;
+ M mask;
+ initialize(mask, a);
+ data::fill(mask, false);
+
+ mln_fwd_piter_(p_array< mln_psite_(I) >) c(obj_array);
+ for_all(c)
+ {
+ mask(c) = true;
+ propagate_node_to_descendants(c, tree, mask);
+ }
+ morpho::tree::propagate_representant(tree, mask);
+
+ // mask now contains all nodes related to objects
+
+ if (mydebug) {
+ dsp("Create mask and propagate"); display_tree_attributes(tree, mask);
+ }
+
+ /* Labeling */
+ typedef mln_ch_value_(I, value::label<8>) L;
+ value::label<8> nlabel;
+ L label = labeling::blobs(mask, c4(), nlabel);
+ io::ppm::save(debug::colorize(value::rgb8(), label, nlabel), "label.pgm");
+
+ /* Now store output image image */
+ I out;
+ initialize(out, input);
+ data::fill(out, 0);
+ data::paste(input | pw::value(mask), out);
+
+ if (mydebug) {
+ mln_fwd_piter_(p_array< mln_psite_(I) >) c(obj_array);
+ for_all(c)
+ draw::box(out, attr_image(c), mln_max(int_u8));
+ dsp("Mask input"); display_tree_attributes(tree, out);
+ }
+ io::pgm::save(out, "output.pgm");
}
Index: trunk/milena/sandbox/edwin/tree/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/tree/Makefile (revision 3571)
+++ trunk/milena/sandbox/edwin/tree/Makefile (revision 3572)
@@ -1,3 +1,4 @@
+include makefile.rules
TARGET=test
SRC=test.cc
OBJS=${SRC:.cc=.o}
@@ -7,16 +8,15 @@
CXXFLAGS=-I$(MILENADIR) -I./ -W -Wall
-CXXFLAGS += -g -ggdb
-#CXXFLAGS += -DNDEBUG -O1
+
+CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG -O1)
CXX=g++
LD=g++
LDFLAGS=
all: clean $(TARGET)
- #chmod +x exo2.sh
- #./exo2.sh
+
$(TARGET): $(OBJS) $(SRC)
$(LD) $(LDFLAGS) -o $@ $(OBJS)
@@ -29,5 +29,5 @@
clean:
rm -f *.o $(TARGET)
- rm -f *.pbm
- find -name "*.pgm" \! -regex ".*/affiche2?.pgm" -delete
\ No newline at end of file
+ #rm -f *.pbm
+ #find -name "*.pgm" \! -regex ".*/affiche2?.pgm" -delete
Index: trunk/milena/sandbox/edwin/attributes/bbox.hh
===================================================================
--- trunk/milena/sandbox/edwin/attributes/bbox.hh (revision 0)
+++ trunk/milena/sandbox/edwin/attributes/bbox.hh (revision 3572)
@@ -0,0 +1,203 @@
+// Copyright (C) 2007, 2008, 2009 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.
+
+#ifndef MLN_MORPHO_ATTRIBUTE_BBOX_HH_
+# define MLN_MORPHO_ATTRIBUTE_BBOX_HH_
+
+/// \file mln/morpho/attribute/bbox.hh
+///
+/// Define an accumulator that computes bounding box of a
+/// component.
+
+# include <mln/core/concept/box.hh>
+
+
+namespace mln
+{
+
+ // Forward declaration.
+
+ namespace morpho {
+ namespace attribute {
+ template <typename I> class bbox;
+ }
+ }
+
+ // Traits.
+
+ namespace trait
+ {
+
+ template <typename I>
+ struct accumulator_< morpho::attribute::bbox<I> >
+ {
+ typedef accumulator::has_untake::no has_untake;
+ typedef accumulator::has_set_value::no has_set_value;
+ typedef accumulator::has_stop::no has_stop;
+ typedef accumulator::when_pix::use_p when_pix;
+ };
+
+ } // end of namespace mln::trait
+
+ namespace morpho {
+ namespace attribute {
+
+ template <typename I>
+ struct bbox : public mln::accu::internal::base<const box<mln_psite(I)>&, bbox<I> >
+ {
+ typedef mln::accu::internal::base<const box<mln_psite(I)>&, bbox<I> > super_;
+
+ public:
+ typedef mln_psite(I) P;
+ typedef mln_psite(I) argument;
+
+ bbox();
+
+ /// Manipulators.
+ /// \{
+ void init();
+ void take(const argument& p);
+ void take(const bbox<I>& other);
+ void take_as_init(const argument& p);
+
+ /// \}
+
+ /// Get the value of the accumulator.
+ const box<P>& to_result() const;
+
+
+ /// Check whether this accu is able to return a result.
+ /// Always true here.
+ bool is_valid() const;
+
+ protected:
+
+ bool is_valid_;
+ box<mln_psite(I)> b_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ inline
+ bbox<I>::bbox()
+ {
+ init();
+ }
+
+ template <typename I>
+ inline
+ void
+ bbox<I>::init()
+ {
+ is_valid_ = false;
+ }
+
+ template <typename I>
+ inline
+ void
+ bbox<I>::take_as_init(const mln_psite(I)& p)
+ {
+ b_.pmin() = p;
+ b_.pmax() = p;
+ is_valid_ = true;
+ }
+
+ template <typename I>
+ inline
+ void
+ bbox<I>::take(const mln_psite(I)& p)
+ {
+ if (!is_valid_)
+ {
+ b_.pmin() = p;
+ b_.pmax() = p;
+ is_valid_ = true;
+ return;
+ }
+ for (unsigned i = 0; i < mln_psite_(I)::dim; ++i)
+ if (p[i] < b_.pmin()[i])
+ b_.pmin()[i] = p[i];
+ else if (p[i] > b_.pmax()[i])
+ b_.pmax()[i] = p[i];
+ }
+
+ template <typename I>
+ inline
+ void
+ bbox<I>::take(const bbox<I>& other)
+ {
+ if (! other.is_valid_)
+ {
+ // no-op
+ return;
+ }
+ if (! this->is_valid_)
+ {
+ // 'other' makes '*this' valid
+ *this = other;
+ is_valid_ = true;
+ return;
+ }
+ // both are valids so:
+ const box<mln_psite(I)>& o_b = other.b_;
+ for (unsigned i = 0; i < mln_psite_(I)::dim; ++i)
+ {
+ if (o_b.pmin()[i] < b_.pmin()[i])
+ b_.pmin()[i] = o_b.pmin()[i];
+ if (o_b.pmax()[i] > b_.pmax()[i])
+ b_.pmax()[i] = o_b.pmax()[i];
+ }
+ }
+
+ template <typename I>
+ inline
+ const box<mln_psite(I)>&
+ bbox<I>::to_result() const
+ {
+ mln_precondition(is_valid_);
+ return b_;
+ }
+
+ template <typename I>
+ inline
+ bool
+ bbox<I>::is_valid() const
+ {
+ return is_valid_;
+ }
+
+
+# endif /* !MLN_INCLUDE_ONLY */
+ } // end of namespace mln::morpho::attribute
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+
+
+#endif /* !MLN_MORPHO_ATTRIBUTE_BBOX_HH_ */
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-24 Frederic Bour <bour(a)lrde.epita.fr>
Add inf, sup accumulator and accu_result function.
* mln/accu/inf.hh: New.
* mln/accu/sup.hh: New.
* mln/accu: New.
* mln/fun/accu_result.hh: New.
* mln/fun/from_accu.hh: Correct some typo errors.
---
accu/inf.hh | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++
accu/sup.hh | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++
fun/accu_result.hh | 69 ++++++++++++++++++++++
fun/from_accu.hh | 7 --
4 files changed, 404 insertions(+), 4 deletions(-)
Index: trunk/milena/sandbox/fred/mln/fun/accu_result.hh
===================================================================
--- trunk/milena/sandbox/fred/mln/fun/accu_result.hh (revision 0)
+++ trunk/milena/sandbox/fred/mln/fun/accu_result.hh (revision 3571)
@@ -0,0 +1,69 @@
+// 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 F 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_ACCU_RESULT_HH
+# define MLN_FUN_ACCU_RESULT_HH
+
+# include <mln/fun/unary.hh>
+# include <mln/core/concept/accumulator.hh>
+# include <mln/math/acos.hh>
+# include <mln/math/cos.hh>
+
+namespace mln
+{
+
+ // accu_result: return result of given accumulator.
+ namespace fun
+ {
+ struct accu_result : unary<accu_result> {};
+ }
+
+ namespace trait
+ {
+
+ namespace next
+ {
+ template <typename E>
+ struct set_unary_<mln::fun::accu_result, mln::Accumulator, E>
+ {
+ typedef set_unary_ ret;
+ typedef typename E::result result;
+ typedef mln::Accumulator<E> argument;
+
+ static result read(const argument& x)
+ {
+ return exact(x).to_result();
+ }
+ };
+
+ }
+
+ }
+
+}
+
+#endif /* ! MLN_FUN_ACCU_RESULT_HH */
\ No newline at end of file
Index: trunk/milena/sandbox/fred/mln/fun/from_accu.hh
===================================================================
--- trunk/milena/sandbox/fred/mln/fun/from_accu.hh (revision 3570)
+++ trunk/milena/sandbox/fred/mln/fun/from_accu.hh (revision 3571)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_FUN_FROMACCU_HH
-# define MLN_FUN_FROMACCU_HH
+#ifndef MLN_FUN_FROM_ACCU_HH
+# define MLN_FUN_FROM_ACCU_HH
# include <mln/fun/unary.hh>
# include <mln/core/concept/accumulator.hh>
@@ -36,7 +36,7 @@
namespace mln
{
- // Cosinus, bijective
+ // from_accu: wrap an accumulator into a function
namespace fun
{
template <typename A>
@@ -92,4 +92,4 @@
}
-#endif /* ! MLN_FUN_MATH_COS_HH */
\ No newline at end of file
+#endif /* ! MLN_FUN_FROM_ACCU_HH */
\ No newline at end of file
Index: trunk/milena/sandbox/fred/mln/accu/sup.hh
===================================================================
--- trunk/milena/sandbox/fred/mln/accu/sup.hh (revision 0)
+++ trunk/milena/sandbox/fred/mln/accu/sup.hh (revision 3571)
@@ -0,0 +1,166 @@
+// 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.
+
+#ifndef MLN_ACCU_SUP_HH
+# define MLN_ACCU_SUP_HH
+
+/// \file mln/accu/sup.hh
+///
+/// Define an accumulator that computes a sup.
+
+# include <mln/accu/internal/base.hh>
+# include <mln/core/concept/meta_accumulator.hh>
+# include <mln/trait/value_.hh>
+# include <mln/util/pix.hh>
+# include <mln/fun/math/sup.hh>
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+
+ /// Generic sup accumulator class.
+ /*!
+ * The parameter \c T is the type of values.
+ */
+ template <typename T>
+ struct sup : public mln::accu::internal::base< const T&, sup<T> >
+ {
+ typedef T argument;
+
+ sup();
+
+ /// Manipulators.
+ /// \{
+ void init();
+ void take_as_init(const argument& t);
+ void take(const argument& t);
+ void take(const sup<T>& other);
+ /// \}
+
+ /// Get the value of the accumulator.
+ const T& to_result() const;
+
+ /// Check whether this accu is able to return a result.
+ /// Always true here.
+ bool is_valid() const;
+
+ protected:
+
+ T t_;
+ mln::fun::sup::with<T, T>::ret fun_;
+ };
+
+
+ template <typename I> struct sup< util::pix<I> >;
+
+
+
+ namespace meta
+ {
+
+ /// Meta accumulator for sup.
+
+ struct sup : public Meta_Accumulator< sup >
+ {
+ template <typename T>
+ struct with
+ {
+ typedef accu::sup<T> ret;
+ };
+ };
+
+ } // end of namespace mln::accu::meta
+
+
+
+ # ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ inline
+ sup<T>::sup()
+ {
+ init();
+ }
+
+ template <typename T>
+ inline
+ void
+ sup<T>::init()
+ {
+ t_ = mln_min(T);
+ }
+
+ template <typename T>
+ inline
+ void sup<T>::take_as_init(const argument& t)
+ {
+ t_ = t;
+ }
+
+ template <typename T>
+ inline
+ void sup<T>::take(const argument& t)
+ {
+ this->t_ = this->fun_(t_, t);
+ }
+
+ template <typename T>
+ inline
+ void
+ sup<T>::take(const sup<T>& other)
+ {
+ this->t_ = this->fun_(t_, other.t_);
+ }
+
+ template <typename T>
+ inline
+ const T&
+ sup<T>::to_result() const
+ {
+ return t_;
+ }
+
+ template <typename T>
+ inline
+ bool
+ sup<T>::is_valid() const
+ {
+ return true;
+ }
+
+ # endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_SUP_HH
Index: trunk/milena/sandbox/fred/mln/accu/inf.hh
===================================================================
--- trunk/milena/sandbox/fred/mln/accu/inf.hh (revision 0)
+++ trunk/milena/sandbox/fred/mln/accu/inf.hh (revision 3571)
@@ -0,0 +1,166 @@
+// 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.
+
+#ifndef MLN_ACCU_INF_HH
+# define MLN_ACCU_INF_HH
+
+/// \file mln/accu/inf.hh
+///
+/// Define an accumulator that computes a inf.
+
+# include <mln/accu/internal/base.hh>
+# include <mln/core/concept/meta_accumulator.hh>
+# include <mln/trait/value_.hh>
+# include <mln/util/pix.hh>
+# include <mln/fun/math/inf.hh>
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+
+ /// Generic inf accumulator class.
+ /*!
+ * The parameter \c T is the type of values.
+ */
+ template <typename T>
+ struct inf : public mln::accu::internal::base< const T&, inf<T> >
+ {
+ typedef T argument;
+
+ inf();
+
+ /// Manipulators.
+ /// \{
+ void init();
+ void take_as_init(const argument& t);
+ void take(const argument& t);
+ void take(const inf<T>& other);
+ /// \}
+
+ /// Get the value of the accumulator.
+ const T& to_result() const;
+
+ /// Check whether this accu is able to return a result.
+ /// Always true here.
+ bool is_valid() const;
+
+ protected:
+
+ T t_;
+ mln::fun::inf::with<T, T>::ret fun_;
+ };
+
+
+ template <typename I> struct inf< util::pix<I> >;
+
+
+
+ namespace meta
+ {
+
+ /// Meta accumulator for inf.
+
+ struct inf : public Meta_Accumulator< inf >
+ {
+ template <typename T>
+ struct with
+ {
+ typedef accu::inf<T> ret;
+ };
+ };
+
+ } // end of namespace mln::accu::meta
+
+
+
+ # ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ inline
+ inf<T>::inf()
+ {
+ init();
+ }
+
+ template <typename T>
+ inline
+ void
+ inf<T>::init()
+ {
+ t_ = mln_max(T);
+ }
+
+ template <typename T>
+ inline
+ void inf<T>::take_as_init(const argument& t)
+ {
+ t_ = t;
+ }
+
+ template <typename T>
+ inline
+ void inf<T>::take(const argument& t)
+ {
+ this->t_ = this->fun_(t_, t);
+ }
+
+ template <typename T>
+ inline
+ void
+ inf<T>::take(const inf<T>& other)
+ {
+ this->t_ = this->fun_(t_, other.t_);
+ }
+
+ template <typename T>
+ inline
+ const T&
+ inf<T>::to_result() const
+ {
+ return t_;
+ }
+
+ template <typename T>
+ inline
+ bool
+ inf<T>::is_valid() const
+ {
+ return true;
+ }
+
+ # endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_INF_HH
1
0
* scribo/Makefile: add new targets.
* scribo/debug/save_linked_textbboxes_image.hh,
* scribo/debug/save_table_image.hh,
* scribo/debug/save_textbboxes_image.hh: improve outputs.
* scribo/draw/bounding_box_links.hh: draw mass centers.
* scribo/filter/small_components.hh: add an assertion.
* scribo/src/extract_text_double_link.cc,
* scribo/src/extract_text_double_several_links.cc,
* scribo/src/extract_text_multiple_links.cc,
* scribo/src/extract_text_single_link.cc: cleanup small components.
* scribo/src/extract_text_several_left_links.cc,
* scribo/src/extract_text_several_multiple_links,
* scribo/src/rectangularity.cc,
* scribo/src/table_erase.cc,
* scribo/src/table_rebuild_opening.cc,
* scribo/src/table_rebuild_rank.cc: new sample code.
* scribo/table/align_lines_horizontaly.hh,
* scribo/table/align_lines_verticaly.hh: fix compilation issues.
* scribo/table/erase.hh: fix traces.
* scribo/table/extract.hh,
* scribo/table/extract_lines_with_opening.hh,
* scribo/table/extract_lines_with_rank.hh: update prototypes.
* scribo/table/rebuild.hh: use for_all_elements instead of
for_all_components.
* scribo/text/grouping/group_from_double_link.hh: fix wrong
link validation.
* scribo/text/grouping/group_with_multiple_links.hh,
* scribo/text/grouping/group_with_single_left_link.hh,
* scribo/text/grouping/group_with_single_right_link.hh: refactor code...
* scribo/text/grouping/internal/find_left_graph_link.hh,
* scribo/text/grouping/internal/find_left_link.hh,
* scribo/text/grouping/internal/find_right_link.hh: ... here.
* scribo/text/grouping/internal/update_link_array.hh: fix wrong
conditions.
* scribo/text/grouping/group_with_several_left_links.hh,
* scribo/text/grouping/group_with_several_multiple_links.hh,
* scribo/text/grouping/group_with_several_right_links.hh: new variants
using three anchors instead of one to find the left/right neighbors.
---
milena/sandbox/ChangeLog | 57 +++++
milena/sandbox/scribo/Makefile | 22 ++-
.../scribo/debug/save_linked_textbboxes_image.hh | 74 ++++++-
milena/sandbox/scribo/debug/save_table_image.hh | 4 +-
.../sandbox/scribo/debug/save_textbboxes_image.hh | 3 +-
milena/sandbox/scribo/draw/bounding_box_links.hh | 215 +++++++++++++++++++-
milena/sandbox/scribo/filter/small_components.hh | 6 +-
.../sandbox/scribo/src/extract_text_double_link.cc | 9 +-
...ink.cc => extract_text_double_several_links.cc} | 32 +--
.../scribo/src/extract_text_multiple_links.cc | 1 +
..._link.cc => extract_text_several_left_links.cc} | 44 +----
...s.cc => extract_text_several_multiple_links.cc} | 11 +-
.../sandbox/scribo/src/extract_text_single_link.cc | 1 +
milena/sandbox/scribo/src/rectangularity.cc | 38 ++++
...tract_text_multiple_links.cc => table_erase.cc} | 47 ++---
..._multiple_links.cc => table_rebuild_opening.cc} | 66 +++----
...ext_multiple_links.cc => table_rebuild_rank.cc} | 66 +++----
.../scribo/table/align_lines_horizontaly.hh | 2 +-
.../sandbox/scribo/table/align_lines_verticaly.hh | 7 +-
milena/sandbox/scribo/table/erase.hh | 9 +-
milena/sandbox/scribo/table/extract.hh | 27 ++-
.../scribo/table/extract_lines_with_opening.hh | 15 +-
.../scribo/table/extract_lines_with_rank.hh | 13 +-
milena/sandbox/scribo/table/rebuild.hh | 23 +--
.../scribo/text/grouping/group_from_double_link.hh | 30 ++--
.../text/grouping/group_with_multiple_links.hh | 32 ++-
...ft_link.hh => group_with_several_left_links.hh} | 89 ++++++---
...nks.hh => group_with_several_multiple_links.hh} | 58 ++++--
...t_link.hh => group_with_several_right_links.hh} | 89 ++++++---
.../text/grouping/group_with_single_left_link.hh | 26 +--
.../text/grouping/group_with_single_right_link.hh | 24 +--
...pdate_link_array.hh => find_left_graph_link.hh} | 62 ++++---
.../find_left_link.hh} | 91 +++++----
.../find_right_link.hh} | 87 ++++----
.../text/grouping/internal/update_link_array.hh | 10 +-
35 files changed, 907 insertions(+), 483 deletions(-)
copy milena/sandbox/scribo/src/{extract_text_double_link.cc => extract_text_double_several_links.cc} (77%)
copy milena/sandbox/scribo/src/{extract_text_single_link.cc => extract_text_several_left_links.cc} (64%)
copy milena/sandbox/scribo/src/{extract_text_multiple_links.cc => extract_text_several_multiple_links.cc} (90%)
create mode 100644 milena/sandbox/scribo/src/rectangularity.cc
copy milena/sandbox/scribo/src/{extract_text_multiple_links.cc => table_erase.cc} (53%)
copy milena/sandbox/scribo/src/{extract_text_multiple_links.cc => table_rebuild_opening.cc} (53%)
copy milena/sandbox/scribo/src/{extract_text_multiple_links.cc => table_rebuild_rank.cc} (53%)
copy milena/sandbox/scribo/text/grouping/{group_with_single_left_link.hh => group_with_several_left_links.hh} (53%)
copy milena/sandbox/scribo/text/grouping/{group_with_multiple_links.hh => group_with_several_multiple_links.hh} (58%)
copy milena/sandbox/scribo/text/grouping/{group_with_single_right_link.hh => group_with_several_right_links.hh} (53%)
copy milena/sandbox/scribo/text/grouping/internal/{update_link_array.hh => find_left_graph_link.hh} (58%)
copy milena/sandbox/scribo/text/grouping/{group_with_multiple_links.hh => internal/find_left_link.hh} (52%)
copy milena/sandbox/scribo/text/grouping/{group_with_multiple_links.hh => internal/find_right_link.hh} (52%)
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 414a7fb..558ec99 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,3 +1,60 @@
+2009-03-24 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Update Scribo's code.
+
+ * scribo/Makefile: add new targets.
+
+ * scribo/debug/save_linked_textbboxes_image.hh,
+ * scribo/debug/save_table_image.hh,
+ * scribo/debug/save_textbboxes_image.hh: improve outputs.
+
+ * scribo/draw/bounding_box_links.hh: draw mass centers.
+
+ * scribo/filter/small_components.hh: add an assertion.
+
+ * scribo/src/extract_text_double_link.cc,
+ * scribo/src/extract_text_double_several_links.cc,
+ * scribo/src/extract_text_multiple_links.cc,
+ * scribo/src/extract_text_single_link.cc: cleanup small components.
+
+ * scribo/src/extract_text_several_left_links.cc,
+ * scribo/src/extract_text_several_multiple_links,
+ * scribo/src/rectangularity.cc,
+ * scribo/src/table_erase.cc,
+ * scribo/src/table_rebuild_opening.cc,
+ * scribo/src/table_rebuild_rank.cc: new sample code.
+
+ * scribo/table/align_lines_horizontaly.hh,
+ * scribo/table/align_lines_verticaly.hh: fix compilation issues.
+
+ * scribo/table/erase.hh: fix traces.
+
+ * scribo/table/extract.hh,
+ * scribo/table/extract_lines_with_opening.hh,
+ * scribo/table/extract_lines_with_rank.hh: update prototypes.
+
+ * scribo/table/rebuild.hh: use for_all_elements instead of
+ for_all_components.
+
+ * scribo/text/grouping/group_from_double_link.hh: fix wrong
+ link validation.
+
+ * scribo/text/grouping/group_with_multiple_links.hh,
+ * scribo/text/grouping/group_with_single_left_link.hh,
+ * scribo/text/grouping/group_with_single_right_link.hh: refactor code...
+
+ * scribo/text/grouping/internal/find_left_graph_link.hh,
+ * scribo/text/grouping/internal/find_left_link.hh,
+ * scribo/text/grouping/internal/find_right_link.hh: ... here.
+
+ * scribo/text/grouping/internal/update_link_array.hh: fix wrong
+ conditions.
+
+ * scribo/text/grouping/group_with_several_left_links.hh,
+ * scribo/text/grouping/group_with_several_multiple_links.hh,
+ * scribo/text/grouping/group_with_several_right_links.hh: new variants
+ using three anchors instead of one to find the left/right neighbors.
+
2009-03-24 Frederic Bour <bour(a)lrde.epita.fr>
Add from_accu functional wrapper.
diff --git a/milena/sandbox/scribo/Makefile b/milena/sandbox/scribo/Makefile
index 09a3a2d..3c3e1a5 100644
--- a/milena/sandbox/scribo/Makefile
+++ b/milena/sandbox/scribo/Makefile
@@ -18,6 +18,9 @@ photo: demat.hh
dmap:
g++ $(CXX_FLAGS) src/dmap.cc -o bin/dmap.out
+rectangularity:
+ g++ $(CXX_FLAGS) src/rectangularity.cc -o bin/rectangularity.out
+
extract_text_single_link:
g++ $(CXX_FLAGS) src/extract_text_single_link.cc -o bin/extract_text_single_link.out
@@ -25,15 +28,30 @@ extract_text_single_link:
extract_text_double_link:
g++ $(CXX_FLAGS) src/extract_text_double_link.cc -o bin/extract_text_double_link.out
+extract_text_double_several_links:
+ g++ $(CXX_FLAGS) src/extract_text_double_several_links.cc -o bin/extract_text_double_several_links.out
+
extract_text_multiple_links:
g++ $(CXX_FLAGS) src/extract_text_multiple_links.cc -o bin/extract_text_multiple_links.out
-table_rebuild:
- g++ $(CXX_FLAGS) src/table_rebuild.cc -o bin/table_rebuild.out
+extract_text_several_multiple_links:
+ g++ $(CXX_FLAGS) src/extract_text_several_multiple_links.cc -o bin/extract_text_several_multiple_links.out
+
+extract_text_several_left_links:
+ g++ $(CXX_FLAGS) src/extract_text_several_left_links.cc -o bin/extract_text_several_left_links.out
+
+table_rebuild_rank:
+ g++ $(CXX_FLAGS) src/table_rebuild_rank.cc -o bin/table_rebuild_rank.out
+
+table_rebuild_opening:
+ g++ $(CXX_FLAGS) src/table_rebuild_opening.cc -o bin/table_rebuild_opening.out
table_extract:
g++ $(CXX_FLAGS) src/table_extract.cc -o bin/table_extract.out
+table_erase:
+ g++ $(CXX_FLAGS) src/table_erase.cc -o bin/table_erase.out
+
thin_bboxes:
g++ $(CXX_FLAGS) src/thin_bboxes.cc -o bin/thin_bboxes.out
diff --git a/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh b/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh
index 4012c05..e7d2a40 100644
--- a/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh
+++ b/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh
@@ -35,6 +35,8 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/graph.hh>
+# include <mln/labeling/compute.hh>
+# include <mln/accu/center.hh>
# include <mln/level/convert.hh>
# include <mln/value/rgb8.hh>
# include <mln/util/array.hh>
@@ -72,8 +74,20 @@ namespace scribo
const mln::util::array<unsigned>& left_link,
const mln::util::array<unsigned>& right_array,
const value::rgb8& box_value,
+ const value::rgb8& link_value,
+ const std::string& filename);
+
+ template <typename I, typename L>
+ inline
+ void
+ save_linked_textbboxes_image(const Image<I>& input,
+ const scribo::util::text<L>& text,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ const value::rgb8& box_value,
const value::rgb8& left_link_value,
const value::rgb8& right_link_value,
+ const value::rgb8& validated_link_value,
const std::string& filename);
@@ -104,8 +118,13 @@ namespace scribo
mln_precondition(exact(input).is_valid());
mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input);
+
+ mln::util::array<mln_site(I)::vec> mass_centers
+ = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
+
draw::bounding_boxes(tmp, text.bboxes(), box_value);
- draw::bounding_box_links(tmp, text.bboxes(), link_array, link_value);
+ draw::bounding_box_links(tmp, mass_centers, link_array, link_value);
+
io::ppm::save(tmp, filename);
trace::exiting("scribo::debug::save_linked_textbboxes_image");
@@ -120,24 +139,62 @@ namespace scribo
const mln::util::array<unsigned>& left_link,
const mln::util::array<unsigned>& right_link,
const value::rgb8& box_value,
- const value::rgb8& left_value,
- const value::rgb8& right_value,
+ const value::rgb8& value,
const std::string& filename)
{
trace::entering("scribo::debug::save_linked_textbboxes_image");
mln_precondition(exact(input).is_valid());
mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input);
+
+ mln::util::array<mln_site(I)::vec> mass_centers
+ = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
+
draw::bounding_boxes(tmp, text.bboxes(), box_value);
- draw::bounding_box_links(tmp, text.bboxes(),
+ draw::bounding_box_links(tmp, mass_centers,
left_link, right_link,
- left_value, right_value);
+ value);
+
io::ppm::save(tmp, filename);
trace::exiting("scribo::debug::save_linked_textbboxes_image");
}
+ template <typename I, typename L>
+ inline
+ void
+ save_linked_textbboxes_image(const Image<I>& input,
+ const scribo::util::text<L>& text,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ const value::rgb8& box_value,
+ const value::rgb8& left_link_value,
+ const value::rgb8& right_link_value,
+ const value::rgb8& validated_link_value,
+ const std::string& filename)
+ {
+ trace::entering("scribo::debug::save_linked_textbboxes_image");
+ mln_precondition(exact(input).is_valid());
+
+ mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input);
+
+ mln::util::array<mln_site(I)::vec> mass_centers
+ = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
+
+ draw::bounding_boxes(tmp, text.bboxes(), box_value);
+ draw::bounding_box_links(tmp, mass_centers,
+ left_link, right_link,
+ left_link_value, right_link_value,
+ validated_link_value);
+
+ io::ppm::save(tmp, filename);
+
+ trace::exiting("scribo::debug::save_linked_textbboxes_image");
+ }
+
+
+
template <typename I, typename L, typename G>
inline
void
@@ -153,8 +210,13 @@ namespace scribo
mln_precondition(exact(input).is_valid());
mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input);
- draw::bounding_boxes(tmp, text.bboxes(), box_value);
+
+ mln::util::array<mln_site(I)::vec> mass_centers
+ = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
+
+ draw::bounding_boxes(tmp, mass_centers, box_value);
draw::bounding_box_links(tmp, text.bboxes(), g, link_value);
+
io::ppm::save(tmp, filename);
trace::exiting("scribo::debug::save_linked_textbboxes_image");
diff --git a/milena/sandbox/scribo/debug/save_table_image.hh b/milena/sandbox/scribo/debug/save_table_image.hh
index 4ed0a68..ebc65f6 100644
--- a/milena/sandbox/scribo/debug/save_table_image.hh
+++ b/milena/sandbox/scribo/debug/save_table_image.hh
@@ -98,7 +98,7 @@ namespace scribo
draw::bounding_boxes(out2, tableboxes.second(), bbox_color);
io::ppm::save(out2, filename);
- trace::exiting("scribo::internal::save_table");
+ trace::exiting("scribo::debug::save_table_image");
}
@@ -121,7 +121,7 @@ namespace scribo
draw::bounding_boxes(out2, tableboxes.second(), bbox_color);
io::ppm::save(out2, filename);
- trace::exiting("scribo::internal::save_table");
+ trace::exiting("scribo::debug::save_table_image");
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/sandbox/scribo/debug/save_textbboxes_image.hh b/milena/sandbox/scribo/debug/save_textbboxes_image.hh
index 86a8b3f..dde3d38 100644
--- a/milena/sandbox/scribo/debug/save_textbboxes_image.hh
+++ b/milena/sandbox/scribo/debug/save_textbboxes_image.hh
@@ -40,7 +40,6 @@
# include <mln/io/ppm/save.hh>
# include <scribo/draw/bounding_boxes.hh>
-# include <scribo/make/debug_filename.hh>
namespace scribo
@@ -76,7 +75,7 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input);
draw::bounding_boxes(tmp, textbboxes, value);
- io::ppm::save(tmp, scribo::make::debug_filename(filename));
+ io::ppm::save(tmp, filename);
trace::exiting("scribo::debug::save_textbboxes_image");
}
diff --git a/milena/sandbox/scribo/draw/bounding_box_links.hh b/milena/sandbox/scribo/draw/bounding_box_links.hh
index e33da38..5d695f6 100644
--- a/milena/sandbox/scribo/draw/bounding_box_links.hh
+++ b/milena/sandbox/scribo/draw/bounding_box_links.hh
@@ -56,6 +56,13 @@ namespace scribo
const mln::util::array<unsigned>& link_array,
const mln_value(I)& value);
+ template <typename I>
+ inline
+ void
+ bounding_box_links(Image<I>& input_,
+ const mln::util::array<mln_site(I)::vec>& mass_centers,
+ const mln::util::array<unsigned>& link_array,
+ const mln_value(I)& value);
template <typename I>
void
@@ -63,8 +70,46 @@ namespace scribo
const mln::util::array< box<mln_site(I)> >& bboxes,
const mln::util::array<unsigned>& left_link,
const mln::util::array<unsigned>& right_link,
+ const mln_value(I)& value);
+
+ template <typename I>
+ inline
+ void
+ bounding_box_links(Image<I>& input_,
+ const mln::util::array<mln_site(I)::vec>& mass_centers,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ const mln_value(I)& value);
+
+ template <typename I>
+ inline
+ void
+ bounding_box_links(Image<I>& input_,
+ const mln::util::array< box<mln_site(I)> >& bboxes,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
const mln_value(I)& left_link_value,
- const mln_value(I)& right_link_value);
+ const mln_value(I)& right_link_value,
+ const mln_value(I)& validated_link_value);
+
+ template <typename I>
+ inline
+ void
+ bounding_box_links(Image<I>& input_,
+ const mln::util::array<mln_site(I)::vec>& mass_centers,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ const mln_value(I)& left_link_value,
+ const mln_value(I)& right_link_value,
+ const mln_value(I)& validated_link_value);
+
+ template <typename I, typename G>
+ inline
+ void
+ bounding_box_links(Image<I>& input,
+ const mln::util::array< box<mln_site(I)> >& bboxes,
+ const Graph<G>& g,
+ const mln_value(I)& link_value);
# ifndef MLN_INCLUDE_ONLY
@@ -147,22 +192,182 @@ namespace scribo
trace::exiting("scribo::draw::bounding_box_links");
}
+ template <typename I>
+ inline
+ void
+ bounding_box_links(Image<I>& input_,
+ const mln::util::array<mln_site(I)::vec>& mass_centers,
+ const mln::util::array<unsigned>& link_array,
+ const mln_value(I)& value)
+ {
+ trace::entering("scribo::draw::bounding_box_links");
+
+ I& input = exact(input_);
+
+ mln_precondition(input.is_valid());
+
+ for_all_components(i, link_array)
+ {
+ if (link_array[i] != i)
+ mln::draw::line(input,
+ mass_centers[i],
+ mass_centers[link_array[i]],
+ value);
+ input(mass_centers[i]) = value;
+ }
+
+ trace::exiting("scribo::draw::bounding_box_links");
+ }
+
template <typename I>
inline
void
- bounding_box_links(Image<I>& input,
+ bounding_box_links(Image<I>& input_,
const mln::util::array< box<mln_site(I)> >& bboxes,
const mln::util::array<unsigned>& left_link,
const mln::util::array<unsigned>& right_link,
+ const mln_value(I)& value)
+ {
+ trace::entering("scribo::draw::bounding_box_links");
+ mln_precondition(exact(input).is_valid());
+
+ I& input = exact(input_);
+
+ mln_precondition(input.is_valid());
+
+ for_all_components(i, left_link)
+ {
+ unsigned nbh = right_link[left_link[i]];
+ if (nbh == i && left_link[i] != i)
+ mln::draw::line(input,
+ bboxes[i].center(),
+ bboxes[left_link[i]].center(),
+ value);
+ }
+
+ trace::exiting("scribo::draw::bounding_box_links");
+ }
+
+ template <typename I>
+ inline
+ void
+ bounding_box_links(Image<I>& input_,
+ const mln::util::array<mln_site(I)::vec>& mass_centers,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ const mln_value(I)& value)
+ {
+ trace::entering("scribo::draw::bounding_box_links");
+ mln_precondition(exact(input).is_valid());
+
+ I& input = exact(input_);
+
+ mln_precondition(input.is_valid());
+
+ for_all_components(i, left_link)
+ {
+ unsigned nbh = right_link[left_link[i]];
+ if (nbh == i && left_link[i] != i)
+ mln::draw::line(input,
+ mass_centers[i],
+ mass_centers[left_link[i]],
+ value);
+ input(mass_centers[i]) = value;
+ }
+
+ trace::exiting("scribo::draw::bounding_box_links");
+ }
+
+
+ template <typename I>
+ inline
+ void
+ bounding_box_links(Image<I>& input_,
+ const mln::util::array<mln_site(I)::vec>& mass_centers,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
const mln_value(I)& left_link_value,
- const mln_value(I)& right_link_value)
+ const mln_value(I)& right_link_value,
+ const mln_value(I)& validated_link_value)
{
trace::entering("scribo::draw::bounding_box_links");
mln_precondition(exact(input).is_valid());
- bounding_box_links(input, bboxes, left_link, left_link_value);
- bounding_box_links(input, bboxes, right_link, right_link_value);
+ I& input = exact(input_);
+
+ mln_precondition(input.is_valid());
+
+ mln_site(I)::vec dleft = literal::origin;
+ dleft[0] = 2;
+ mln_site(I)::vec dright = literal::origin;
+ dright[0] = -2;
+ for_all_components(i, left_link)
+ {
+ mln::draw::line(input,
+ mass_centers[i] + dleft,
+ mass_centers[left_link[i]] + dleft,
+ left_link_value);
+
+ mln::draw::line(input,
+ mass_centers[i] + dright,
+ mass_centers[right_link[i]] + dright,
+ right_link_value);
+
+ unsigned nbh = right_link[left_link[i]];
+ if (nbh == i && left_link[i] != i)
+ mln::draw::line(input,
+ mass_centers[i],
+ mass_centers[left_link[i]],
+ validated_link_value);
+
+ input(mass_centers[i]) = validated_link_value;
+ }
+
+ trace::exiting("scribo::draw::bounding_box_links");
+ }
+
+ template <typename I>
+ inline
+ void
+ bounding_box_links(Image<I>& input_,
+ const mln::util::array< box<mln_site(I)> >& bboxes,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ const mln_value(I)& left_link_value,
+ const mln_value(I)& right_link_value,
+ const mln_value(I)& validated_link_value)
+ {
+ trace::entering("scribo::draw::bounding_box_links");
+ mln_precondition(exact(input).is_valid());
+
+ I& input = exact(input_);
+
+ mln_precondition(input.is_valid());
+
+ mln_site(I)::vec dleft = literal::origin;
+ dleft[0] = 2;
+ mln_site(I)::vec dright = literal::origin;
+ dright[0] = -2;
+ for_all_components(i, left_link)
+ {
+ mln::draw::line(input,
+ bboxes[i].center() + dleft,
+ bboxes[left_link[i]].center() + dleft,
+ left_link_value);
+
+ mln::draw::line(input,
+ bboxes[i].center() + dright,
+ bboxes[right_link[i]].center() + dright,
+ right_link_value);
+
+ unsigned nbh = right_link[left_link[i]];
+ if (nbh == i && left_link[i] != i)
+ mln::draw::line(input,
+ bboxes[i].center(),
+ bboxes[left_link[i]].center(),
+ validated_link_value);
+ }
trace::exiting("scribo::draw::bounding_box_links");
}
diff --git a/milena/sandbox/scribo/filter/small_components.hh b/milena/sandbox/scribo/filter/small_components.hh
index 8cb6858..fb8ff5a 100644
--- a/milena/sandbox/scribo/filter/small_components.hh
+++ b/milena/sandbox/scribo/filter/small_components.hh
@@ -40,6 +40,7 @@
# include <mln/labeling/blobs.hh>
# include <mln/labeling/relabel.hh>
+# include <mln/make/relabelfun.hh>
# include <mln/util/array.hh>
# include <mln/value/label_16.hh>
@@ -191,7 +192,10 @@ namespace scribo
mln_value(I) new_nbboxes;
I new_lbl = labeling::relabel(text.label_image(), text.nbboxes(),
- new_nbboxes, f);
+ mln::make::relabelfun(f, text.nbboxes(),
+ new_nbboxes));
+
+ mln_assertion(new_nbboxes.next() == bresult.nelements());
trace::exiting("scribo::filter::small_components");
return scribo::make::text(bresult, new_lbl, new_nbboxes);
diff --git a/milena/sandbox/scribo/src/extract_text_double_link.cc b/milena/sandbox/scribo/src/extract_text_double_link.cc
index ea4b2b8..d7de94b 100644
--- a/milena/sandbox/scribo/src/extract_text_double_link.cc
+++ b/milena/sandbox/scribo/src/extract_text_double_link.cc
@@ -29,14 +29,17 @@
#include <mln/essential/2d.hh>
#include <mln/debug/colorize.hh>
+#include <mln/debug/println.hh>
#include <scribo/text/extract_bboxes.hh>
#include <scribo/text/grouping/group_with_single_left_link.hh>
#include <scribo/text/grouping/group_with_single_right_link.hh>
#include <scribo/debug/save_linked_textbboxes_image.hh>
#include <scribo/text/grouping/group_from_double_link.hh>
+#include <scribo/filter/small_components.hh>
#include <scribo/debug/save_textbboxes_image.hh>
+#include <scribo/make/debug_filename.hh>
int usage(const char *name)
{
@@ -62,6 +65,8 @@ int main(int argc, char* argv[])
scribo::util::text<image2d<value::label_16> > text
= text::extract_bboxes(input, c8(), nbboxes);
+ text = filter::small_components(text,4);
+
mln::util::array<unsigned> left_link
= text::grouping::group_with_single_left_link(text, 30);
mln::util::array<unsigned> right_link
@@ -80,8 +85,8 @@ int main(int argc, char* argv[])
scribo::debug::save_linked_textbboxes_image(input,
text, left_link, right_link,
- literal::red, literal::cyan,
- literal::yellow,
+ literal::red, literal::cyan, literal::yellow,
+ literal::green,
scribo::make::debug_filename("links.ppm"));
// io::ppm::save(mln::debug::colorize(value::rgb8(),
diff --git a/milena/sandbox/scribo/src/extract_text_double_link.cc b/milena/sandbox/scribo/src/extract_text_double_several_links.cc
similarity index 77%
copy from milena/sandbox/scribo/src/extract_text_double_link.cc
copy to milena/sandbox/scribo/src/extract_text_double_several_links.cc
index ea4b2b8..ee7d384 100644
--- a/milena/sandbox/scribo/src/extract_text_double_link.cc
+++ b/milena/sandbox/scribo/src/extract_text_double_several_links.cc
@@ -31,12 +31,14 @@
#include <mln/debug/colorize.hh>
#include <scribo/text/extract_bboxes.hh>
-#include <scribo/text/grouping/group_with_single_left_link.hh>
-#include <scribo/text/grouping/group_with_single_right_link.hh>
+#include <scribo/text/grouping/group_with_several_left_links.hh>
+#include <scribo/text/grouping/group_with_several_right_links.hh>
#include <scribo/debug/save_linked_textbboxes_image.hh>
#include <scribo/text/grouping/group_from_double_link.hh>
+#include <scribo/filter/small_components.hh>
#include <scribo/debug/save_textbboxes_image.hh>
+#include <scribo/make/debug_filename.hh>
int usage(const char *name)
{
@@ -53,7 +55,7 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix = "extract_text_double_link";
+ scribo::make::internal::debug_filename_prefix = "extract_text_double_several_links";
image2d<bool> input;
io::pbm::load(input, argv[1]);
@@ -62,33 +64,21 @@ int main(int argc, char* argv[])
scribo::util::text<image2d<value::label_16> > text
= text::extract_bboxes(input, c8(), nbboxes);
+ text = filter::small_components(text,4);
+
mln::util::array<unsigned> left_link
- = text::grouping::group_with_single_left_link(text, 30);
+ = text::grouping::group_with_several_left_links(text, 30);
mln::util::array<unsigned> right_link
- = text::grouping::group_with_single_right_link(text, 30);
+ = text::grouping::group_with_several_right_links(text, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes << std::endl;
-// scribo::debug::save_linked_textbboxes_image(input,
-// text, left_link,
-// literal::red, literal::cyan,
-// scribo::make::debug_filename("left_linked.ppm"));
-// scribo::debug::save_linked_textbboxes_image(input,
-// text, right_link,
-// literal::red, literal::cyan,
-// scribo::make::debug_filename("right_linked.ppm"));
-
scribo::debug::save_linked_textbboxes_image(input,
text, left_link, right_link,
- literal::red, literal::cyan,
- literal::yellow,
+ literal::red, literal::cyan, literal::yellow,
+ literal::green,
scribo::make::debug_filename("links.ppm"));
-// io::ppm::save(mln::debug::colorize(value::rgb8(),
-// text.label_image(),
-// text.nbboxes()),
-// scribo::make::debug_filename("lbl_before.ppm"));
-
// With validation.
scribo::util::text<image2d<value::label_16> > grouped_text
= text::grouping::group_from_double_link(text, left_link, right_link);
diff --git a/milena/sandbox/scribo/src/extract_text_multiple_links.cc b/milena/sandbox/scribo/src/extract_text_multiple_links.cc
index 0c8c624..eacef81 100644
--- a/milena/sandbox/scribo/src/extract_text_multiple_links.cc
+++ b/milena/sandbox/scribo/src/extract_text_multiple_links.cc
@@ -35,6 +35,7 @@
#include <scribo/debug/save_textbboxes_image.hh>
#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/make/debug_filename.hh>
int usage(const char *name)
{
diff --git a/milena/sandbox/scribo/src/extract_text_single_link.cc b/milena/sandbox/scribo/src/extract_text_several_left_links.cc
similarity index 64%
copy from milena/sandbox/scribo/src/extract_text_single_link.cc
copy to milena/sandbox/scribo/src/extract_text_several_left_links.cc
index 1dee956..a050ff3 100644
--- a/milena/sandbox/scribo/src/extract_text_single_link.cc
+++ b/milena/sandbox/scribo/src/extract_text_several_left_links.cc
@@ -30,12 +30,12 @@
#include <mln/essential/2d.hh>
#include <scribo/text/extract_bboxes.hh>
-#include <scribo/text/grouping/group_with_single_left_link.hh>
-#include <scribo/text/grouping/group_with_single_right_link.hh>
+#include <scribo/text/grouping/group_with_several_left_links.hh>
#include <scribo/text/grouping/group_from_single_link.hh>
#include <scribo/debug/save_textbboxes_image.hh>
#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/make/debug_filename.hh>
int usage(const char *name)
{
@@ -51,7 +51,7 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix = "extract_text_single_link";
+ scribo::make::internal::debug_filename_prefix = "extract_text_several_left_links";
image2d<bool> input;
io::pbm::load(input, argv[1]);
@@ -63,19 +63,15 @@ int main(int argc, char* argv[])
{
std::cout << "* Left grouping" << std::endl;
mln::util::array<unsigned> left_link
- = text::grouping::group_with_single_left_link(text, 30);
+ = text::grouping::group_with_several_left_links(text, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes << std::endl;
scribo::debug::save_linked_textbboxes_image(input,
text, left_link,
literal::red, literal::cyan,
scribo::make::debug_filename("left_links.ppm"));
-// io::ppm::save(mln::debug::colorize(value::rgb8(),
-// text.label_image(),
-// text.nbboxes()),
-// scribo::make::debug_filename("lbl_before.ppm"));
- scribo::util::text<image2d<value::label_16> > grouped_text
+ scribo::util::text<image2d<value::label_16> > grouped_text
= text::grouping::group_from_single_link(text, left_link);
std::cout << "AFTER - nbboxes = " << grouped_text.bboxes().nelements() << std::endl;
@@ -88,35 +84,5 @@ int main(int argc, char* argv[])
scribo::make::debug_filename("left_bboxes.ppm"));
}
- {
- std::cout << "* Left grouping" << std::endl;
- mln::util::array<unsigned> right_link
- = text::grouping::group_with_single_right_link(text, 30);
-
- std::cout << "BEFORE - nbboxes = " << nbboxes << std::endl;
- scribo::debug::save_linked_textbboxes_image(input,
- text, right_link,
- literal::red, literal::cyan,
- scribo::make::debug_filename("right_links.ppm"));
-// io::ppm::save(mln::debug::colorize(value::rgb8(),
-// text.label_image(),
-// text.nbboxes()),
-// scribo::make::debug_filename("lbl_before.ppm"));
-
- scribo::util::text<image2d<value::label_16> > grouped_text
- = text::grouping::group_from_single_link(text, right_link);
-
- io::ppm::save(mln::debug::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
- scribo::make::debug_filename("right_label_color.ppm"));
- std::cout << "AFTER - nbboxes = " << grouped_text.bboxes().nelements() << std::endl;
-
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("right_bboxes.ppm"));
- }
-
-
}
diff --git a/milena/sandbox/scribo/src/extract_text_multiple_links.cc b/milena/sandbox/scribo/src/extract_text_several_multiple_links.cc
similarity index 90%
copy from milena/sandbox/scribo/src/extract_text_multiple_links.cc
copy to milena/sandbox/scribo/src/extract_text_several_multiple_links.cc
index 0c8c624..3c85c20 100644
--- a/milena/sandbox/scribo/src/extract_text_multiple_links.cc
+++ b/milena/sandbox/scribo/src/extract_text_several_multiple_links.cc
@@ -30,11 +30,12 @@
#include <mln/essential/2d.hh>
#include <scribo/text/extract_bboxes.hh>
-#include <scribo/text/grouping/group_with_multiple_links.hh>
+#include <scribo/text/grouping/group_with_several_multiple_links.hh>
#include <scribo/text/grouping/group_from_multiple_links.hh>
#include <scribo/debug/save_textbboxes_image.hh>
#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/make/debug_filename.hh>
int usage(const char *name)
{
@@ -50,7 +51,7 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix = "extract_text_multiple_links";
+ scribo::make::internal::debug_filename_prefix = "extract_text_several_multiple_links";
image2d<bool> input;
io::pbm::load(input, argv[1]);
@@ -59,17 +60,13 @@ int main(int argc, char* argv[])
scribo::util::text<image2d<value::label_16> > text
= text::extract_bboxes(input, c8(), nbboxes);
- mln::util::graph g = text::grouping::group_with_multiple_links(text, 30);
+ mln::util::graph g = text::grouping::group_with_several_multiple_links(text, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes.next() << std::endl;
scribo::debug::save_linked_textbboxes_image(input,
text, g,
literal::red, literal::cyan,
scribo::make::debug_filename("left_linked.ppm"));
-// io::ppm::save(mln::debug::colorize(value::rgb8(),
-// text.label_image(),
-// text.nbboxes()),
-// scribo::make::debug_filename("lbl_before.ppm"));
scribo::util::text<image2d<value::label_16> > grouped_text
= text::grouping::group_from_multiple_links(text, g);
diff --git a/milena/sandbox/scribo/src/extract_text_single_link.cc b/milena/sandbox/scribo/src/extract_text_single_link.cc
index 1dee956..640f9f2 100644
--- a/milena/sandbox/scribo/src/extract_text_single_link.cc
+++ b/milena/sandbox/scribo/src/extract_text_single_link.cc
@@ -36,6 +36,7 @@
#include <scribo/debug/save_textbboxes_image.hh>
#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/make/debug_filename.hh>
int usage(const char *name)
{
diff --git a/milena/sandbox/scribo/src/rectangularity.cc b/milena/sandbox/scribo/src/rectangularity.cc
new file mode 100644
index 0000000..67f0bc8
--- /dev/null
+++ b/milena/sandbox/scribo/src/rectangularity.cc
@@ -0,0 +1,38 @@
+#include <mln/essential/2d.hh>
+#include <mln/transform/distance_geodesic.hh>
+#include <mln/core/var.hh>
+#include <mln/fun/l2l/wrap.hh>
+#include <mln/win/hline2d.hh>
+#include <mln/morpho/watershed/flooding.hh>
+#include <mln/morpho/watershed/superpose.hh>
+
+#include <scribo/make/debug_filename.hh>
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+
+ using value::int_u16;
+ using value::label_16;
+ using value::label_8;
+ using value::rgb8;
+
+ image2d<bool> input;
+ io::pbm::load(input, argv[1]);
+
+ scribo::make::internal::debug_filename_prefix = "morpho";
+
+ label_16 nlabels;
+ image2d<label_16> lbl = labeling::blobs(input, c8(), nlabels);
+
+ mln_VAR(dmap, transform::distance_geodesic(lbl, c8(), mln_max(unsigned)));
+
+ io::pgm::save(level::transform(dmap, fun::l2l::wrap<label_8>()), "dmap.pgm");
+
+ {
+ image2d<unsigned> clo = morpho::closing::structural(dmap, win::disk2d(51));
+ io::pgm::save(clo, scribo::make::debug_filename("clo_disk_51.pgm"));
+ image2d<float> r = morpho::tree:compute_attribute_image(accu::site_set::rectangularity<point2d>(),clo);
+ image2d<point2d> r = morpho::tree:max(r,c8());
+ }
+}
diff --git a/milena/sandbox/scribo/src/extract_text_multiple_links.cc b/milena/sandbox/scribo/src/table_erase.cc
similarity index 53%
copy from milena/sandbox/scribo/src/extract_text_multiple_links.cc
copy to milena/sandbox/scribo/src/table_erase.cc
index 0c8c624..3cfcb46 100644
--- a/milena/sandbox/scribo/src/extract_text_multiple_links.cc
+++ b/milena/sandbox/scribo/src/table_erase.cc
@@ -28,13 +28,10 @@
#include <iostream>
#include <mln/essential/2d.hh>
+#include <mln/io/dump/save.hh>
-#include <scribo/text/extract_bboxes.hh>
-#include <scribo/text/grouping/group_with_multiple_links.hh>
-#include <scribo/text/grouping/group_from_multiple_links.hh>
+#include <scribo/table/extract.hh>
-#include <scribo/debug/save_textbboxes_image.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
int usage(const char *name)
{
@@ -42,6 +39,7 @@ int usage(const char *name)
return 1;
}
+
int main(int argc, char* argv[])
{
using namespace scribo;
@@ -50,39 +48,20 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix = "extract_text_multiple_links";
+ scribo::make::internal::debug_filename_prefix = "table_erase";
image2d<bool> input;
io::pbm::load(input, argv[1]);
+ logical::not_inplace(input);
- value::label_16 nbboxes;
- scribo::util::text<image2d<value::label_16> > text
- = text::extract_bboxes(input, c8(), nbboxes);
-
- mln::util::graph g = text::grouping::group_with_multiple_links(text, 30);
-
- std::cout << "BEFORE - nbboxes = " << nbboxes.next() << std::endl;
- scribo::debug::save_linked_textbboxes_image(input,
- text, g,
- literal::red, literal::cyan,
- scribo::make::debug_filename("left_linked.ppm"));
-// io::ppm::save(mln::debug::colorize(value::rgb8(),
-// text.label_image(),
-// text.nbboxes()),
-// scribo::make::debug_filename("lbl_before.ppm"));
+ typedef util::couple<util::array<box2d>,
+ util::array<box2d> > tables_t;
- scribo::util::text<image2d<value::label_16> > grouped_text
- = text::grouping::group_from_multiple_links(text, g);
-
- std::cout << "AFTER - nbboxes = " << grouped_text.bboxes().nelements() << std::endl;
-
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("grouped_text.ppm"));
- io::ppm::save(mln::debug::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
- scribo::make::debug_filename("label_color.ppm"));
+ value::label_16 ncells;
+ tables_t tables = scribo::table::extract_lines_with_rank(input, c8(), ncells,
+ win::vline2d(51), win::hline2d(51),
+ 8,6);
+ image2d<bool> input_notables = scribo::table::erase(input, tables);
+ io::pbm::save(input_notables, scribo::make::debug_filename("input_notables.pbm"));
}
-
diff --git a/milena/sandbox/scribo/src/extract_text_multiple_links.cc b/milena/sandbox/scribo/src/table_rebuild_opening.cc
similarity index 53%
copy from milena/sandbox/scribo/src/extract_text_multiple_links.cc
copy to milena/sandbox/scribo/src/table_rebuild_opening.cc
index 0c8c624..375646d 100644
--- a/milena/sandbox/scribo/src/extract_text_multiple_links.cc
+++ b/milena/sandbox/scribo/src/table_rebuild_opening.cc
@@ -28,13 +28,12 @@
#include <iostream>
#include <mln/essential/2d.hh>
+#include <mln/pw/all.hh>
-#include <scribo/text/extract_bboxes.hh>
-#include <scribo/text/grouping/group_with_multiple_links.hh>
-#include <scribo/text/grouping/group_from_multiple_links.hh>
-
-#include <scribo/debug/save_textbboxes_image.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/table/rebuild.hh>
+#include <scribo/table/erase.hh>
+#include <scribo/table/extract_lines_with_opening.hh>
+#include <scribo/make/debug_filename.hh>
int usage(const char *name)
{
@@ -42,6 +41,7 @@ int usage(const char *name)
return 1;
}
+
int main(int argc, char* argv[])
{
using namespace scribo;
@@ -50,39 +50,35 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix = "extract_text_multiple_links";
+ scribo::make::internal::debug_filename_prefix = argv[0];
image2d<bool> input;
io::pbm::load(input, argv[1]);
+ logical::not_inplace(input);
+ typedef util::couple<util::array<box2d>,util::array<box2d> > tblboxes_t;
+
+ win::vline2d vline(51);
+ win::hline2d hline(51);
value::label_16 nbboxes;
- scribo::util::text<image2d<value::label_16> > text
- = text::extract_bboxes(input, c8(), nbboxes);
-
- mln::util::graph g = text::grouping::group_with_multiple_links(text, 30);
-
- std::cout << "BEFORE - nbboxes = " << nbboxes.next() << std::endl;
- scribo::debug::save_linked_textbboxes_image(input,
- text, g,
- literal::red, literal::cyan,
- scribo::make::debug_filename("left_linked.ppm"));
-// io::ppm::save(mln::debug::colorize(value::rgb8(),
-// text.label_image(),
-// text.nbboxes()),
-// scribo::make::debug_filename("lbl_before.ppm"));
-
- scribo::util::text<image2d<value::label_16> > grouped_text
- = text::grouping::group_from_multiple_links(text, g);
-
- std::cout << "AFTER - nbboxes = " << grouped_text.bboxes().nelements() << std::endl;
-
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("grouped_text.ppm"));
- io::ppm::save(mln::debug::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
- scribo::make::debug_filename("label_color.ppm"));
+ tblboxes_t lineboxes
+ = table::extract_lines_with_opening(input, c8(), nbboxes,
+ vline, hline);
-}
+ value::label_8 ncells;
+ image2d<value::label_8> tables = scribo::table::rebuild(input, lineboxes, 30, ncells);
+
+ std::cout << "ncells (including background) = " << ncells << std::endl;
+ io::ppm::save(mln::debug::colorize(value::rgb8(), tables, ncells),
+ scribo::make::debug_filename("table_cells.ppm"));
+ io::pgm::save(tables, scribo::make::debug_filename("table_cells.pgm"));
+
+ image2d<value::rgb8> input_rgb = level::convert(value::rgb8(), input);
+ data::fill((input_rgb | pw::value(tables) == pw::cst(0u)).rw(), literal::red);
+ io::ppm::save(input_rgb, scribo::make::debug_filename("table_superposed.ppm"));
+
+ image2d<bool> in_wo_tables = table::erase(input, lineboxes);
+ io::pbm::save(in_wo_tables,
+ scribo::make::debug_filename("input_wo_tables.pbm"));
+}
diff --git a/milena/sandbox/scribo/src/extract_text_multiple_links.cc b/milena/sandbox/scribo/src/table_rebuild_rank.cc
similarity index 53%
copy from milena/sandbox/scribo/src/extract_text_multiple_links.cc
copy to milena/sandbox/scribo/src/table_rebuild_rank.cc
index 0c8c624..77b2b79 100644
--- a/milena/sandbox/scribo/src/extract_text_multiple_links.cc
+++ b/milena/sandbox/scribo/src/table_rebuild_rank.cc
@@ -28,13 +28,12 @@
#include <iostream>
#include <mln/essential/2d.hh>
+#include <mln/pw/all.hh>
-#include <scribo/text/extract_bboxes.hh>
-#include <scribo/text/grouping/group_with_multiple_links.hh>
-#include <scribo/text/grouping/group_from_multiple_links.hh>
-
-#include <scribo/debug/save_textbboxes_image.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/table/rebuild.hh>
+#include <scribo/table/erase.hh>
+#include <scribo/table/extract_lines_with_rank.hh>
+#include <scribo/make/debug_filename.hh>
int usage(const char *name)
{
@@ -42,6 +41,7 @@ int usage(const char *name)
return 1;
}
+
int main(int argc, char* argv[])
{
using namespace scribo;
@@ -50,39 +50,35 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix = "extract_text_multiple_links";
+ scribo::make::internal::debug_filename_prefix = argv[0];
image2d<bool> input;
io::pbm::load(input, argv[1]);
+ logical::not_inplace(input);
+ typedef util::couple<util::array<box2d>,util::array<box2d> > tblboxes_t;
+
+ win::vline2d vline(51);
+ win::hline2d hline(51);
value::label_16 nbboxes;
- scribo::util::text<image2d<value::label_16> > text
- = text::extract_bboxes(input, c8(), nbboxes);
-
- mln::util::graph g = text::grouping::group_with_multiple_links(text, 30);
-
- std::cout << "BEFORE - nbboxes = " << nbboxes.next() << std::endl;
- scribo::debug::save_linked_textbboxes_image(input,
- text, g,
- literal::red, literal::cyan,
- scribo::make::debug_filename("left_linked.ppm"));
-// io::ppm::save(mln::debug::colorize(value::rgb8(),
-// text.label_image(),
-// text.nbboxes()),
-// scribo::make::debug_filename("lbl_before.ppm"));
-
- scribo::util::text<image2d<value::label_16> > grouped_text
- = text::grouping::group_from_multiple_links(text, g);
-
- std::cout << "AFTER - nbboxes = " << grouped_text.bboxes().nelements() << std::endl;
-
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("grouped_text.ppm"));
- io::ppm::save(mln::debug::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
- scribo::make::debug_filename("label_color.ppm"));
+ tblboxes_t lineboxes
+ = table::extract_lines_with_rank(input, c8(), nbboxes,
+ vline, hline, 6, 6);
-}
+ value::label_8 ncells;
+ image2d<value::label_8> tables = scribo::table::rebuild(input, lineboxes, 5, ncells);
+
+ std::cout << "ncells (including background) = " << ncells << std::endl;
+ io::ppm::save(mln::debug::colorize(value::rgb8(), tables, ncells),
+ scribo::make::debug_filename("table_cells.ppm"));
+ io::pgm::save(tables, scribo::make::debug_filename("table_cells.pgm"));
+
+ image2d<value::rgb8> input_rgb = level::convert(value::rgb8(), input);
+ data::fill((input_rgb | pw::value(tables) == pw::cst(0u)).rw(), literal::red);
+ io::ppm::save(input_rgb, scribo::make::debug_filename("table_superposed.ppm"));
+
+ image2d<bool> in_wo_tables = table::erase(input, lineboxes);
+ io::pbm::save(in_wo_tables,
+ scribo::make::debug_filename("input_wo_tables.pbm"));
+}
diff --git a/milena/sandbox/scribo/table/align_lines_horizontaly.hh b/milena/sandbox/scribo/table/align_lines_horizontaly.hh
index 4828cfe..88e283e 100644
--- a/milena/sandbox/scribo/table/align_lines_horizontaly.hh
+++ b/milena/sandbox/scribo/table/align_lines_horizontaly.hh
@@ -79,7 +79,7 @@ namespace scribo
util::array<int>
align_lines_horizontaly(const Image<I>& input,
util::array<box<mln_site(I)> >& lines_bboxes,
- max_alignment_diff)
+ unsigned max_alignment_diff)
{
trace::entering("scribo::table::align_lines_horizontaly");
diff --git a/milena/sandbox/scribo/table/align_lines_verticaly.hh b/milena/sandbox/scribo/table/align_lines_verticaly.hh
index e4d04ba..c1062bf 100644
--- a/milena/sandbox/scribo/table/align_lines_verticaly.hh
+++ b/milena/sandbox/scribo/table/align_lines_verticaly.hh
@@ -79,9 +79,10 @@ namespace scribo
template <typename I>
util::array<int>
align_lines_verticaly(const Image<I>& input,
- util::array<box<mln_site(I)> >& lines_bboxes)
+ util::array<box<mln_site(I)> >& lines_bboxes,
+ unsigned max_alignment_diff)
{
- trace::entering("scribo::table::align_lines_horizontaly");
+ trace::entering("scribo::table::align_lines_verticaly");
mln_precondition(exact(input).is_valid());
util::array<int> res = internal::align_lines(geom::ncols(input),
@@ -90,7 +91,7 @@ namespace scribo
lines_bboxes, 1,
max_alignment_diff);
- trace::exiting("scribo::table::align_lines_horizontaly");
+ trace::exiting("scribo::table::align_lines_verticaly");
return res;
}
diff --git a/milena/sandbox/scribo/table/erase.hh b/milena/sandbox/scribo/table/erase.hh
index 9d94edb..2f5957a 100644
--- a/milena/sandbox/scribo/table/erase.hh
+++ b/milena/sandbox/scribo/table/erase.hh
@@ -37,6 +37,8 @@
# include <mln/core/site_set/box.hh>
# include <mln/core/routine/duplicate.hh>
+# include <mln/pw/all.hh>
+
# include <mln/util/array.hh>
# include <mln/util/couple.hh>
@@ -48,6 +50,8 @@ namespace scribo
namespace table
{
+ using namespace mln;
+
/// Erase table line bboxes from an image.
///
/// \param[in] line_bboxes vertical and horizontal line bounding
@@ -64,7 +68,6 @@ namespace scribo
util::array< box<mln_site(I)> > >& line_bboxes);
-
# ifndef MLN_INCLUDE_ONLY
@@ -74,7 +77,7 @@ namespace scribo
const util::couple<util::array< box<mln_site(I)> >,
util::array< box<mln_site(I)> > >& line_bboxes)
{
- trace::entering("scribo::internal::erase_table");
+ trace::entering("scribo::internal::erase");
mlc_equal(mln_value(I),bool)::check();
mln_precondition(exact(in).is_valid());
@@ -83,7 +86,7 @@ namespace scribo
erase_bboxes(output, line_bboxes.first());
erase_bboxes(output, line_bboxes.second());
- trace::exiting("scribo::internal::erase_table");
+ trace::exiting("scribo::internal::erase");
return output;
}
diff --git a/milena/sandbox/scribo/table/extract.hh b/milena/sandbox/scribo/table/extract.hh
index 06520c9..ebe4955 100644
--- a/milena/sandbox/scribo/table/extract.hh
+++ b/milena/sandbox/scribo/table/extract.hh
@@ -51,8 +51,20 @@ namespace scribo
namespace table
{
+ /// Extract tables from a binary image.
+ /// Use arbitrary criterions.
+ /*
+ ** \param[in] input_ A binary image.
+ ** \param[in,out] ncells The number of cells.
+ **
+ ** \return a couple. The first element is an image containing the
+ ** cells components. The second element is a couple of vertical and
+ ** horizontal table lines.
+ */
template <typename I, typename V>
- mln_ch_value(I,V)
+ mln::util::couple<mln_ch_value(I,V),
+ util::couple<util::array<box<mln_site(I)> >,
+ util::array<box<mln_site(I)> > > >
extract(const Image<I>& input_, V& ncells);
@@ -60,7 +72,9 @@ namespace scribo
template <typename I, typename V>
inline
- mln_ch_value(I,V)
+ mln::util::couple<mln_ch_value(I,V),
+ util::couple<util::array<box<mln_site(I)> >,
+ util::array<box<mln_site(I)> > > >
extract(const Image<I>& input_, V& ncells)
{
trace::entering("scribo::table::extract");
@@ -75,11 +89,14 @@ namespace scribo
win::line<mln_grid(I::site), 0, mln_coord(I::site)> vline(51);
win::line<mln_grid(I::site), 1, mln_coord(I::site)> hline(51);
tblboxes_t lineboxes
- = table::extract_lines_with_rank(input, c8(), V(),
+ = table::extract_lines_with_rank(input, c8(), ncells,
vline, hline, 6, 6);
- image2d<V> tables
- = scribo::table::rebuild(input, lineboxes, 30, ncells);
+ typedef mln::util::couple<mln_ch_value(I,V),
+ util::couple<util::array<box<mln_site(I)> >,
+ util::array<box<mln_site(I)> > > >
+ tables_t;
+ tables_t tables = scribo::table::rebuild(input, lineboxes, 30, ncells);
trace::exiting("scribo::table::extract");
return tables;
diff --git a/milena/sandbox/scribo/table/extract_lines_with_opening.hh b/milena/sandbox/scribo/table/extract_lines_with_opening.hh
index 55fd77f..a4ddfd1 100644
--- a/milena/sandbox/scribo/table/extract_lines_with_opening.hh
+++ b/milena/sandbox/scribo/table/extract_lines_with_opening.hh
@@ -63,7 +63,7 @@ namespace scribo
*
* \param[in] input_ A binary image.
* \param[in] nbh_ The neighborhood used for labeling image components.
- * \param[in] label_type The type used to store the labels.
+ * \param[out] nlines The number of lines found.
* \param[in] vwin Window used to extract the vertical lines in a morphological
* opening
* \param[in] hwin Window used to extract the horizontal lines in a morphological
@@ -77,7 +77,7 @@ namespace scribo
util::couple<util::array<box<mln_site(I)> >,
util::array<box<mln_site(I)> > >
extract_lines_with_opening(const Image<I>& input_,
- const Neighborhood<N>& nbh_, const V& label_type,
+ const Neighborhood<N>& nbh_, V& nlines,
const Window<HW>& vwin, const Window<VW>& hwin);
@@ -88,8 +88,8 @@ namespace scribo
util::couple<util::array<box<mln_site(I)> >,
util::array<box<mln_site(I)> > >
extract_lines_with_opening(const Image<I>& input_,
- const Neighborhood<N>& nbh_, const V& label_type,
- const Window<VW>& vwin_, const Window<HW>& hwin_);
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<VW>& vwin_, const Window<HW>& hwin_)
{
trace::entering("scribo::table::extract_lines_with_opening");
@@ -106,12 +106,11 @@ namespace scribo
mln_precondition(vwin.is_valid());
mln_precondition(hwin.is_valid());
- typedef accu::bbox<mln_psite(I)> A;
- typedef util::array<mln_result(A)> boxes_t;
+ typedef util::array<box<mln_site(I)> > boxes_t;
// Vertical lines
mln_ch_value(I,bool) vfilter = morpho::erosion(input, vwin);
- boxes_t vboxes = component_bboxes(vfilter, nbh, label_type);
+ boxes_t vboxes = component_bboxes(vfilter, nbh, nlines).first();
for_all_components(i, vboxes)
{
vboxes[i].enlarge(0, vwin.length() / 2);
@@ -120,7 +119,7 @@ namespace scribo
// Horizontal lines.
mln_ch_value(I,bool) hfilter = morpho::erosion(input, hwin);
- boxes_t hboxes = component_bboxes(hfilter, nbh, label_type);
+ boxes_t hboxes = component_bboxes(hfilter, nbh, nlines).first();
for_all_components(i, hboxes)
{
hboxes[i].enlarge(1, hwin.length() / 2);
diff --git a/milena/sandbox/scribo/table/extract_lines_with_rank.hh b/milena/sandbox/scribo/table/extract_lines_with_rank.hh
index 63c90b1..dbb3d50 100644
--- a/milena/sandbox/scribo/table/extract_lines_with_rank.hh
+++ b/milena/sandbox/scribo/table/extract_lines_with_rank.hh
@@ -63,7 +63,7 @@ namespace scribo
*
* \param[in] input_ A binary image.
* \param[in] nbh_ The neighborhood used for labeling image components.
- * \param[in] label_type The type used to store the labels.
+ * \param[out] nlines The number of lines.
* \param[in] vwin Window used to extract the vertical lines in the rank
* filter.
* \param[in] hwin Window used to extract the horizontal lines in the rank
@@ -79,7 +79,7 @@ namespace scribo
util::couple<util::array<box<mln_site(I)> >,
util::array<box<mln_site(I)> > >
extract_lines_with_rank(const Image<I>& input_,
- const Neighborhood<N>& nbh_, const V& label_type,
+ const Neighborhood<N>& nbh_, V& nlines,
const Window<HW>& vwin, const Window<VW>& hwin,
unsigned vrank_k, unsigned hrank_k);
@@ -91,7 +91,7 @@ namespace scribo
util::couple<util::array<box<mln_site(I)> >,
util::array<box<mln_site(I)> > >
extract_lines_with_rank(const Image<I>& input_,
- const Neighborhood<N>& nbh_, const V& label_type,
+ const Neighborhood<N>& nbh_, V& nlines,
const Window<VW>& vwin_, const Window<HW>& hwin_,
unsigned vrank_k, unsigned hrank_k)
{
@@ -110,12 +110,11 @@ namespace scribo
mln_precondition(vwin.is_valid());
mln_precondition(hwin.is_valid());
- typedef accu::bbox<mln_psite(I)> A;
- typedef util::array<mln_result(A)> boxes_t;
+ typedef util::array<box<mln_site(I)> > boxes_t;
// Vertical lines
mln_ch_value(I,bool) vfilter = morpho::rank_filter(input, vwin, vrank_k);
- boxes_t vboxes = component_bboxes(vfilter, nbh, label_type);
+ boxes_t vboxes = component_bboxes(vfilter, nbh, nlines).first();
for_all_components(i, vboxes)
{
vboxes[i].enlarge(0, vwin.length() / 2);
@@ -124,7 +123,7 @@ namespace scribo
// Horizontal lines.
mln_ch_value(I,bool) hfilter = morpho::rank_filter(input, hwin, hrank_k);
- boxes_t hboxes = component_bboxes(hfilter, nbh, label_type);
+ boxes_t hboxes = component_bboxes(hfilter, nbh, nlines).first();
for_all_components(i, hboxes)
{
hboxes[i].enlarge(1, hwin.length() / 2);
diff --git a/milena/sandbox/scribo/table/rebuild.hh b/milena/sandbox/scribo/table/rebuild.hh
index b78112d..4c632ba 100644
--- a/milena/sandbox/scribo/table/rebuild.hh
+++ b/milena/sandbox/scribo/table/rebuild.hh
@@ -57,7 +57,9 @@ namespace scribo
{
template <typename I, typename V>
- mln_ch_value(I,V)
+ mln::util::couple<mln_ch_value(I,V),
+ util::couple<util::array<box<mln_site(I)> >,
+ util::array<box<mln_site(I)> > > >
rebuild(const Image<I>& in_,
const util::couple<util::array<box<mln_site(I)> >,
util::array<box<mln_site(I)> > >& lineboxes,
@@ -69,7 +71,9 @@ namespace scribo
template <typename I, typename V>
- mln_ch_value(I,V)
+ mln::util::couple<mln_ch_value(I,V),
+ util::couple<util::array<box<mln_site(I)> >,
+ util::array<box<mln_site(I)> > > >
rebuild(const Image<I>& in_,
const util::couple<util::array<box<mln_site(I)> >,
util::array<box<mln_site(I)> > >& lineboxes,
@@ -85,10 +89,6 @@ namespace scribo
util::couple<util::array<box<mln_site(I)> >,
util::array<box<mln_site(I)> > > tblboxes = lineboxes;
-//# ifndef SCRIBO_NDEBUG
-// scribo::debug::save_table_image(in, tblboxes,
-// literal::red, "table.ppm");
-//# endif
scribo::debug::save_table_image(in, tblboxes,
literal::red, "table-raw.ppm");
@@ -121,20 +121,15 @@ namespace scribo
mln_ch_value(I,bool) res;
initialize(res, in);
data::fill(res, false);
- for_all_components(i, tblboxes.first())
+ for_all_elements(i, tblboxes.first())
mln::draw::box(res, tblboxes.first()[i], true);
- for_all_components(i, tblboxes.second())
+ for_all_elements(i, tblboxes.second())
mln::draw::box(res, tblboxes.second()[i], true);
mln_ch_value(I,V) lbl = labeling::background(res, c8(), ncells);
-//# ifndef SCRIBO_NDEBUG
-// scribo::debug::save_table_image(in, tblboxes,
-// literal::red, "table-connected.ppm");
-//# endif
-
trace::exiting("scribo::table::rebuild");
- return lbl;
+ return mln::make::couple(lbl, tblboxes);
}
diff --git a/milena/sandbox/scribo/text/grouping/group_from_double_link.hh b/milena/sandbox/scribo/text/grouping/group_from_double_link.hh
index 582abcd..d4e5d71 100644
--- a/milena/sandbox/scribo/text/grouping/group_from_double_link.hh
+++ b/milena/sandbox/scribo/text/grouping/group_from_double_link.hh
@@ -82,27 +82,31 @@ namespace scribo
mln::util::array< accu::bbox<mln_site(I)> > tboxes;
tboxes.resize(text.bboxes().nelements());
- mln::util::array<unsigned> left_parent = left_link;
- for_all_components(i, left_parent)
- left_parent[i] = internal::find_root(left_parent, i);
-
- fun::i2v::array<mln_value(I)> f(text.bboxes().nelements(),
- literal::zero);
+ mln::util::array<unsigned> parent(left_link.nelements());
+ internal::init_link_array(parent);
for_all_components(i, text.bboxes())
{
unsigned nbh = right_link[left_link[i]];
if (nbh == i)
{
- tboxes[left_parent[i]].take(text.bbox(i));
- f(i) = left_parent[left_link[i]];
- }
- else
- {
- f(i) = i;
- tboxes[i].take(text.bbox(i));
+ unsigned par = internal::find_root(parent, left_link[i]);
+ if (par < i)
+ parent[par] = i;
+ else
+ parent[i] = par;
}
}
+ for_all_elements(i, parent)
+ for (unsigned i = parent.nelements() - 1; i < parent.nelements(); --i)
+ {
+ parent[i] = parent[parent[i]];
+ tboxes[parent[i]].take(text.bbox(i));
+ }
+
+ fun::i2v::array<unsigned> f;
+ convert::from_to(parent, f);
+
// Update bounding boxes information.
mln::util::array< box<mln_site(I)> > bresult;
// component 0, the background, has an invalid box.
diff --git a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh b/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
index 236cf16..bfe1bc3 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
@@ -35,6 +35,8 @@
/// Group character bounding boxes with multiple links.
# include <mln/core/concept/image.hh>
+# include <mln/labeling/compute.hh>
+# include <mln/accu/center.hh>
# include <mln/math/abs.hh>
@@ -55,35 +57,47 @@ namespace scribo
{
/// Group character bounding boxes with multiple links.
- /// Look up for neighbors on the left of each box.
- template <typename I>
+ /// Look up for neighbors on the right of each box.
+ template <typename L>
mln::util::graph
- group_with_multiple_links(const scribo::util::text<I>& text,
+ group_with_multiple_links(const scribo::util::text<L>& text,
unsigned neighb_max_distance);
# ifndef MLN_INCLUDE_ONLY
- template <typename I>
+ template <typename L>
inline
mln::util::graph
- group_with_multiple_links(const scribo::util::text<I>& text,
+ group_with_multiple_links(const scribo::util::text<L>& text,
unsigned neighb_max_distance)
{
trace::entering("scribo::text::grouping::group_with_multiple_links");
mln::util::graph g(text.nbboxes().next());
+ mln::util::array<mln_site(L)::vec> centers
+ = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
+
for_all_ncomponents(i, text.nbboxes())
{
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
- mln_site(I) c = text.bbox(i).center();
-
+ mln_site(L) c = centers[i];
+
+ // -------
+ // | |
+ // | |
+ // | |
+ // | X------->
+ // | |
+ // | |
+ // | |
+ // -------
/// First site on the right of the central site
- mln_site(I) p = c + right;
+ mln_site(L) p = c + right;
- const I& lbl = text.label_image();
+ const L& lbl = text.label_image();
while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i)
&& math::abs(p.col() - c.col()) < dmax)
++p.col();
diff --git a/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh b/milena/sandbox/scribo/text/grouping/group_with_several_left_links.hh
similarity index 53%
copy from milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh
copy to milena/sandbox/scribo/text/grouping/group_with_several_left_links.hh
index ca1a8da..84a743d 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_several_left_links.hh
@@ -27,10 +27,10 @@
// Public License.
-#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_LEFT_LINK_HH
-# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_LEFT_LINK_HH
+#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_LEFT_LINKS_HH
+# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_LEFT_LINKS_HH
-/// \file scribo/text/grouping/group_with_single_left_link.hh
+/// \file scribo/text/grouping/group_with_several_left_links.hh
///
/// Link text bounding boxes with their left neighbor.
///
@@ -38,19 +38,16 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-
-# include <mln/math/abs.hh>
+# include <mln/labeling/compute.hh>
+# include <mln/accu/center.hh>
# include <mln/util/array.hh>
# include <scribo/core/macros.hh>
# include <scribo/text/grouping/internal/init_link_array.hh>
-# include <scribo/text/grouping/internal/update_link_array.hh>
-# include <scribo/text/grouping/internal/find_root.hh>
+# include <scribo/text/grouping/internal/find_left_link.hh>
# include <scribo/util/text.hh>
-//FIXME: not generic.
-# include <mln/core/alias/dpoint2d.hh>
namespace scribo
{
@@ -69,50 +66,80 @@ namespace scribo
template <typename L>
inline
mln::util::array<unsigned>
- group_with_single_left_link(const scribo::util::text<L>& text,
- unsigned neighb_max_distance);
+ group_with_several_left_links(const scribo::util::text<L>& text,
+ unsigned neighb_max_distance);
# ifndef MLN_INCLUDE_ONLY
template <typename L>
inline
mln::util::array<unsigned>
- group_with_single_left_link(const scribo::util::text<L>& text,
- unsigned neighb_max_distance)
+ group_with_several_left_links(const scribo::util::text<L>& text,
+ unsigned neighb_max_distance)
{
- trace::entering("scribo::text::grouping::group_with_single_left_link");
+ trace::entering("scribo::text::grouping::group_with_several_left_links");
mln_precondition(text.is_valid());
- mln::util::array<unsigned> left_link(text.nbboxes().next());
- internal::init_link_array(left_link);
+ mln::util::array<unsigned>
+ link_1(text.nbboxes().next()), link_2(text.nbboxes().next()),
+ link_3(text.nbboxes().next()), final_link(text.nbboxes().next());
+ internal::init_link_array(link_1);
+ internal::init_link_array(link_2);
+ internal::init_link_array(link_3);
+
+ //FIXME: should be removed if this information is stored in util::text.
+ mln::util::array<mln_site(L)::vec> centers
+ = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
+ std::cout << "dmax = " << neighb_max_distance << std::endl;
for_all_ncomponents(i, text.nbboxes())
{
+ // -------
+ // | X------->
+ // | |
+ // | |
+ // | X------->
+ // | |
+ // | |
+ // | X------->
+ // -------
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
+
mln_site(L) c = text.bbox(i).center();
- ///
- /// Find a neighbor on the right
- ///
+ /// Left link from the top anchor.
+ mln_site(L) a1 = c;
+ a1.row() = text.bbox(i).pmin().row() + (c.row() - text.bbox(i).pmin().row()) / 4;
+ internal::find_left_link(text, link_1, i, dmax, a1);
- ///FIXME: the following code is not generic...
- /// First site on the right of the central site
- mln_site(L) p = c + right;
+ /// Left link from the central site
+ internal::find_left_link(text, link_2, i, dmax, centers[i]);
- const L& lbl = text.label_image();
- while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i ||
- left_link[i] == lbl(p))
- && math::abs(p.col() - c.col()) < dmax)
- ++p.col();
+ /// Left link from the bottom anchor.
+ mln_site(L) a2 = c;
+ a2.row() = text.bbox(i).pmax().row() - (c.row() - text.bbox(i).pmin().row()) / 4;
+ internal::find_left_link(text, link_3, i, dmax, a2);
+ }
- internal::update_link_array(lbl, left_link, p, c, i, dmax);
+ for_all_ncomponents(i, text.nbboxes())
+ {
+ if (link_2[i] != i)
+ final_link[i] = link_2[i];
+ else if (link_1[i] == link_3[i])
+ final_link[i] = link_1[i];
+ else if (link_1[i] != i && link_3[i] == i)
+ final_link[i] = link_1[i];
+ else if (link_3[i] != i && link_1[i] == i)
+ final_link[i] = link_3[i];
+ else
+ final_link[i] = i;
}
- trace::exiting("scribo::text::grouping::group_with_single_left_link");
- return left_link;
+ trace::exiting("scribo::text::grouping::group_with_several_left_links");
+ return final_link;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -123,4 +150,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_LEFT_LINK_HH
+#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_LEFT_LINKS_HH
diff --git a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh b/milena/sandbox/scribo/text/grouping/group_with_several_multiple_links.hh
similarity index 58%
copy from milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
copy to milena/sandbox/scribo/text/grouping/group_with_several_multiple_links.hh
index 236cf16..4dec5c7 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_several_multiple_links.hh
@@ -27,14 +27,16 @@
// Public License.
-#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
-# define SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
+#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_MULTIPLE_LINKS_HH
+# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_MULTIPLE_LINKS_HH
-/// \file scribo/text/grouping/group_with_multiple_links.hh
+/// \file scribo/text/grouping/group_with_several_multiple_links.hh
///
-/// Group character bounding boxes with multiple links.
+/// Group character bounding boxes with several multiple links.
# include <mln/core/concept/image.hh>
+# include <mln/labeling/compute.hh>
+# include <mln/accu/center.hh>
# include <mln/math/abs.hh>
@@ -43,6 +45,7 @@
# include <scribo/core/macros.hh>
# include <scribo/text/grouping/internal/init_link_array.hh>
# include <scribo/text/grouping/internal/update_link_graph.hh>
+# include <scribo/text/grouping/internal/find_left_graph_link.hh>
# include <scribo/util/text.hh>
namespace scribo
@@ -54,44 +57,61 @@ namespace scribo
namespace grouping
{
- /// Group character bounding boxes with multiple links.
+ /// Group character bounding boxes with several_multiple links.
/// Look up for neighbors on the left of each box.
- template <typename I>
+ template <typename L>
mln::util::graph
- group_with_multiple_links(const scribo::util::text<I>& text,
+ group_with_several_multiple_links(const scribo::util::text<L>& text,
unsigned neighb_max_distance);
# ifndef MLN_INCLUDE_ONLY
- template <typename I>
+ template <typename L>
inline
mln::util::graph
- group_with_multiple_links(const scribo::util::text<I>& text,
+ group_with_several_multiple_links(const scribo::util::text<L>& text,
unsigned neighb_max_distance)
{
- trace::entering("scribo::text::grouping::group_with_multiple_links");
+ trace::entering("scribo::text::grouping::group_with_several_multiple_links");
mln::util::graph g(text.nbboxes().next());
+ mln::util::array<mln_site(L)::vec> centers
+ = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
+
for_all_ncomponents(i, text.nbboxes())
{
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
- mln_site(I) c = text.bbox(i).center();
+ mln_site(L) c = centers[i];
+
+ // -------
+ // | X------->
+ // | |
+ // | |
+ // | X------->
+ // | |
+ // | |
+ // | X------->
+ // -------
+
+ /// Left link from the top anchor.
+ mln_site(L) a1 = c;
+ a1.row() = text.bbox(i).pmin().row() + (c.row() - text.bbox(i).pmin().row()) / 4;
+ internal::find_left_graph_link(g, text, i, dmax, a1);
/// First site on the right of the central site
- mln_site(I) p = c + right;
+ internal::find_left_graph_link(g, text, i, dmax, c);
- const I& lbl = text.label_image();
- while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i)
- && math::abs(p.col() - c.col()) < dmax)
- ++p.col();
+ /// Left link from the bottom anchor.
+ mln_site(L) a2 = c;
+ a2.row() = text.bbox(i).pmax().row() - (c.row() - text.bbox(i).pmin().row()) / 4;
+ internal::find_left_graph_link(g, text, i, dmax, a2);
- internal::update_link_graph(lbl, g, p, c, i, dmax);
}
- trace::exiting("scribo::text::grouping::group_with_multiple_links");
+ trace::exiting("scribo::text::grouping::group_with_several_multiple_links");
return g;
}
@@ -103,4 +123,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
+#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_MULTIPLE_LINKS_HH
diff --git a/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh b/milena/sandbox/scribo/text/grouping/group_with_several_right_links.hh
similarity index 53%
copy from milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh
copy to milena/sandbox/scribo/text/grouping/group_with_several_right_links.hh
index 5740b09..cc2ee2c 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_several_right_links.hh
@@ -27,10 +27,10 @@
// Public License.
-#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_RIGHT_LINK_HH
-# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_RIGHT_LINK_HH
+#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_RIGHT_LINKS_HH
+# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_RIGHT_LINKS_HH
-/// \file scribo/text/grouping/group_with_single_right_link.hh
+/// \file scribo/text/grouping/group_with_several_right_links.hh
///
/// Link text bounding boxes with their right neighbor.
///
@@ -38,19 +38,16 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-
-# include <mln/math/abs.hh>
+# include <mln/labeling/compute.hh>
+# include <mln/accu/center.hh>
# include <mln/util/array.hh>
# include <scribo/core/macros.hh>
# include <scribo/text/grouping/internal/init_link_array.hh>
-# include <scribo/text/grouping/internal/update_link_array.hh>
-# include <scribo/text/grouping/internal/find_root.hh>
+# include <scribo/text/grouping/internal/find_right_link.hh>
# include <scribo/util/text.hh>
-//FIXME: not generic.
-# include <mln/core/alias/dpoint2d.hh>
namespace scribo
{
@@ -69,50 +66,80 @@ namespace scribo
template <typename L>
inline
mln::util::array<unsigned>
- group_with_single_right_link(const scribo::util::text<L>& text,
- unsigned neighb_max_distance);
+ group_with_several_right_links(const scribo::util::text<L>& text,
+ unsigned neighb_max_distance);
# ifndef MLN_INCLUDE_ONLY
template <typename L>
inline
mln::util::array<unsigned>
- group_with_single_right_link(const scribo::util::text<L>& text,
- unsigned neighb_max_distance)
+ group_with_several_right_links(const scribo::util::text<L>& text,
+ unsigned neighb_max_distance)
{
- trace::entering("scribo::text::grouping::group_with_single_right_link");
+ trace::entering("scribo::text::grouping::group_with_several_right_links");
mln_precondition(text.is_valid());
- mln::util::array<unsigned> right_link(text.nbboxes().next());
- internal::init_link_array(right_link);
+ mln::util::array<unsigned>
+ link_1(text.nbboxes().next()), link_2(text.nbboxes().next()),
+ link_3(text.nbboxes().next()), final_link(text.nbboxes().next());
+ internal::init_link_array(link_1);
+ internal::init_link_array(link_2);
+ internal::init_link_array(link_3);
+
+ //FIXME: should be removed if this information is stored in util::text.
+ mln::util::array<mln_site(L)::vec> centers
+ = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
+ std::cout << "dmax = " << neighb_max_distance << std::endl;
for_all_ncomponents(i, text.nbboxes())
{
+ // -------
+ // <------X |
+ // | |
+ // | |
+ // <------X |
+ // | |
+ // | |
+ // <------X |
+ // -------
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
+
mln_site(L) c = text.bbox(i).center();
- ///
- /// Find a neighbor on the left
- ///
+ /// Right link from the top anchor.
+ mln_site(L) a1 = c;
+ a1.row() = text.bbox(i).pmin().row() + (c.row() - text.bbox(i).pmin().row()) / 4;
+ internal::find_right_link(text, link_1, i, dmax, a1);
- ///FIXME: the following code is not generic...
- /// First site on the left of the central site
- mln_site(L) p = c + left;
+ /// Right link from the central site
+ internal::find_right_link(text, link_2, i, dmax, centers[i]);
- const L& lbl = text.label_image();
- while (lbl.domain().has(p) && (lbl(p) == literal::zero
- || lbl(p) == i || right_link[i] == lbl(p))
- && math::abs(p.col() - c.col()) < dmax)
- --p.col();
+ /// Right link from the bottom anchor.
+ mln_site(L) a2 = c;
+ a2.row() = text.bbox(i).pmax().row() - (c.row() - text.bbox(i).pmin().row()) / 4;
+ internal::find_right_link(text, link_3, i, dmax, a2);
+ }
- internal::update_link_array(lbl, right_link, p, c, i, dmax);
+ for_all_ncomponents(i, text.nbboxes())
+ {
+ if (link_2[i] != i)
+ final_link[i] = link_2[i];
+ else if (link_1[i] == link_3[i])
+ final_link[i] = link_1[i];
+ else if (link_1[i] != i && link_3[i] == i)
+ final_link[i] = link_1[i];
+ else if (link_3[i] != i && link_1[i] == i)
+ final_link[i] = link_3[i];
+ else
+ final_link[i] = i;
}
- trace::exiting("scribo::text::grouping::group_with_single_right_link");
- return right_link;
+ trace::exiting("scribo::text::grouping::group_with_several_right_links");
+ return final_link;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -123,4 +150,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_RIGHT_LINK_HH
+#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_RIGHT_LINKS_HH
diff --git a/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh b/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh
index ca1a8da..1b39485 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh
@@ -38,6 +38,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
+# include <mln/labeling/compute.hh>
# include <mln/math/abs.hh>
@@ -45,8 +46,7 @@
# include <scribo/core/macros.hh>
# include <scribo/text/grouping/internal/init_link_array.hh>
-# include <scribo/text/grouping/internal/update_link_array.hh>
-# include <scribo/text/grouping/internal/find_root.hh>
+# include <scribo/text/grouping/internal/find_left_link.hh>
# include <scribo/util/text.hh>
//FIXME: not generic.
@@ -87,28 +87,18 @@ namespace scribo
mln::util::array<unsigned> left_link(text.nbboxes().next());
internal::init_link_array(left_link);
+ mln::util::array<mln_site(L)::vec> centers
+ = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
+
for_all_ncomponents(i, text.nbboxes())
{
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
- mln_site(L) c = text.bbox(i).center();
-
- ///
- /// Find a neighbor on the right
- ///
-
- ///FIXME: the following code is not generic...
- /// First site on the right of the central site
- mln_site(L) p = c + right;
-
- const L& lbl = text.label_image();
- while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i ||
- left_link[i] == lbl(p))
- && math::abs(p.col() - c.col()) < dmax)
- ++p.col();
+ mln_site(L) c = centers[i];
- internal::update_link_array(lbl, left_link, p, c, i, dmax);
+ /// Find a neighbor on the left
+ internal::find_left_link(text, left_link, i, dmax, c);
}
trace::exiting("scribo::text::grouping::group_with_single_left_link");
diff --git a/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh b/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh
index 5740b09..6327d9f 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh
@@ -34,10 +34,11 @@
///
/// Link text bounding boxes with their right neighbor.
///
-/// Merge code with text::grouping::group_with_single_right_link.hh
+/// \todo Merge code with text::grouping::group_with_single_right_link.hh
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
+# include <mln/labeling/compute.hh>
# include <mln/math/abs.hh>
@@ -47,6 +48,7 @@
# include <scribo/text/grouping/internal/init_link_array.hh>
# include <scribo/text/grouping/internal/update_link_array.hh>
# include <scribo/text/grouping/internal/find_root.hh>
+# include <scribo/text/grouping/internal/find_right_link.hh>
# include <scribo/util/text.hh>
//FIXME: not generic.
@@ -87,28 +89,20 @@ namespace scribo
mln::util::array<unsigned> right_link(text.nbboxes().next());
internal::init_link_array(right_link);
+ mln::util::array<mln_site(L)::vec> centers
+ = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
+
for_all_ncomponents(i, text.nbboxes())
{
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
- mln_site(L) c = text.bbox(i).center();
+ mln_site(L) c = centers[i];
///
- /// Find a neighbor on the left
+ /// Find a neighbor on the right
///
-
- ///FIXME: the following code is not generic...
- /// First site on the left of the central site
- mln_site(L) p = c + left;
-
- const L& lbl = text.label_image();
- while (lbl.domain().has(p) && (lbl(p) == literal::zero
- || lbl(p) == i || right_link[i] == lbl(p))
- && math::abs(p.col() - c.col()) < dmax)
- --p.col();
-
- internal::update_link_array(lbl, right_link, p, c, i, dmax);
+ internal::find_right_link(text, right_link, i, dmax, c);
}
trace::exiting("scribo::text::grouping::group_with_single_right_link");
diff --git a/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh b/milena/sandbox/scribo/text/grouping/internal/find_left_graph_link.hh
similarity index 58%
copy from milena/sandbox/scribo/text/grouping/internal/update_link_array.hh
copy to milena/sandbox/scribo/text/grouping/internal/find_left_graph_link.hh
index 501d6f2..4055ea1 100644
--- a/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh
+++ b/milena/sandbox/scribo/text/grouping/internal/find_left_graph_link.hh
@@ -26,19 +26,24 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
+#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_GRAPH_LINK_HH
+# define SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_GRAPH_LINK_HH
-#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_LINK_ARRAY_HH
-# define SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_LINK_ARRAY_HH
-
-/// \file scribo/text/grouping/internal/update_link_array.hh
+/// \file scribo/text/grouping/internal/find_left_graph_link.hh
+///
///
-/// Update a lookup table if a neighbor is found on the right of
-/// the current bbox.
-
# include <mln/core/concept/image.hh>
+
+# include <mln/math/abs.hh>
+
# include <mln/util/array.hh>
+# include <scribo/util/text.hh>
+# include <scribo/text/grouping/internal/update_link_graph.hh>
+
+//FIXME: not generic.
+# include <mln/core/alias/dpoint2d.hh>
namespace scribo
{
@@ -52,35 +57,38 @@ namespace scribo
namespace internal
{
- /// Update the lookup table \p link_array if a neighbor is found
- /// on the right of the current bbox.
- template <typename I>
+ template <typename L>
void
- update_link_array(const Image<I>& lbl, mln::util::array<unsigned>& link_array,
- const mln_site(I)& p, const mln_site(I)& c,
- unsigned i, int dmax);
+ find_left_graph_link(const scribo::util::text<L>& text,
+ mln::util::array<unsigned>& left_link,
+ unsigned current_comp,
+ int dmax,
+ const mln_site(L)& c);
# ifndef MLN_INCLUDE_ONLY
- template <typename I>
- inline
+ template <typename L>
void
- update_link_array(const Image<I>& lbl_, mln::util::array<unsigned>& link_array,
- const mln_site(I)& p, const mln_site(I)& c,
- unsigned i, int dmax)
+ find_left_graph_link(mln::util::graph& g,
+ const scribo::util::text<L>& text,
+ unsigned current_comp,
+ int dmax,
+ const mln_site(L)& c)
{
- const I& lbl = exact(lbl_);
+ ///FIXME: the following code is not generic...
+ /// First site on the right of the central site
+ mln_site(L) p = c + left;
- mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
- mln_assertion(lbl.is_valid());
+ const L& lbl = text.label_image();
+ while (lbl.domain().has(p) && (lbl(p) == literal::zero
+ || lbl(p) == current_comp)
+ && math::abs(p.col() - c.col()) < dmax)
+ --p.col();
- if (lbl.domain().has(p) && lbl(p) != literal::zero && lbl(p) != i
- && (math::abs(p.col() - c.col())) < dmax && link_array[lbl(p)] == lbl(p)
- && link_array[i] != lbl(p))
- link_array[lbl(p)] = i;
+ update_link_graph(lbl, g, p, c, current_comp, dmax);
}
-# endif // ! MLN_INCLUDE_ONLY
+# endif // MLN_INCLUDE_ONLY
} // end of namespace scribo::text::grouping::internal
@@ -91,4 +99,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_LINK_ARRAY_HH
+#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_GRAPH_LINK_HH
diff --git a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh b/milena/sandbox/scribo/text/grouping/internal/find_left_link.hh
similarity index 52%
copy from milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
copy to milena/sandbox/scribo/text/grouping/internal/find_left_link.hh
index 236cf16..4695012 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
+++ b/milena/sandbox/scribo/text/grouping/internal/find_left_link.hh
@@ -26,13 +26,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
+#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_LINK_HH
+# define SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_LINK_HH
-#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
-# define SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
-
-/// \file scribo/text/grouping/group_with_multiple_links.hh
+/// \file scribo/text/grouping/internal/find_left_link.hh
+///
///
-/// Group character bounding boxes with multiple links.
# include <mln/core/concept/image.hh>
@@ -40,10 +39,11 @@
# include <mln/util/array.hh>
-# include <scribo/core/macros.hh>
-# include <scribo/text/grouping/internal/init_link_array.hh>
-# include <scribo/text/grouping/internal/update_link_graph.hh>
# include <scribo/util/text.hh>
+# include <scribo/text/grouping/internal/update_link_array.hh>
+
+//FIXME: not generic.
+# include <mln/core/alias/dpoint2d.hh>
namespace scribo
{
@@ -54,48 +54,52 @@ namespace scribo
namespace grouping
{
- /// Group character bounding boxes with multiple links.
- /// Look up for neighbors on the left of each box.
- template <typename I>
- mln::util::graph
- group_with_multiple_links(const scribo::util::text<I>& text,
- unsigned neighb_max_distance);
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename I>
- inline
- mln::util::graph
- group_with_multiple_links(const scribo::util::text<I>& text,
- unsigned neighb_max_distance)
+ namespace internal
{
- trace::entering("scribo::text::grouping::group_with_multiple_links");
- mln::util::graph g(text.nbboxes().next());
+ template <typename L>
+ void
+ find_left_link(const scribo::util::text<L>& text,
+ mln::util::array<unsigned>& left_link,
+ unsigned current_comp,
+ int dmax,
+ const mln_site(L)& c);
- for_all_ncomponents(i, text.nbboxes())
- {
- unsigned midcol = (text.bbox(i).pmax().col()
- - text.bbox(i).pmin().col()) / 2;
- int dmax = midcol + neighb_max_distance;
- mln_site(I) c = text.bbox(i).center();
+# ifndef MLN_INCLUDE_ONLY
+ template <typename L>
+ void
+ find_left_link(const scribo::util::text<L>& text,
+ mln::util::array<unsigned>& left_link,
+ unsigned current_comp,
+ int dmax,
+ const mln_site(L)& c)
+ {
+ ///FIXME: the following code is not generic...
/// First site on the right of the central site
- mln_site(I) p = c + right;
-
- const I& lbl = text.label_image();
- while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i)
- && math::abs(p.col() - c.col()) < dmax)
- ++p.col();
-
- internal::update_link_graph(lbl, g, p, c, i, dmax);
+ mln_site(L) p = c + left;
+
+ /// Construct a new label image with the components bounding
+ /// boxes only.
+ /// TOO SLOW, so disabled!!!
+// L lbl(text.label_image().domain());
+// for_all_components(i, text.bboxes())
+// mln::draw::box(lbl, text.bbox(i), i);
+ const L& lbl = text.label_image();
+
+ while (lbl.domain().has(p) // Not outside image domain
+ && (lbl(p) == literal::zero // Is the background
+ || lbl(p) == current_comp // Is the current component
+ || left_link[lbl(p)] == current_comp) // Creates a loop
+ && math::abs(p.col() - c.col()) < dmax) // Not to far
+ --p.col();
+
+ update_link_array(lbl, left_link, p, c, current_comp, dmax);
}
- trace::exiting("scribo::text::grouping::group_with_multiple_links");
- return g;
- }
+# endif // MLN_INCLUDE_ONLY
-# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace scribo::text::grouping::internal
} // end of namespace scribo::text::grouping
@@ -103,4 +107,5 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
+
+#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_LINK_HH
diff --git a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh b/milena/sandbox/scribo/text/grouping/internal/find_right_link.hh
similarity index 52%
copy from milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
copy to milena/sandbox/scribo/text/grouping/internal/find_right_link.hh
index 236cf16..e83aa46 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
+++ b/milena/sandbox/scribo/text/grouping/internal/find_right_link.hh
@@ -26,13 +26,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
+#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_FIND_RIGHT_LINK_HH
+# define SCRIBO_TEXT_GROUPING_INTERNAL_FIND_RIGHT_LINK_HH
-#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
-# define SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
-
-/// \file scribo/text/grouping/group_with_multiple_links.hh
+/// \file scribo/text/grouping/internal/find_right_link.hh
+///
///
-/// Group character bounding boxes with multiple links.
# include <mln/core/concept/image.hh>
@@ -40,10 +39,11 @@
# include <mln/util/array.hh>
-# include <scribo/core/macros.hh>
-# include <scribo/text/grouping/internal/init_link_array.hh>
-# include <scribo/text/grouping/internal/update_link_graph.hh>
# include <scribo/util/text.hh>
+# include <scribo/text/grouping/internal/update_link_array.hh>
+
+//FIXME: not generic.
+# include <mln/core/alias/dpoint2d.hh>
namespace scribo
{
@@ -54,48 +54,52 @@ namespace scribo
namespace grouping
{
- /// Group character bounding boxes with multiple links.
- /// Look up for neighbors on the left of each box.
- template <typename I>
- mln::util::graph
- group_with_multiple_links(const scribo::util::text<I>& text,
- unsigned neighb_max_distance);
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename I>
- inline
- mln::util::graph
- group_with_multiple_links(const scribo::util::text<I>& text,
- unsigned neighb_max_distance)
+ namespace internal
{
- trace::entering("scribo::text::grouping::group_with_multiple_links");
- mln::util::graph g(text.nbboxes().next());
+ template <typename L>
+ void
+ find_right_link(const scribo::util::text<L>& text,
+ mln::util::array<unsigned>& right_link,
+ unsigned current_comp,
+ int dmax,
+ const mln_site(L)& c);
- for_all_ncomponents(i, text.nbboxes())
- {
- unsigned midcol = (text.bbox(i).pmax().col()
- - text.bbox(i).pmin().col()) / 2;
- int dmax = midcol + neighb_max_distance;
- mln_site(I) c = text.bbox(i).center();
+# ifndef MLN_INCLUDE_ONLY
+ template <typename L>
+ void
+ find_right_link(const scribo::util::text<L>& text,
+ mln::util::array<unsigned>& right_link,
+ unsigned current_comp,
+ int dmax,
+ const mln_site(L)& c)
+ {
+ ///FIXME: the following code is not generic...
/// First site on the right of the central site
- mln_site(I) p = c + right;
-
- const I& lbl = text.label_image();
- while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i)
- && math::abs(p.col() - c.col()) < dmax)
+ mln_site(L) p = c + right;
+
+ /// Construct a new label image with the components bounding
+ /// boxes only.
+ /// TOO SLOW, so disabled!!!
+// L lbl(text.label_image().domain());
+// for_all_components(i, text.bboxes())
+// mln::draw::box(lbl, text.bbox(i), i);
+ const L& lbl = text.label_image();
+
+ while (lbl.domain().has(p) // Not outside image domain
+ && (lbl(p) == literal::zero // Is the background
+ || lbl(p) == current_comp // Is the current component
+ || right_link[lbl(p)] == current_comp) // Creates a loop
+ && math::abs(p.col() - c.col()) < dmax) // Not too far
++p.col();
- internal::update_link_graph(lbl, g, p, c, i, dmax);
+ update_link_array(lbl, right_link, p, c, current_comp, dmax);
}
- trace::exiting("scribo::text::grouping::group_with_multiple_links");
- return g;
- }
+# endif // MLN_INCLUDE_ONLY
-# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace scribo::text::grouping::internal
} // end of namespace scribo::text::grouping
@@ -103,4 +107,5 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
+
+#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_FIND_RIGHT_LINK_HH
diff --git a/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh b/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh
index 501d6f2..1642d1a 100644
--- a/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh
+++ b/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh
@@ -74,10 +74,12 @@ namespace scribo
mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
mln_assertion(lbl.is_valid());
- if (lbl.domain().has(p) && lbl(p) != literal::zero && lbl(p) != i
- && (math::abs(p.col() - c.col())) < dmax && link_array[lbl(p)] == lbl(p)
- && link_array[i] != lbl(p))
- link_array[lbl(p)] = i;
+ if (lbl.domain().has(p) // Not outside image domain
+ && lbl(p) != literal::zero // Not the background
+ && lbl(p) != i // Not the current component
+ && (math::abs(p.col() - c.col())) < dmax // Not too far
+ && link_array[lbl(p)] != i) // Not creating a loop
+ link_array[i] = lbl(p);
}
# endif // ! MLN_INCLUDE_ONLY
--
1.5.6.5
1
0
* headers.mk: update distributed header list.
* doc/ref_guide/ref_guide.tex: update reference to clone().
* doc/tutorial/tutorial.tex: fix references.
* mln/accu/center.hh: Fix meta accu.
* mln/canvas/browsing/depth_first_search.hh: update functor interface.
* mln/core/concept/function.hh: Introduce Function_i2b.
* mln/debug/colorize.hh: call srand.
* mln/fun/i2v/array.hh: update from_to overloads: add a special case
for element[0].
* mln/io/pgm/save.hh: Check if the image is compatible with pgm
format.
* mln/labeling/level.hh,
* mln/labeling/regional_maxima.hh: avoid warnings.
* mln/labeling/relabel.hh: update call to make::relabelfun.
* mln/make/graph.hh: adjust extension to structural element.
* mln/util/array.hh:
- add subject_impl specialization.
- Update from_to overloads: add a special case for element[0].
* tests/accu/site_set/rectangularity.cc: add more tests.
* tests/unit_test/unit-tests.mk: update unit test list.
---
milena/ChangeLog | 41 +++++
milena/doc/Doxyfile.in | 2 +-
milena/doc/ref_guide/ref_guide.tex | 4 +-
milena/doc/tutorial/tutorial.tex | 50 +++---
milena/headers.mk | 14 ++-
milena/mln/accu/center.hh | 5 +-
milena/mln/canvas/browsing/depth_first_search.hh | 14 +-
milena/mln/core/concept/function.hh | 38 ++++
milena/mln/debug/colorize.hh | 1 +
milena/mln/fun/i2v/array.hh | 48 +++++-
milena/mln/io/pgm/save.hh | 12 +-
milena/mln/labeling/level.hh | 4 +-
milena/mln/labeling/regional_maxima.hh | 2 +-
milena/mln/labeling/relabel.hh | 2 +-
milena/mln/make/graph.hh | 4 +
milena/mln/util/array.hh | 197 +++++++++++++++++++++-
milena/tests/accu/site_set/rectangularity.cc | 15 ++-
milena/tests/unit_test/unit-tests.mk | 30 +++-
18 files changed, 410 insertions(+), 73 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 31180d8..cbbdf13 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,46 @@
2009-03-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Small fixes.
+
+ * headers.mk: update distributed header list.
+
+ * doc/Doxyfile.in: Do not use mln:: prefix in class name lists.
+
+ * doc/ref_guide/ref_guide.tex: update reference to clone().
+
+ * doc/tutorial/tutorial.tex: fix references.
+
+ * mln/accu/center.hh: Fix meta accu.
+
+ * mln/canvas/browsing/depth_first_search.hh: update functor interface.
+
+ * mln/core/concept/function.hh: Introduce Function_i2b.
+
+ * mln/debug/colorize.hh: call srand.
+
+ * mln/fun/i2v/array.hh: update from_to overloads: add a special case
+ for element[0].
+
+ * mln/io/pgm/save.hh: Check if the image is compatible with pgm
+ format.
+
+ * mln/labeling/level.hh,
+ * mln/labeling/regional_maxima.hh: avoid warnings.
+
+ * mln/labeling/relabel.hh: update call to make::relabelfun.
+
+ * mln/make/graph.hh: adjust extension to structural element.
+
+ * mln/util/array.hh:
+ - add subject_impl specialization.
+ - Update from_to overloads: add a special case for element[0].
+
+ * tests/accu/site_set/rectangularity.cc: add more tests.
+
+ * tests/unit_test/unit-tests.mk: update unit test list.
+
+2009-03-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Fix compilation issues with Cygwin.
* mln/convert/from_to.hxx,
diff --git a/milena/doc/Doxyfile.in b/milena/doc/Doxyfile.in
index 053cbe7..649ea2f 100644
--- a/milena/doc/Doxyfile.in
+++ b/milena/doc/Doxyfile.in
@@ -118,7 +118,7 @@ VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 5
-IGNORE_PREFIX =
+IGNORE_PREFIX = mln::
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
diff --git a/milena/doc/ref_guide/ref_guide.tex b/milena/doc/ref_guide/ref_guide.tex
index 28bc543..43f8787 100644
--- a/milena/doc/ref_guide/ref_guide.tex
+++ b/milena/doc/ref_guide/ref_guide.tex
@@ -1483,7 +1483,7 @@ variable behaves like some mathematical variable. Put differently it is just a
name to designate an image:
\doxycode{ima2d-5}
-If a deep copy of the image is needed, a clone() routine is available:
+If a deep copy of the image is needed, a duplicate() routine is available:
\doxycode{ima2d-6-clone}
Output:
\doxyoutput{ima2d-6-clone}
@@ -1499,7 +1499,7 @@ Output:
\begin{tabular}{l|p{8cm}}
\hline
Routine name & Description \\ \hline
-level::clone() & creates a deep copy of an object. Any shared data is
+duplicate() & creates a deep copy of an object. Any shared data is
duplicated. \\
data::fill() & fill an object with a value. \\
diff --git a/milena/doc/tutorial/tutorial.tex b/milena/doc/tutorial/tutorial.tex
index a36a365..ede9d90 100644
--- a/milena/doc/tutorial/tutorial.tex
+++ b/milena/doc/tutorial/tutorial.tex
@@ -318,7 +318,6 @@ $$
\backslash endhtmlonly
\backslash page tutorial Tutorial
-- \backslash subpage tuto0
- \backslash subpage tuto1
- \backslash subpage tuto2
- \backslash subpage tuto3
@@ -347,7 +346,6 @@ A copy of the license is provided in the file COPYING.DOC.
\tableofcontents
\end{latexonly}
-%\begin{htmlonly}
%====================================
\doxychapter{tuto1}{Welcome}
@@ -475,7 +473,7 @@ We invite you to take a look at the description of the directory structure
(\ref{tuto1dirstruct}.
If you encounter any issues in the installation process or if you have any
question, do not forget to join the mailing lists (\ref{tuto1mailinglists}
-and/or use the other documentations ressources (\ref{tuto1ressources}).
+and/or use the other documentations ressources (\ref{tuto1documentation}).
@@ -488,11 +486,7 @@ and/or use the other documentations ressources (\ref{tuto1ressources}).
Milena's packages can be downloaded from:
-\begin{center}
-\begin{verbatim}
-http://www.lrde.epita.fr/Olena/Download
-\end{verbatim}
-\end{center}
+\href{http://www.lrde.epita.fr/Olena/Download}
On this page you will find the latest and past releases.
Currently, we provide only '.tar.gz' and 'tar.bz2' archives.
@@ -521,7 +515,7 @@ We invite you to take a look at the description of the directory structure
(\ref{tuto1dirstruct}.
If you encounter any issues in the installation process or if you have any
question, do not forget to join the mailing lists (\ref{tuto1mailinglists}
-and/or use the other documentations ressources (\ref{tuto1ressources}).
+and/or use the other documentations ressources (\ref{tuto1documentation}).
@@ -666,7 +660,7 @@ List of \hpath{doc}'s subdirectories:
%**************************
-\doxysection{tuto1ressources}{Documentation}
+\doxysection{tuto1documentation}{Documentation}
This tutorial is not the only documentation of Milena. Other documents are available:
@@ -696,7 +690,7 @@ This tutorial is not the only documentation of Milena. Other documents are avail
%**************************
-\doxysection{tuto1ressources}{Community and Support}
+\doxysection{tuto1community}{Community and Support}
Even though Milena is currently developped by the LRDE in EPITA, we are open
for new contributors.
@@ -730,23 +724,27 @@ the mailing-lists (\ref{tuto1mailinglists}).
There are other ways to get to know what is the status of the project.
\begin{itemize}
-\item Olena's trac --- \href{https://trac.lrde.org/olena} --- Here is the
-roadmap, the current open tickets/bugs/improvements which are taken in
-consideration. A source browser is also available.
-
-\item Olena's Buildfarm --- https://buildfarm.lrde.org/buildfarm/oln/ --- The
-official buildfarm. Every night and after each commit, tests are compiled and run.
-The buildfarm can show you whether it is safe to update your svn copy of Milena or not\ldots
-
-\item Test failures --- http://www.lrde.epita.fr/dload/olena/test-failures-daily.html
---- Through this page, you can see exactly which tests do not compile or pass.
-This page is updated every night.
+\item Olena's trac\\
+ \href{https://trac.lrde.org/olena} \\
+ Here is the roadmap, the current open tickets/bugs/improvements which
+ are taken in consideration. A source browser is also available.
+
+\item Olena's Buildfarm \\
+ \href{https://buildfarm.lrde.org/buildfarm/oln/} \\
+ The official buildfarm. Every night and after each commit, tests
+ are compiled and run. The buildfarm can show you whether it is safe
+ to update your svn copy of Milena or not\ldots
+
+\item Test failures
+ \href{http://www.lrde.epita.fr/dload/olena/test-failures-daily.html}
+ Through this page, you can see exactly which tests do not compile or pass.
+ This page is updated every night.
\end{itemize}
%**************************
-\doxysection{tuto1ressources}{A brief history of Milena}
+\doxysection{tuto1briefhistory}{A brief history of Milena}
The Olena project aims at building a scientific computation platform oriented
towards image processing, image recognition, and artificial vision.
@@ -787,7 +785,6 @@ If you want to reach us directly, you can contact one of the following people:
-%\begin{htmlonly}
%====================================
\doxychapter{tuto2}{Installation}
@@ -960,7 +957,7 @@ Text and image outputs will be respectively stored in
-\doxysubsection{tuto2examples}{Tools}
+\doxysubsection{tuto2tools}{Tools}
Few tools are provided with Milena. They can be considered as full program
examples.
@@ -979,7 +976,7 @@ $ make
\end{verbatim}
-\doxysubsection{tuto2examples}{Tests}
+\doxysubsection{tuto2tests}{Tests}
The test suite used for Milena's development is shipped with the library.
@@ -1008,7 +1005,6 @@ In the installed path prefix, Milena's files are located in:
-%\begin{htmlonly}
%====================================
\doxychapter{tuto3}{Getting started with Milena}
diff --git a/milena/headers.mk b/milena/headers.mk
index a74f35f..1a20506 100644
--- a/milena/headers.mk
+++ b/milena/headers.mk
@@ -116,7 +116,6 @@ mln/data/all.hh \
mln/data/paste.hh \
mln/data/fill_with_image.hh \
mln/data/fill_with_image.spe.hh \
-mln/data/swap.hh \
mln/data/fill_with_value.hh \
mln/data/fill_with_value.spe.hh \
mln/data/fill.hh \
@@ -331,6 +330,7 @@ mln/value/all.hh \
mln/value/super_value.hh \
mln/value/builtin/symbolics.hh \
mln/value/builtin/ops.hh \
+mln/value/builtin/carrays.hh \
mln/value/builtin/all.hh \
mln/value/builtin/promotions.hh \
mln/value/builtin/integers.hh \
@@ -373,6 +373,9 @@ mln/value/label_8.hh \
mln/value/essential.hh \
mln/accu/tuple.hh \
mln/accu/min_h.hh \
+mln/accu/site_set/rectangularity.hh \
+mln/accu/site_set/all.hh \
+mln/accu/site_set/essential.hh \
mln/accu/stat/deviation.hh \
mln/accu/max.hh \
mln/accu/lor.hh \
@@ -380,6 +383,7 @@ mln/accu/rank.hh \
mln/accu/transform_stop.hh \
mln/accu/maj_h.hh \
mln/accu/min_max.hh \
+mln/accu/internal/couple.hh \
mln/accu/internal/base.hh \
mln/accu/transform_snake.hh \
mln/accu/rank_high_quant.hh \
@@ -417,6 +421,7 @@ mln/accu/image/all.hh \
mln/accu/image/set_value.hh \
mln/accu/image/take.hh \
mln/accu/image/take_as_init.hh \
+mln/accu/image/essential.hh \
mln/accu/center.hh \
mln/accu/line.hh \
mln/accu/essential.hh \
@@ -479,8 +484,11 @@ mln/trait/promote.hh \
mln/trait/solve_binary.hh \
mln/trait/value_.hh \
mln/trait/all.hh \
+mln/trait/value/internal/all.hh \
+mln/trait/value/internal/comp.hh \
mln/trait/value/all.hh \
mln/trait/value/nature.hh \
+mln/trait/value/comp.hh \
mln/trait/value/quant.hh \
mln/trait/value/kind.hh \
mln/trait/value/print.hh \
@@ -651,7 +659,6 @@ mln/morpho/closing/leveling.hh \
mln/morpho/closing/area_on_vertices.hh \
mln/morpho/closing/area.hh \
mln/morpho/closing/volume.hh \
-mln/morpho/closing/sum.hh \
mln/morpho/closing/height.hh \
mln/morpho/closing/structural.hh \
mln/morpho/closing/essential.hh \
@@ -1021,6 +1028,7 @@ mln/test/predicate.hh \
mln/test/all.hh \
mln/test/positive.hh \
mln/test/essential.hh \
+mln/transform/distance_and_closest_point_geodesic.hh \
mln/transform/distance_geodesic.hh \
mln/transform/internal/all.hh \
mln/transform/internal/closest_point_functor.hh \
@@ -1028,9 +1036,9 @@ mln/transform/internal/distance_functor.hh \
mln/transform/internal/influence_zone_functor.hh \
mln/transform/all.hh \
mln/transform/influence_zone_front.hh \
+mln/transform/distance_and_influence_zone_geodesic.hh \
mln/transform/distance_front.hh \
mln/transform/influence_zone_geodesic.hh \
-mln/transform/closest_point_geodesic.hh \
mln/transform/essential.hh \
mln/arith/includes.hh \
mln/arith/min.spe.hh \
diff --git a/milena/mln/accu/center.hh b/milena/mln/accu/center.hh
index f7caff3..8f793c6 100644
--- a/milena/mln/accu/center.hh
+++ b/milena/mln/accu/center.hh
@@ -84,10 +84,10 @@ namespace mln
struct center : public Meta_Accumulator< center >
{
- template <typename P, typename V>
+ template <typename P>
struct with
{
- typedef accu::center<P, V> ret;
+ typedef accu::center<P> ret;
};
};
@@ -136,6 +136,7 @@ namespace mln
V
center<P,V>::to_result() const
{
+ mln_precondition(is_valid());
return center_ / nsites_;
}
diff --git a/milena/mln/canvas/browsing/depth_first_search.hh b/milena/mln/canvas/browsing/depth_first_search.hh
index a8d840e..179bf1c 100644
--- a/milena/mln/canvas/browsing/depth_first_search.hh
+++ b/milena/mln/canvas/browsing/depth_first_search.hh
@@ -103,26 +103,26 @@ namespace mln
mln_vertex_iter(G) v(g);
for_all(v)
- if (f.to_be_treated(v.id()))
+ if (f.to_be_treated(v.id())) // <--- to_be_treated
{
std::queue<unsigned> queue;
queue.push(v.id());
- f.update_treated(v.id());
+ f.new_component_from_vertex(v.id()); // <--- new_component_from_vertex
while (!queue.empty())
{
util::vertex<G> current_v = g.vertex(queue.front());
+ f.process_vertex(current_v);
queue.pop();
for (unsigned nv = 0; nv < current_v.nmax_nbh_vertices(); ++nv)
- if (f.to_be_queued(current_v.ith_nbh_vertex(nv)))
+ if (f.to_be_queued(current_v.ith_nbh_vertex(nv))) // <--- to_be_queued
{
- f.update_queued(current_v.ith_nbh_vertex(nv));
+ f.added_to_queue(current_v.ith_nbh_vertex(nv)); // <--- added_to_queue
queue.push(current_v.ith_nbh_vertex(nv));
}
}
- f.next();
+ f.next_component(); // <-- next_component
}
-
- f.final();
+ f.final(); // <-- final
trace::exiting("canvas::browsing::depth_first_search");
}
diff --git a/milena/mln/core/concept/function.hh b/milena/mln/core/concept/function.hh
index 2d8baff..ff3015f 100644
--- a/milena/mln/core/concept/function.hh
+++ b/milena/mln/core/concept/function.hh
@@ -44,6 +44,7 @@ namespace mln
template <typename E> struct Function_v2v;
template <typename E> struct Function_v2w2v;
template <typename E> struct Function_v2w_w2v;
+ template <typename E> struct Function_i2b;
template <typename E> struct Function_i2v;
template <typename E> struct Function_p2v;
template <typename E> struct Function_v2b;
@@ -176,6 +177,29 @@ namespace mln
/*-----------------.
+ | Index -> bool. |
+ `-----------------*/
+
+ template <>
+ struct Function_i2b<void> { typedef Function_v2b<void> super; };
+
+ /// Base class for implementation of function-objects from
+ /// index to value.
+ ///
+ /// The parameter \a E is the exact type.
+ ///
+ template <typename E>
+ struct Function_i2b : public Function_v2b<E>
+ {
+ typedef Function_i2b<void> category;
+ typedef bool result;
+ protected:
+ Function_i2b();
+ Function_i2b(const Function_i2b&);
+ };
+
+
+ /*-----------------.
| Index -> Value. |
`-----------------*/
@@ -476,6 +500,20 @@ namespace mln
template <typename E>
inline
+ Function_i2b<E>::Function_i2b()
+ {
+ }
+
+ template <typename E>
+ inline
+ Function_i2b<E>::Function_i2b(const Function_i2b<E>& rhs)
+ : Function_v2b<E>(rhs)
+ {
+ }
+
+
+ template <typename E>
+ inline
Function_i2v<E>::Function_i2v()
{
}
diff --git a/milena/mln/debug/colorize.hh b/milena/mln/debug/colorize.hh
index 15ecb47..4f492bf 100644
--- a/milena/mln/debug/colorize.hh
+++ b/milena/mln/debug/colorize.hh
@@ -117,6 +117,7 @@ namespace mln
int diff_size = f.size() - label_count;
if (diff_size < 0)
{
+ srand(1);
f.resize(label_count);
unsigned i = f.size() + diff_size;
// We want to treat comp 0 differently since it is the background.
diff --git a/milena/mln/fun/i2v/array.hh b/milena/mln/fun/i2v/array.hh
index cd00db5..c140cc3 100644
--- a/milena/mln/fun/i2v/array.hh
+++ b/milena/mln/fun/i2v/array.hh
@@ -43,7 +43,7 @@
# include <mln/core/concept/function.hh>
# include <mln/fun/internal/array_base.hh>
# include <mln/util/array.hh>
-
+# include <mln/metal/equal.hh>
namespace mln
{
@@ -102,16 +102,36 @@ namespace mln
namespace i2v
{
+
+ namespace internal
+ {
+
+ template <typename T, bool B = false >
+ struct array_selector_
+ : public Function_i2v< i2v::array<T> >
+ {
+ };
+
+ template <typename T>
+ struct array_selector_<T,true>
+ : public Function_i2b< i2v::array<T> >
+ {
+ };
+
+ } // end of namespace mln::fun::i2v::internal
+
+
template <typename T>
- class array : public Function_i2v< array<T> >,
- public internal::array_base<T>
+ class array : public internal::array_selector_<T,mlc_equal(T,bool)::value>,
+ public fun::internal::array_base<T>
{
- typedef internal::array_base<T> super_base_;
+ typedef fun::internal::array_base<T> super_base_;
public:
/// Mutable result type. The function results can be modified.
typedef typename super_base_::mutable_result mutable_result;
+ typedef typename fun::internal::array_base<T>::result result;
/// Constructors
/// \{
@@ -175,7 +195,15 @@ namespace mln
{
mlc_converts_to(T,U)::check();
- for (unsigned i = 0; i < from.nelements(); ++i)
+ to.reserve(from.nelements());
+
+ //Special case. Handle background component data.
+ if (from[0].is_valid())
+ to.append(convert::to<U>(from[0]));
+ else
+ to.append(U());
+
+ for (unsigned i = 1; i < from.nelements(); ++i)
to.append(convert::to<U>(from[i]));
}
@@ -194,7 +222,15 @@ namespace mln
{
mlc_converts_to(T,U)::check();
- for (unsigned i = 0; i < from.size(); ++i)
+ to.reserve(from.nelements());
+
+ //Special case. Handle background component data.
+ if (from[0].is_valid())
+ to.append(convert::to<U>(from[0]));
+ else
+ to.append(U());
+
+ for (unsigned i = 1; i < from.size(); ++i)
to.append(convert::to<U>(from[i]));
}
diff --git a/milena/mln/io/pgm/save.hh b/milena/mln/io/pgm/save.hh
index f15c0eb..5e7df76 100644
--- a/milena/mln/io/pgm/save.hh
+++ b/milena/mln/io/pgm/save.hh
@@ -43,8 +43,9 @@
# include <mln/io/pnm/save.hh>
# include <mln/geom/size2d.hh>
-# include <mln/metal/templated_by.hh>
# include <mln/metal/bexpr.hh>
+# include <mln/metal/is_not_a.hh>
+# include <mln/value/concept/vectorial.hh>
namespace mln
@@ -78,11 +79,10 @@ namespace mln
inline
void save(const Image<I>& ima, const std::string& filename)
{
- // FIXME : this is too restrictive. Check if I is compatible with PGM.
- // mln::metal::or_<
- // mln::metal::templated_by<mln_value(I), value::int_u >,
- // mln::metal::templated_by<mln_value(I), value::int_u_sat >
- // >::check();
+ // FIXME: Is it exhaustive?
+ mlc_is_not_a(mln_value(I), value::Vectorial)::check();
+ mlc_converts_to(mln_value(I),unsigned)::check();
+
trace::entering("mln::io::pgm::save");
io::pnm::save(PGM, exact(ima), filename);
trace::exiting("mln::io::pgm::save");
diff --git a/milena/mln/labeling/level.hh b/milena/mln/labeling/level.hh
index 11b3a06..677b027 100644
--- a/milena/mln/labeling/level.hh
+++ b/milena/mln/labeling/level.hh
@@ -111,9 +111,9 @@ namespace mln
bool handles(const P& p) const { return input(p) == val; }
bool equiv(const P& n, const P&) const { return input(n) == val; }
bool labels(const P&) const { return true; }
- void do_no_union(const P& n, const P& p) {}
+ void do_no_union(const P&, const P&) {}
void init_attr(const P&) {}
- void merge_attr(const P& r, const P& p) {}
+ void merge_attr(const P&, const P&) {}
// Fastest implementation
diff --git a/milena/mln/labeling/regional_maxima.hh b/milena/mln/labeling/regional_maxima.hh
index c7c2d53..ae2c8f4 100644
--- a/milena/mln/labeling/regional_maxima.hh
+++ b/milena/mln/labeling/regional_maxima.hh
@@ -95,7 +95,7 @@ namespace mln
// Fastest implementation
void init_() { data::fill(attr, true); }
- bool handles_(unsigned p) const { return true; }
+ bool handles_(unsigned) const { return true; }
bool labels_(unsigned p) const { return attr.element(p); }
bool equiv_(unsigned n, unsigned p) const { return input.element(n) ==
input.element(p); }
diff --git a/milena/mln/labeling/relabel.hh b/milena/mln/labeling/relabel.hh
index 867a0fb..47ca647 100644
--- a/milena/mln/labeling/relabel.hh
+++ b/milena/mln/labeling/relabel.hh
@@ -187,7 +187,7 @@ namespace mln
typedef fun::l2l::relabel<mln_value(I)> fv2v_t;
fv2v_t fv2v = make::relabelfun(fv2b, nlabels, new_nlabels);
- mln_concrete(I) output = labeling::relabel(label, nlabels, new_nlabels, fv2v);
+ mln_concrete(I) output = labeling::relabel(label, new_nlabels, fv2v);
trace::exiting("labeling::relabel");
return output;
diff --git a/milena/mln/make/graph.hh b/milena/mln/make/graph.hh
index c9dddb1..9c0f33e 100644
--- a/milena/mln/make/graph.hh
+++ b/milena/mln/make/graph.hh
@@ -34,6 +34,9 @@
/// Create a graph from an influence zone image.
///
/// \sa transform::influence_zone_geodesic.
+///
+/// \todo Add dispatch for fast images.
+/// \todo Use an adjacency matrix when available in the library.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
@@ -100,6 +103,7 @@ namespace mln
mln::image2d<bool> adj(mln::box2d(nlabels.next(), nlabels.next()));
data::fill(adj, false);
+ extension::adjust_fill(iz, nbh, 0u);
typedef mln_value(I) L;
mln_piter(I) p(iz.domain());
diff --git a/milena/mln/util/array.hh b/milena/mln/util/array.hh
index da7c40c..9e646a5 100644
--- a/milena/mln/util/array.hh
+++ b/milena/mln/util/array.hh
@@ -56,7 +56,6 @@ namespace mln
} // end of namespace mln::util
-
namespace convert
{
@@ -174,8 +173,12 @@ namespace mln
/// Operator<<.
template <typename T>
std::ostream& operator<<(std::ostream& ostr,
- const mln::util::array<T>& a);
+ const array<T>& a);
+ /// Operator==
+ template <typename T>
+ bool operator==(const array<T>& lhs,
+ const array<T>& rhs);
// array_fwd_iter<T>
@@ -272,6 +275,48 @@ namespace mln
} // end of namespace mln::util
+ namespace internal
+ {
+
+ template <typename T, typename E>
+ struct subject_impl<const util::array<T>&, E>
+ {
+ unsigned nelements() const;
+ bool is_empty() const;
+ const T& operator[](unsigned i) const;
+ const std::vector<T>& std_vector() const;
+
+ private:
+ const E& exact_() const;
+ };
+
+
+ template <typename T, typename E>
+ struct subject_impl<util::array<T>&, E>
+ : subject_impl<const util::array<T>&, E>
+ {
+ void reserve(unsigned n);
+ void resize(unsigned n);
+ void resize(unsigned n, const T& value);
+
+ util::array<T>& append(const T& elt);
+
+ template <typename U>
+ util::array<T>& append(const util::array<U>& other);
+
+ T& operator[](unsigned i);
+
+ void clear();
+
+ std::vector<T>& hook_std_vector_();
+
+ private:
+ E& exact_();
+ };
+
+
+ } // end of namespace mln::internal
+
# ifndef MLN_INCLUDE_ONLY
@@ -288,9 +333,18 @@ namespace mln
void
from_to_(const util::array<T1>& from, util::array<T2>& to)
{
- to.resize(from.nelements());
- for (unsigned i = 0; i < from.nelements(); ++i)
- from_to(from[i], to[i]);
+ mlc_converts_to(T1,T2)::check();
+
+ to.reserve(from.nelements());
+
+ //Special case. Handle background component data.
+ if (from[0].is_valid())
+ to.append(convert::to<T2>(from[0]));
+ else
+ to.append(T2());
+
+ for (unsigned i = 1; i < from.nelements(); ++i)
+ to.append(convert::to<T2>(from[i]));
}
} // end of namespace mln::convert::over_load
@@ -628,7 +682,7 @@ namespace mln
template <typename T>
std::ostream& operator<<(std::ostream& ostr,
- const mln::util::array<T>& a)
+ const array<T>& a)
{
ostr << '[';
const unsigned n = a.nelements();
@@ -642,12 +696,141 @@ namespace mln
return ostr;
}
+
+ // Operator <<.
+
+ template <typename T>
+ bool operator==(const array<T>& lhs,
+ const array<T>& rhs)
+ {
+ return lhs.std_vector() == rhs.std_vector();
+ }
+
} // end of namespace mln::util
-# endif // ! MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ template <typename T, typename E>
+ inline
+ void
+ subject_impl<util::array<T>&, E>::reserve(unsigned n)
+ {
+ exact_().get_subject().reserve(n);
+ }
+
+ template <typename T, typename E>
+ inline
+ void
+ subject_impl<util::array<T>&, E>::resize(unsigned n)
+ {
+ exact_().get_subject().resize(n);
+ }
+
+ template <typename T, typename E>
+ inline
+ void
+ subject_impl<util::array<T>&, E>::resize(unsigned n, const T& value)
+ {
+ exact_().get_subject().resize(n, value);
+ }
+
+ template <typename T, typename E>
+ inline
+ util::array<T>&
+ subject_impl<util::array<T>&, E>::append(const T& elt)
+ {
+ return exact_().get_subject().append(elt);
+ }
+
+ template <typename T, typename E>
+ template <typename U>
+ inline
+ util::array<T>&
+ subject_impl<util::array<T>&, E>::append(const util::array<U>& other)
+ {
+ return exact_().get_subject().append(other);
+ }
+
+ template <typename T, typename E>
+ inline
+ T&
+ subject_impl<util::array<T>&, E>::operator[](unsigned i)
+ {
+ return exact_().get_subject()[i];
+ }
+
+ template <typename T, typename E>
+ inline
+ void
+ subject_impl<util::array<T>&, E>::clear()
+ {
+ exact_().get_subject().clear();
+ }
+
+ template <typename T, typename E>
+ inline
+ std::vector<T>&
+ subject_impl<util::array<T>&, E>::hook_std_vector_()
+ {
+ return exact_().get_subject().hook_std_vector_();
+ }
+
+ template <typename T, typename E>
+ inline
+ E&
+ subject_impl<util::array<T>&, E >::exact_()
+ {
+ return internal::force_exact<E>(*this);
+ }
+ template <typename T, typename E>
+ inline
+ unsigned
+ subject_impl<const util::array<T>&, E>::nelements() const
+ {
+ return exact_().get_subject().nelements();
+ }
+
+ template <typename T, typename E>
+ inline
+ bool
+ subject_impl<const util::array<T>&, E>::is_empty() const
+ {
+ return exact_().get_subject().is_empty();
+ }
+
+ template <typename T, typename E>
+ inline
+ const T&
+ subject_impl<const util::array<T>&, E>::operator[](unsigned i) const
+ {
+ return exact_().get_subject()[i];
+ }
+
+ template <typename T, typename E>
+ inline
+ const std::vector<T>&
+ subject_impl<const util::array<T>&, E>::std_vector() const
+ {
+ return exact_().get_subject().std_vector();
+ }
+
+ template <typename T, typename E>
+ inline
+ const E&
+ subject_impl<const util::array<T>&, E >::exact_() const
+ {
+ return internal::force_exact<const E>(*this);
+ }
+
+
+ } // end of namespace mln::internal
+
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
diff --git a/milena/tests/accu/site_set/rectangularity.cc b/milena/tests/accu/site_set/rectangularity.cc
index 22e1e3e..ee6b6d1 100644
--- a/milena/tests/accu/site_set/rectangularity.cc
+++ b/milena/tests/accu/site_set/rectangularity.cc
@@ -29,11 +29,12 @@
///
/// Tests on mln::accu::site_set::rectangularity.
-
+#include <mln/core/image/image2d.hh>
#include <mln/core/alias/point2d.hh>
#include <mln/core/alias/box2d.hh>
#include <mln/accu/site_set/rectangularity.hh>
+#include <mln/set/compute.hh>
int main()
{
@@ -53,8 +54,18 @@ int main()
accu::site_set::rectangularity<point2d> accu;
accu.take(point2d(0,0));
accu.take(point2d(1,1));
- std::cout << accu << std::endl;
mln_assertion(accu.to_result() == 0.5f);
}
+
+ {
+ box2d b(2,2);
+ float r = set::compute(accu::site_set::rectangularity<point2d>(), b);
+ mln_assertion(r == 1.0f);
+ }
+
+ {
+ accu::site_set::rectangularity<point2d> a;
+ accu::site_set::rectangularity<point2d> b = exact(a);
+ }
}
diff --git a/milena/tests/unit_test/unit-tests.mk b/milena/tests/unit_test/unit-tests.mk
index 1449e41..d88724b 100644
--- a/milena/tests/unit_test/unit-tests.mk
+++ b/milena/tests/unit_test/unit-tests.mk
@@ -112,7 +112,6 @@ mln_data_memcpy_ \
mln_data_all \
mln_data_paste \
mln_data_fill_with_image \
-mln_data_swap \
mln_data_fill_with_value \
mln_data_fill \
mln_data_essential \
@@ -326,6 +325,7 @@ mln_value_all \
mln_value_super_value \
mln_value_builtin_symbolics \
mln_value_builtin_ops \
+mln_value_builtin_carrays \
mln_value_builtin_all \
mln_value_builtin_promotions \
mln_value_builtin_integers \
@@ -368,6 +368,9 @@ mln_value_label_8 \
mln_value_essential \
mln_accu_tuple \
mln_accu_min_h \
+mln_accu_site_set_rectangularity \
+mln_accu_site_set_all \
+mln_accu_site_set_essential \
mln_accu_stat_deviation \
mln_accu_max \
mln_accu_lor \
@@ -375,6 +378,7 @@ mln_accu_rank \
mln_accu_transform_stop \
mln_accu_maj_h \
mln_accu_min_max \
+mln_accu_internal_couple \
mln_accu_internal_base \
mln_accu_transform_snake \
mln_accu_rank_high_quant \
@@ -412,6 +416,7 @@ mln_accu_image_all \
mln_accu_image_set_value \
mln_accu_image_take \
mln_accu_image_take_as_init \
+mln_accu_image_essential \
mln_accu_center \
mln_accu_line \
mln_accu_essential \
@@ -472,8 +477,11 @@ mln_trait_promote \
mln_trait_solve_binary \
mln_trait_value_ \
mln_trait_all \
+mln_trait_value_internal_all \
+mln_trait_value_internal_comp \
mln_trait_value_all \
mln_trait_value_nature \
+mln_trait_value_comp \
mln_trait_value_quant \
mln_trait_value_kind \
mln_trait_value_print \
@@ -644,7 +652,6 @@ mln_morpho_closing_leveling \
mln_morpho_closing_area_on_vertices \
mln_morpho_closing_area \
mln_morpho_closing_volume \
-mln_morpho_closing_sum \
mln_morpho_closing_height \
mln_morpho_closing_structural \
mln_morpho_closing_essential \
@@ -995,6 +1002,7 @@ mln_test_predicate \
mln_test_all \
mln_test_positive \
mln_test_essential \
+mln_transform_distance_and_closest_point_geodesic \
mln_transform_distance_geodesic \
mln_transform_internal_all \
mln_transform_internal_closest_point_functor \
@@ -1002,9 +1010,9 @@ mln_transform_internal_distance_functor \
mln_transform_internal_influence_zone_functor \
mln_transform_all \
mln_transform_influence_zone_front \
+mln_transform_distance_and_influence_zone_geodesic \
mln_transform_distance_front \
mln_transform_influence_zone_geodesic \
-mln_transform_closest_point_geodesic \
mln_transform_essential \
mln_arith_includes \
mln_arith_plus \
@@ -1221,7 +1229,6 @@ mln_data_memcpy__SOURCES = mln_data_memcpy_.cc
mln_data_all_SOURCES = mln_data_all.cc
mln_data_paste_SOURCES = mln_data_paste.cc
mln_data_fill_with_image_SOURCES = mln_data_fill_with_image.cc
-mln_data_swap_SOURCES = mln_data_swap.cc
mln_data_fill_with_value_SOURCES = mln_data_fill_with_value.cc
mln_data_fill_SOURCES = mln_data_fill.cc
mln_data_essential_SOURCES = mln_data_essential.cc
@@ -1435,6 +1442,7 @@ mln_value_all_SOURCES = mln_value_all.cc
mln_value_super_value_SOURCES = mln_value_super_value.cc
mln_value_builtin_symbolics_SOURCES = mln_value_builtin_symbolics.cc
mln_value_builtin_ops_SOURCES = mln_value_builtin_ops.cc
+mln_value_builtin_carrays_SOURCES = mln_value_builtin_carrays.cc
mln_value_builtin_all_SOURCES = mln_value_builtin_all.cc
mln_value_builtin_promotions_SOURCES = mln_value_builtin_promotions.cc
mln_value_builtin_integers_SOURCES = mln_value_builtin_integers.cc
@@ -1477,6 +1485,9 @@ mln_value_label_8_SOURCES = mln_value_label_8.cc
mln_value_essential_SOURCES = mln_value_essential.cc
mln_accu_tuple_SOURCES = mln_accu_tuple.cc
mln_accu_min_h_SOURCES = mln_accu_min_h.cc
+mln_accu_site_set_rectangularity_SOURCES = mln_accu_site_set_rectangularity.cc
+mln_accu_site_set_all_SOURCES = mln_accu_site_set_all.cc
+mln_accu_site_set_essential_SOURCES = mln_accu_site_set_essential.cc
mln_accu_stat_deviation_SOURCES = mln_accu_stat_deviation.cc
mln_accu_max_SOURCES = mln_accu_max.cc
mln_accu_lor_SOURCES = mln_accu_lor.cc
@@ -1484,6 +1495,7 @@ mln_accu_rank_SOURCES = mln_accu_rank.cc
mln_accu_transform_stop_SOURCES = mln_accu_transform_stop.cc
mln_accu_maj_h_SOURCES = mln_accu_maj_h.cc
mln_accu_min_max_SOURCES = mln_accu_min_max.cc
+mln_accu_internal_couple_SOURCES = mln_accu_internal_couple.cc
mln_accu_internal_base_SOURCES = mln_accu_internal_base.cc
mln_accu_transform_snake_SOURCES = mln_accu_transform_snake.cc
mln_accu_rank_high_quant_SOURCES = mln_accu_rank_high_quant.cc
@@ -1521,6 +1533,7 @@ mln_accu_image_all_SOURCES = mln_accu_image_all.cc
mln_accu_image_set_value_SOURCES = mln_accu_image_set_value.cc
mln_accu_image_take_SOURCES = mln_accu_image_take.cc
mln_accu_image_take_as_init_SOURCES = mln_accu_image_take_as_init.cc
+mln_accu_image_essential_SOURCES = mln_accu_image_essential.cc
mln_accu_center_SOURCES = mln_accu_center.cc
mln_accu_line_SOURCES = mln_accu_line.cc
mln_accu_essential_SOURCES = mln_accu_essential.cc
@@ -1581,8 +1594,11 @@ mln_trait_promote_SOURCES = mln_trait_promote.cc
mln_trait_solve_binary_SOURCES = mln_trait_solve_binary.cc
mln_trait_value__SOURCES = mln_trait_value_.cc
mln_trait_all_SOURCES = mln_trait_all.cc
+mln_trait_value_internal_all_SOURCES = mln_trait_value_internal_all.cc
+mln_trait_value_internal_comp_SOURCES = mln_trait_value_internal_comp.cc
mln_trait_value_all_SOURCES = mln_trait_value_all.cc
mln_trait_value_nature_SOURCES = mln_trait_value_nature.cc
+mln_trait_value_comp_SOURCES = mln_trait_value_comp.cc
mln_trait_value_quant_SOURCES = mln_trait_value_quant.cc
mln_trait_value_kind_SOURCES = mln_trait_value_kind.cc
mln_trait_value_print_SOURCES = mln_trait_value_print.cc
@@ -1753,7 +1769,6 @@ mln_morpho_closing_leveling_SOURCES = mln_morpho_closing_leveling.cc
mln_morpho_closing_area_on_vertices_SOURCES = mln_morpho_closing_area_on_vertices.cc
mln_morpho_closing_area_SOURCES = mln_morpho_closing_area.cc
mln_morpho_closing_volume_SOURCES = mln_morpho_closing_volume.cc
-mln_morpho_closing_sum_SOURCES = mln_morpho_closing_sum.cc
mln_morpho_closing_height_SOURCES = mln_morpho_closing_height.cc
mln_morpho_closing_structural_SOURCES = mln_morpho_closing_structural.cc
mln_morpho_closing_essential_SOURCES = mln_morpho_closing_essential.cc
@@ -2104,6 +2119,7 @@ mln_test_predicate_SOURCES = mln_test_predicate.cc
mln_test_all_SOURCES = mln_test_all.cc
mln_test_positive_SOURCES = mln_test_positive.cc
mln_test_essential_SOURCES = mln_test_essential.cc
+mln_transform_distance_and_closest_point_geodesic_SOURCES = mln_transform_distance_and_closest_point_geodesic.cc
mln_transform_distance_geodesic_SOURCES = mln_transform_distance_geodesic.cc
mln_transform_internal_all_SOURCES = mln_transform_internal_all.cc
mln_transform_internal_closest_point_functor_SOURCES = mln_transform_internal_closest_point_functor.cc
@@ -2111,9 +2127,9 @@ mln_transform_internal_distance_functor_SOURCES = mln_transform_internal_distanc
mln_transform_internal_influence_zone_functor_SOURCES = mln_transform_internal_influence_zone_functor.cc
mln_transform_all_SOURCES = mln_transform_all.cc
mln_transform_influence_zone_front_SOURCES = mln_transform_influence_zone_front.cc
+mln_transform_distance_and_influence_zone_geodesic_SOURCES = mln_transform_distance_and_influence_zone_geodesic.cc
mln_transform_distance_front_SOURCES = mln_transform_distance_front.cc
mln_transform_influence_zone_geodesic_SOURCES = mln_transform_influence_zone_geodesic.cc
-mln_transform_closest_point_geodesic_SOURCES = mln_transform_closest_point_geodesic.cc
mln_transform_essential_SOURCES = mln_transform_essential.cc
mln_arith_includes_SOURCES = mln_arith_includes.cc
mln_arith_plus_SOURCES = mln_arith_plus.cc
@@ -2137,6 +2153,8 @@ mln_io_cloud_load_SOURCES = mln_io_cloud_load.cc
mln_io_cloud_all_SOURCES = mln_io_cloud_all.cc
mln_io_cloud_save_SOURCES = mln_io_cloud_save.cc
mln_io_all_SOURCES = mln_io_all.cc
+mln_io_magick_load_SOURCES = mln_io_magick_load.cc
+mln_io_magick_all_SOURCES = mln_io_magick_all.cc
mln_io_dump_load_SOURCES = mln_io_dump_load.cc
mln_io_dump_all_SOURCES = mln_io_dump_all.cc
mln_io_dump_save_SOURCES = mln_io_dump_save.cc
--
1.5.6.5
1
0
* mln/convert/from_to.hxx,
* mln/core/concept/site_set.hh: do NOT prefix template parameter names
with '_'. Names prefixed by '_' are reserved!
---
milena/ChangeLog | 8 ++++++++
milena/mln/convert/from_to.hxx | 8 ++++----
milena/mln/core/concept/site_set.hh | 16 ++++++++--------
3 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 1b6f60d..31180d8 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,11 @@
+2009-03-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Fix compilation issues with Cygwin.
+
+ * mln/convert/from_to.hxx,
+ * mln/core/concept/site_set.hh: do NOT prefix template parameter names
+ with '_'. Names prefixed by '_' are reserved!
+
2009-03-24 Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Relax a couple of contraints related to labels and integers.
diff --git a/milena/mln/convert/from_to.hxx b/milena/mln/convert/from_to.hxx
index 6c7bfc7..eb05b13 100644
--- a/milena/mln/convert/from_to.hxx
+++ b/milena/mln/convert/from_to.hxx
@@ -404,14 +404,14 @@ namespace mln
from_to_(const Site_Set<S>& from, Image<I>& to);
// Site_Set -> std::set
- template <typename S, typename P, typename _C>
+ template <typename S, typename P, typename C_>
void
- from_to_(const Site_Set<S>& from, std::set<P,_C>& to);
+ from_to_(const Site_Set<S>& from, std::set<P,C_>& to);
// std::set -> Site_Set
- template <typename P, typename _C, typename S>
+ template <typename P, typename C_, typename S>
void
- from_to_(const std::set<P,_C>& from, Site_Set<S>& to);
+ from_to_(const std::set<P,C_>& from, Site_Set<S>& to);
// histo::array -> image1d
template <typename V, typename T>
diff --git a/milena/mln/core/concept/site_set.hh b/milena/mln/core/concept/site_set.hh
index 863bc3f..844d5aa 100644
--- a/milena/mln/core/concept/site_set.hh
+++ b/milena/mln/core/concept/site_set.hh
@@ -96,13 +96,13 @@ namespace mln
namespace over_load
{
- template <typename S, typename P, typename _C>
+ template <typename S, typename P, typename C_>
void
- from_to_(const Site_Set<S>& from, std::set<P,_C>& to);
+ from_to_(const Site_Set<S>& from, std::set<P,C_>& to);
- template <typename P, typename _C, typename S>
+ template <typename P, typename C_, typename S>
void
- from_to_(const std::set<P,_C>& from, Site_Set<S>& to);
+ from_to_(const std::set<P,C_>& from, Site_Set<S>& to);
} // end of namespace mln::convert::over_load
@@ -138,10 +138,10 @@ namespace mln
namespace over_load
{
- template <typename S, typename P, typename _C>
+ template <typename S, typename P, typename C_>
inline
void
- from_to_(const Site_Set<S>& from_, std::set<P,_C>& to)
+ from_to_(const Site_Set<S>& from_, std::set<P,C_>& to)
{
mlc_converts_to(mln_psite(S), P)::check();
const S& from = exact(from_);
@@ -152,10 +152,10 @@ namespace mln
}
- template <typename P, typename _C, typename S>
+ template <typename P, typename C_, typename S>
inline
void
- from_to_(const std::set<P,_C>& from, Site_Set<S>& to_)
+ from_to_(const std::set<P,C_>& from, Site_Set<S>& to_)
{
mlc_converts_to(P, mln_i_element(S))::check();
S& to = exact(to_);
--
1.5.6.5
1
0
24 Mar '09
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Relax a couple of contraints related to labels and integers.
* mln/debug/colorize.hh: Relax the Symbolic constraint.
That allows for colorizing images containing integers.
* mln/value/int_u.hh (next): New.
That allows for images containing integers to be processed
as labeled images.
debug/colorize.hh | 4 ++--
value/int_u.hh | 15 +++++++++++++--
2 files changed, 15 insertions(+), 4 deletions(-)
Index: mln/debug/colorize.hh
--- mln/debug/colorize.hh (revision 3565)
+++ mln/debug/colorize.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of the Olena Library. This library is free
@@ -109,7 +109,7 @@
mln_precondition(exact(input).is_valid());
// FIXME: check that V is a color type.
// FIXME: we want to be sure that this is a label.
- mlc_is_a(mln_value(L), mln::value::Symbolic)::check();
+ // mlc_is_a(mln_value(L), mln::value::Symbolic)::check();
(void) value;
unsigned label_count = nlabels.next();
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 3565)
+++ mln/value/int_u.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 2009 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
@@ -154,6 +154,9 @@
/// Assignment from an integer.
int_u<n>& operator=(int i);
+
+ /// Give the next value (i.e., i + 1).
+ int_u<n> next() const;
};
@@ -256,6 +259,14 @@
template <unsigned n>
inline
+ int_u<n>
+ int_u<n>::next() const
+ {
+ return this->v_ + 1;
+ }
+
+ template <unsigned n>
+ inline
std::ostream& operator<<(std::ostream& ostr, const int_u<n>& i)
{
// FIXME: This code could be factored for almost every Value<*>...
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-24 Frederic Bour <bour(a)lrde.epita.fr>
Add from_accu functional wrapper.
* fred/mln/fun/from_accu.hh: New.
* fred/mln/fun/math/cos.hh: Support for integer value as argument.
---
from_accu.hh | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
math/cos.hh | 15 +++++++++
2 files changed, 110 insertions(+)
Index: trunk/milena/sandbox/fred/mln/fun/math/cos.hh
===================================================================
--- trunk/milena/sandbox/fred/mln/fun/math/cos.hh (revision 3565)
+++ trunk/milena/sandbox/fred/mln/fun/math/cos.hh (revision 3566)
@@ -30,6 +30,7 @@
# include <mln/fun/unary.hh>
# include <mln/value/builtin/floatings.hh>
+# include <mln/value/builtin/integers.hh>
# include <mln/math/acos.hh>
# include <mln/math/cos.hh>
@@ -67,6 +68,20 @@
}
};
+ template <typename T>
+ struct set_unary_<mln::fun::cos, mln::value::Integer, T>
+ {
+ typedef set_unary_ ret;
+ typedef double result;
+ typedef T argument;
+
+ static result read(const argument& x)
+ {
+ return math::cos((result)x);
+ }
+
+ };
+
}
}
Index: trunk/milena/sandbox/fred/mln/fun/from_accu.hh
===================================================================
--- trunk/milena/sandbox/fred/mln/fun/from_accu.hh (revision 0)
+++ trunk/milena/sandbox/fred/mln/fun/from_accu.hh (revision 3566)
@@ -0,0 +1,95 @@
+// 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 F 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_FROMACCU_HH
+# define MLN_FUN_FROMACCU_HH
+
+# include <mln/fun/unary.hh>
+# include <mln/core/concept/accumulator.hh>
+# include <mln/math/acos.hh>
+# include <mln/math/cos.hh>
+
+namespace mln
+{
+
+ // Cosinus, bijective
+ namespace fun
+ {
+ template <typename A>
+ struct from_accu : unary_param<from_accu<A>, A*>
+ {
+ from_accu() : unary_param<from_accu<A>, A*>() {};
+ from_accu(A* a) : unary_param<from_accu<A>, A*>(a) {};
+ };
+ }
+
+ namespace trait
+ {
+
+ namespace next
+ {
+ template <typename A, typename T>
+ struct set_unary_<mln::fun::from_accu<A>, mln::Object, T>
+ {
+ typedef set_unary_ ret;
+ typedef typename A::result result;
+ typedef typename A::argument argument;
+ typedef A* param;
+
+ set_unary_()
+ {
+ }
+
+ set_unary_(const param& accu)
+ : accu_(accu)
+ {
+ }
+
+ result read(const argument& x) const
+ {
+ mln_precondition(accu_ != 0);
+
+ accu_->take(x);
+ return accu_->to_result ();
+ }
+
+ void init(const param& accu)
+ {
+ accu_ = accu;
+ }
+
+ protected:
+ A* accu_;
+ };
+
+ }
+
+ }
+
+}
+
+#endif /* ! MLN_FUN_MATH_COS_HH */
\ No newline at end of file
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add some executable source.
* theo/icdar: New directory.
* theo/icdar/dibco: New directory.
* theo/icdar/hsc: New directory.
* theo/icdar/hsc/fuzzy.sh: New.
* theo/icdar/hsc/dist.sh: New.
* theo/icdar/hsc/exec: New directory.
* theo/icdar/hsc/exec/iz_lines.cc: New.
* theo/icdar/hsc/exec/relabel_lines.cc: New.
* theo/icdar/hsc/exec/show_lines_pbm.cc: New.
* theo/icdar/hsc/exec/show_lines.cc: New.
* theo/exec/watershed_superpose.cc: New.
* theo/exec/gaussian_directional_2d__float.cc: New.
* theo/exec/distance_thick.cc: New.
* theo/exec/closing_rectangle.cc: Add pbm case.
* theo/exec/opening_rectangle.cc: New.
* theo/exec/closing_isotropic.cc: Add pgm case.
exec/closing_isotropic.cc | 10 +
exec/closing_rectangle.cc | 26 ++
exec/distance_thick.cc | 46 +++++
exec/gaussian_directional_2d__float.cc | 99 +++++++++++
exec/opening_rectangle.cc | 62 ++++++
exec/watershed_superpose.cc | 36 ++++
icdar/hsc/dist.sh | 8
icdar/hsc/exec/iz_lines.cc | 106 +++++++++++
icdar/hsc/exec/relabel_lines.cc | 296 +++++++++++++++++++++++++++++++++
icdar/hsc/exec/show_lines.cc | 53 +++++
icdar/hsc/exec/show_lines_pbm.cc | 44 ++++
icdar/hsc/fuzzy.sh | 18 ++
12 files changed, 801 insertions(+), 3 deletions(-)
Index: theo/icdar/hsc/fuzzy.sh
--- theo/icdar/hsc/fuzzy.sh (revision 0)
+++ theo/icdar/hsc/fuzzy.sh (revision 0)
@@ -0,0 +1,18 @@
+#! /bin/sh
+
+convert -geometry 25% -depth 8 +compress $1 small.pgm
+./+bin/gaussian_directional_2d__float small.pgm 1 1 31 fuz.pgm
+
+./+bin/closing_rectangle fuz.pgm 7 31 tmp.pgm
+./+bin/watershed_flooding tmp.pgm ws_txt.pgm
+
+convert -negate fuz.pgm -depth 8 +compress tmp.pgm
+
+./+bin/closing_rectangle tmp.pgm 7 31 tmp.pgm
+./+bin/watershed_flooding tmp.pgm ws_spc.pgm
+
+./+bin/relabel_lines ws_txt.pgm ws_spc.pgm tmp.ppm
+
+./+bin/show_lines small.pgm tmp.ppm ${1%pbm}ppm
+
+rm fuz.pgm tmp.pgm ws_txt.pgm ws_spc.pgm small.pgm tmp.ppm
Property changes on: theo/icdar/hsc/fuzzy.sh
___________________________________________________________________
Added: svn:executable
+ *
Index: theo/icdar/hsc/exec/iz_lines.cc
--- theo/icdar/hsc/exec/iz_lines.cc (revision 0)
+++ theo/icdar/hsc/exec/iz_lines.cc (revision 0)
@@ -0,0 +1,106 @@
+#include "../exec/filetype.hh"
+
+#include <mln/core/alias/point2d.hh>
+#include <mln/core/alias/dpoint2d.hh>
+
+#include <mln/core/image/image_if.hh>
+
+#include <mln/data/fill.hh>
+#include <mln/data/paste.hh>
+#include <mln/pw/all.hh>
+
+// #include <mln/debug/colorize.hh>
+
+#include <mln/transform/influence_zone_geodesic.hh>
+
+// #include <mln/level/transform.hh>
+// #include <mln/fun/l2l/wrap.hh>
+
+
+using mln::value::int_u8;
+
+
+
+namespace mln
+{
+
+
+ template <typename L>
+ image2d<int_u8>
+ left_iz(const image2d<bool>& in, const image2d<L>& ws_txt)
+ {
+ box2d b = ws_txt.domain();
+
+ image2d<int_u8> ima(b);
+ data::fill(ima, 0);
+
+ unsigned nrows = ima.nrows();
+ int_u8 l = 0;
+ for (unsigned row = 0; row < nrows; ++row)
+ if (ws_txt.at_(row, 0) == 0)
+ ima.at_(row, 0) = ++l;
+
+ io::pgm::save(ima, "tmp_iz_start.pgm");
+
+ data::paste( transform::influence_zone_geodesic(ima | (pw::value(ws_txt) == pw::cst(0)),
+ c8(),
+ mln_max(unsigned)),
+ ima );
+
+ image2d<int_u8> out(in.domain());
+ data::fill(out, false);
+ data::fill((out | pw::value(in)).rw(), 255);
+
+ mln_piter(box2d) p(out.domain());
+ for_all(p)
+// if (in(p) == true)
+ {
+ point2d p_(p.row() / 4, p.col() / 4);
+ if (! ima.has(p_) || ima(p_) == 0)
+ continue;
+ out(p) = ima(p_);
+ }
+
+ return out;
+ }
+
+
+} // ! mln
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.pbm ws_txt.pgm output.ppm" << std::endl
+ << " Label lines." << std::endl
+ << " input is the large binary image;" << std::endl
+ << " ws_txt is a small (25p) watershed image thru text." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+
+ if (argc != 4)
+ usage(argv);
+
+ trace::entering("main");
+
+ image2d<bool> in;
+ io::pbm::load(in, argv[1]);
+
+ image2d<int_u8> ws_txt, out;
+ io::pgm::load(ws_txt, argv[2]);
+
+ out = left_iz(in, ws_txt);
+
+ io::pgm::save(out, argv[3]);
+
+// io::ppm::save(debug::colorize(value::rgb8(), out, 254),
+// argv[3]);
+
+ trace::exiting("main");
+}
Index: theo/icdar/hsc/exec/relabel_lines.cc
--- theo/icdar/hsc/exec/relabel_lines.cc (revision 0)
+++ theo/icdar/hsc/exec/relabel_lines.cc (revision 0)
@@ -0,0 +1,296 @@
+#include "../exec/filetype.hh"
+
+#include <mln/core/alias/point2d.hh>
+#include <mln/core/alias/dpoint2d.hh>
+
+#include <mln/value/label_8.hh>
+#include <mln/core/image/image_if.hh>
+
+#include <mln/data/fill.hh>
+#include <mln/pw/all.hh>
+#include <mln/labeling/blobs.hh>
+// #include <mln/labeling/compute.hh>
+#include <mln/accu/maj_h.hh>
+
+#include <mln/morpho/elementary/dilation.hh>
+#include <mln/debug/colorize.hh>
+
+#include <mln/transform/influence_zone_geodesic.hh>
+#include <mln/level/transform.hh>
+#include <mln/fun/l2l/wrap.hh>
+
+
+namespace mln
+{
+
+ typedef value::int_u8 L;
+
+ enum { max_L = 256 - 1 };
+
+ typedef L par_t[max_L];
+ typedef std::vector<L> labels_t[max_L];
+
+
+ L find_root(par_t& par, L l)
+ {
+ if (par[l] == l)
+ return l;
+ return par[l] = find_root(par, par[l]);
+ }
+
+
+ image2d<L> doit(const image2d<L>& ws_txt,
+ const image2d<L>& ws_spc)
+ {
+ labels_t left_, right_;
+
+// image2d<bool> cross(ws_txt.domain());
+// data::fill(cross, false);
+
+ box2d b = ws_txt.domain();
+ mln_piter_(box2d) p(b);
+ for_all(p)
+ {
+ if (ws_txt(p) != 0 || ws_spc(p) != 0)
+ continue;
+ if (ws_txt(p + left) == 0 && ws_txt(p + right) == 0
+ // text = locally horizontal:
+ // o o o
+ &&
+ ws_spc(p + left) != 0 && ws_spc(p + right) != 0
+ // region frontiere = locally roughly vertical:
+ // x .
+ // o
+ // . x
+ )
+ {
+ L l1 = ws_spc(p + left),
+ l2 = ws_spc(p + right);
+ if (l1 == 0 || l2 == 0)
+ continue;
+ if (l2 == l1)
+ continue;
+ right_[l1].push_back(l2);
+ left_[l2].push_back(l1);
+// cross(p) = true;
+ }
+ }
+
+// io::pbm::save(cross, "tmp_cross.pbm");
+
+
+ // debug code:
+
+// for (L l = 0; l < max_L; ++l)
+// if (right_[l].size())
+// {
+// std::cout << l << " -> ";
+// const std::vector<L>& lab = right_[l];
+// for (L i = 0; i < lab.size(); ++i)
+// {
+// std::cout << lab[i] << ' ';
+// const std::vector<L>& rev_lab = left_[ lab[i] ];
+// if (rev_lab.size())
+// {
+// std::cout << '(';
+// for (L j = 0; j < rev_lab.size(); ++j)
+// std::cout << rev_lab[j] << ',';
+// std::cout << ')';
+// }
+// }
+// std::cout << std::endl;
+// }
+
+
+ par_t par;
+ for (L l = 0; l < max_L; ++l)
+ par[l] = l;
+
+ for (L l = 1; l < max_L; ++l)
+ if (right_[l].size() == 1)
+ {
+ L l2 = right_[l][0];
+ mln_invariant(l2 != 0);
+ if (left_[l2].size() != 0 && left_[l2][0] == l)
+ {
+ mln_invariant(l != 0 && l2 != l);
+ // Union.
+ par[l] = l2; // l --right--> l2
+ }
+ }
+
+ for (L l = 1; l < max_L; ++l)
+ par[l] = find_root(par, l);
+
+// // debug code:
+
+// for (L l = 1; l < max_L; ++l)
+// if (par[l] != l)
+// std::cout << l << " -> " << par[l] << " ";
+// std::cout << std::endl;
+
+
+ image2d<L> out(b);
+ for_all(p)
+ out(p) = par[ ws_spc(p) ];
+
+ return out;
+ }
+
+
+ void left_iz(const image2d<bool>& ws)
+ {
+ using value::int_u8;
+ image2d<int_u8> ima(ws.domain());
+ data::fill(ima, 0);
+ unsigned nrows = ima.nrows();
+ int_u8 l = 0;
+ for (unsigned row = 0; row < nrows; ++row)
+ if (ws.at_(row, 0) == true)
+ ima.at_(row, 0) = ++l;
+ io::pgm::save(ima, "tmp_iz_start.pgm");
+
+ data::paste( transform::influence_zone_geodesic(ima | pw::value(ws),
+ c8(),
+ mln_max(unsigned)),
+ ima );
+
+ io::pgm::save(ima, "tmp_iz.pgm");
+ }
+
+
+
+ image2d<L> doit_cut(const image2d<L>& ws_txt,
+ const image2d<L>& ws_spc)
+ {
+
+ box2d b = ws_txt.domain();
+
+ image2d<bool> lines(b);
+ data::fill(lines, (pw::value(ws_txt) == pw::cst(0)) | b);
+
+ left_iz(lines); // THIS IS A TEST!
+
+
+ //debug:
+ io::pbm::save(lines, "tmp_ws_line.pbm");
+
+ mln_piter_(box2d) p(b);
+ for_all(p)
+ if (ws_txt(p) == 0 &&
+ ws_txt(p + up) == 0 &&
+ ws_txt(p + down) == 0)
+ lines(p) = false;
+
+ //debug:
+ io::pbm::save(lines, "tmp_lines.pbm");
+
+ typedef value::int_u<12> L2;
+ L2 n_lines;
+ image2d<L2> line_lab = labeling::blobs(lines, c8(), n_lines);
+
+ {
+ io::pgm::save(level::transform(line_lab,
+ fun::l2l::wrap<value::int_u8>()),
+ "tmp_lines.pgm");
+ }
+
+ // Cannot be used with int_u* (only with label_*):
+ // util::array<L2> arr = labeling::compute(accu::maj_h<L2>(),
+ // line_lab | (pw::value(line_lab) != pw::cst(0)),
+ // ws_spc,
+ // max_L);
+
+ util::array< accu::maj_h<L2> > arr(max_L + 1); // L -> L2
+ for_all(p)
+ {
+ if (line_lab(p) == 0) // not on a line
+ continue;
+ L l = ws_spc(p); // l = label of a region
+ if (l == 0)
+ continue;
+ arr[l].take(line_lab(p));
+ }
+
+ util::array<L2> arr_(max_L); // L -> L2
+ for (L l = 1; l < max_L; ++l)
+ arr_[l] = arr[l].to_result();
+
+// // debug:
+// for (L l = 1; l < max_L; ++l)
+// std::cout << l << " -> " << arr_[l] << " ";
+// std::cout << std::endl;
+
+ L2 l2_max = 0;
+ for (L l = 1; l < max_L; ++l)
+ if (arr_[l] > l2_max)
+ l2_max = arr_[l];
+
+ for (L l = 1; l < max_L; ++l)
+ if (arr_[l] == 0)
+ arr_[l] = ++l2_max;
+
+// // debug:
+// std::cout << std::endl << std::endl;
+// for (L l = 1; l < max_L; ++l)
+// std::cout << l << " -> " << arr_[l] << " ";
+// std::cout << std::endl;
+
+ util::array<L> newl(l2_max + 1);
+ for (unsigned i = 0; i <= l2_max; ++i)
+ newl[i] = 0;
+
+ L cur = 1;
+ for (L l = 1; l < max_L; ++l)
+ {
+ L2 l2 = arr_[l];
+ if (newl[l2] == 0)
+ newl[l2] = cur++;
+ }
+
+ image2d<L> out(b);
+ for_all(p)
+ if (ws_spc(p) == 0)
+ out(p) = 0;
+ else
+ out(p) = newl[ arr_[ws_spc(p)] ];
+
+ out = morpho::elementary::dilation(out, c4()); // c2_row
+
+ return out;
+ }
+
+
+} // ! mln
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " ws_txt.pgm ws_spc.pgm output.ppm" << std::endl
+ << " Label lines." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 4)
+ usage(argv);
+
+ trace::entering("main");
+
+ image2d<L> ws_txt, ws_spc;
+ io::pgm::load(ws_txt, argv[1]);
+ io::pgm::load(ws_spc, argv[2]);
+
+ image2d<L> out = doit_cut(ws_txt, ws_spc);
+
+ io::ppm::save(debug::colorize(value::rgb8(), out, 254),
+ argv[3]);
+
+ trace::exiting("main");
+}
Index: theo/icdar/hsc/exec/show_lines_pbm.cc
--- theo/icdar/hsc/exec/show_lines_pbm.cc (revision 0)
+++ theo/icdar/hsc/exec/show_lines_pbm.cc (revision 0)
@@ -0,0 +1,44 @@
+#include "../exec/filetype.hh"
+
+#include <mln/core/alias/point2d.hh>
+#include <mln/core/alias/dpoint2d.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.pbm regions.ppm output.ppm" << std::endl
+ << " 'input' is PBM: dark text / light background" << std::endl
+ << " 'regions': one color per region." << std::endl;
+ std::abort();
+}
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::rgb8;
+
+ if (argc != 4)
+ usage(argv);
+
+ trace::entering("main");
+
+ image2d<bool> input;
+ io::pbm::load(input, argv[1]);
+ box2d b = input.domain();
+
+ image2d<rgb8> reg, out(b);
+ io::ppm::load(reg, argv[2]);
+
+ data::fill(out, rgb8(0,0,0));
+
+ mln_piter_(box2d) p(b);
+ for_all(p) if (input(p))
+ out(p) = reg.at_(p.row() / 4, p.col() / 4);
+
+ io::ppm::save(out, argv[3]);
+
+ trace::exiting("main");
+}
Index: theo/icdar/hsc/exec/show_lines.cc
--- theo/icdar/hsc/exec/show_lines.cc (revision 0)
+++ theo/icdar/hsc/exec/show_lines.cc (revision 0)
@@ -0,0 +1,53 @@
+#include "../exec/filetype.hh"
+
+#include <mln/core/alias/point2d.hh>
+#include <mln/core/alias/dpoint2d.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.pgm regions.ppm output.ppm" << std::endl
+ << " 'input': dark text / light background" << std::endl
+ << " 'regions': one color per region." << std::endl;
+ std::abort();
+}
+
+
+const mln::value::int_u8
+foo(const mln::value::int_u8& c,
+ const mln::value::int_u8& g)
+{
+ float ratio = 1.f - float(g) / 256.f;
+ return unsigned(ratio * c);
+}
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::rgb8;
+
+ if (argc != 4)
+ usage(argv);
+
+ trace::entering("main");
+
+ image2d<int_u8> input;
+ io::pgm::load(input, argv[1]);
+ box2d b = input.domain();
+
+ image2d<rgb8> reg, out(b);
+ io::ppm::load(reg, argv[2]);
+
+ mln_piter_(box2d) p(b);
+ for_all(p)
+ out(p) = rgb8( foo(reg(p).red(), input(p)),
+ foo(reg(p).green(), input(p)),
+ foo(reg(p).blue(), input(p)) );
+
+ io::ppm::save(out, argv[3]);
+
+ trace::exiting("main");
+}
Index: theo/icdar/hsc/dist.sh
--- theo/icdar/hsc/dist.sh (revision 0)
+++ theo/icdar/hsc/dist.sh (revision 0)
@@ -0,0 +1,8 @@
+#! /bin/sh
+
+./+bin/distance_thick $1 out.pgm
+convert -depth 8 +compress $1 ${1%pbm}pgm
+./+bin/closing_rectangle out.pgm 11 101 out2.pgm
+./+bin/watershed_flooding out2.pgm out3.pgm
+./+bin/watershed_superpose ${1%pbm}pgm out3.pgm ${1%pbm}ppm
+rm out.pgm out2.pgm out3.pgm
Property changes on: theo/icdar/hsc/dist.sh
___________________________________________________________________
Added: svn:executable
+ *
Index: theo/exec/watershed_superpose.cc
--- theo/exec/watershed_superpose.cc (revision 0)
+++ theo/exec/watershed_superpose.cc (revision 0)
@@ -0,0 +1,36 @@
+#include "filetype.hh"
+
+#include <mln/morpho/watershed/superpose.hh>
+#include <mln/data/fill.hh>
+#include <mln/pw/all.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.pgm watershed.pgm output.ppm" << std::endl
+ << " Superpose the watershed line over the input image." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 4)
+ usage(argv);
+
+ trace::entering("main");
+
+ image2d<int_u8> ima, ws;
+ io::pgm::load(ima, argv[1]);
+ io::pgm::load(ws, argv[2]);
+
+ io::ppm::save(morpho::watershed::superpose(ima, ws),
+ argv[3]);
+
+ trace::exiting("main");
+}
Index: theo/exec/gaussian_directional_2d__float.cc
--- theo/exec/gaussian_directional_2d__float.cc (revision 0)
+++ theo/exec/gaussian_directional_2d__float.cc (revision 0)
@@ -0,0 +1,99 @@
+
+# define MLN_FLOAT float
+
+#include "filetype.hh"
+#include "./gaussian_directional_2d.hh"
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/pw/all.hh>
+
+#include <mln/data/fill.hh>
+#include <mln/level/saturate.hh>
+
+
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.xxx bdr dir sigma output.pgm" << std::endl
+ << " xxx is pbm or pgm" << std::endl
+ << " bdr is the outer border value" << std::endl
+ << " dir = 0 (vertical blur) or 1 (horizontal blur)" << std::endl
+ << " sigma > 0" << std::endl
+ << " Directional gaussian blur." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+
+ using namespace mln;
+ using value::int_u8;
+
+ trace::entering("main");
+
+ if (argc != 6)
+ usage(argv);
+
+
+ int dir = atoi(argv[3]);
+ if (dir != 0 && dir != 1)
+ usage(argv);
+
+ MLN_FLOAT sigma = atof(argv[4]);
+ if (sigma <= 0.f)
+ usage(argv);
+
+
+ switch (get_filetype(argv[1]))
+ {
+ case filetype::pbm:
+ {
+ int bdr = atoi(argv[2]);
+ if (bdr != 0 && bdr != 1)
+ usage(argv);
+
+ image2d<bool> ima;
+ io::pbm::load(ima, argv[1]);
+
+ image2d<MLN_FLOAT> temp(ima.domain()), out;
+ data::fill(temp, ima);
+
+ out = linear::gaussian_directional_2d(temp, dir, sigma, bdr);
+
+ io::pgm::save(level::saturate(int_u8(),
+ (pw::value(out) * pw::cst(255.f)) | out.domain()),
+ argv[5]);
+ }
+ break;
+
+ case filetype::pgm:
+ {
+ int bdr = atoi(argv[2]);
+ if (bdr < 0 || bdr > 255)
+ usage(argv);
+
+ image2d<int_u8> ima;
+ io::pgm::load(ima, argv[1]);
+
+ image2d<MLN_FLOAT> temp(ima.domain()), out;
+ data::fill(temp, ima);
+
+ out = linear::gaussian_directional_2d(temp, dir, sigma, bdr);
+
+ io::pgm::save(level::saturate(int_u8(), out), argv[5]);
+ }
+ break;
+
+ default:
+ std::cerr << "file type not handled!" << std::endl;
+ usage(argv);
+ }
+
+ trace::exiting("main");
+}
Index: theo/exec/distance_thick.cc
--- theo/exec/distance_thick.cc (revision 0)
+++ theo/exec/distance_thick.cc (revision 0)
@@ -0,0 +1,46 @@
+#include "filetype.hh"
+
+#include <mln/transform/distance_front.hh>
+#include <mln/make/w_window2d_int.hh>
+#include <mln/level/stretch.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.pbm dmap.pgm" << std::endl
+ << " Distance is stretch (from int_u12) to int_u8." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ typedef value::int_u<12> int_u12;
+
+ if (argc != 3)
+ usage(argv);
+
+ trace::entering("main");
+
+ image2d<bool> ima;
+ io::pbm::load(ima, argv[1]);
+
+ int ws[] = { 00, 11, 0, 11, 0,
+ 11, 7, 5, 7, 11,
+ 00, 5, 0, 5, 0,
+ 11, 7, 5, 7, 11,
+ 00, 11, 0, 11, 0 };
+
+ image2d<int_u12> dmap = transform::distance_front(ima,
+ c4(), make::w_window2d_int(ws),
+ mln_max(int_u12));
+
+ io::pgm::save(level::stretch(int_u8(), dmap),
+ argv[2]);
+
+ trace::exiting("main");
+}
Index: theo/exec/closing_rectangle.cc
--- theo/exec/closing_rectangle.cc (revision 3564)
+++ theo/exec/closing_rectangle.cc (working copy)
@@ -6,9 +6,10 @@
void usage(char* argv[])
{
- std::cerr << "usage: " << argv[0] << " input.pgm height width output.pgm" << std::endl
+ std::cerr << "usage: " << argv[0] << " input.xxx height width output.xxx" << std::endl
<< " Height and width are odd positive integers." << std::endl
- << " Rectangle closing." << std::endl;
+ << " xxx is pbm or pgm." << std::endl
+ << " Rectangle closing on a 2D image." << std::endl;
std::abort();
}
@@ -32,11 +33,30 @@
if (width < 0 || width % 2 == 0)
usage(argv);
+
+ std::string filename = argv[1];
+
+ switch (get_filetype(argv[1]))
+ {
+ case filetype::pbm:
+ {
+ image2d<bool> ima, clo;
+ io::pbm::load(ima, argv[1]);
+ clo = morpho::closing::structural(ima, win::rectangle2d(height, width));
+ io::pbm::save(clo, argv[4]);
+ }
+ break;
+
+ case filetype::pgm:
+ {
image2d<int_u8> ima, clo;
io::pgm::load(ima, argv[1]);
-
clo = morpho::closing::structural(ima, win::rectangle2d(height, width));
io::pgm::save(clo, argv[4]);
+ }
+ break;
+ };
+
trace::exiting("main");
}
Index: theo/exec/opening_rectangle.cc
--- theo/exec/opening_rectangle.cc (revision 0)
+++ theo/exec/opening_rectangle.cc (revision 0)
@@ -0,0 +1,62 @@
+#include "filetype.hh"
+
+#include <mln/morpho/opening/structural.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.xxx height width output.xxx" << std::endl
+ << " Height and width are odd positive integers." << std::endl
+ << " xxx is pbm or pgm." << std::endl
+ << " Rectangle opening on a 2D image." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ trace::entering("main");
+
+ if (argc != 5)
+ usage(argv);
+
+ int height = atoi(argv[2]);
+ if (height < 0 || height % 2 == 0)
+ usage(argv);
+
+ int width = atoi(argv[3]);
+ if (width < 0 || width % 2 == 0)
+ usage(argv);
+
+
+ std::string filename = argv[1];
+
+ switch (get_filetype(argv[1]))
+ {
+ case filetype::pbm:
+ {
+ image2d<bool> ima, ope;
+ io::pbm::load(ima, argv[1]);
+ ope = morpho::opening::structural(ima, win::rectangle2d(height, width));
+ io::pbm::save(ope, argv[4]);
+ }
+ break;
+
+ case filetype::pgm:
+ {
+ image2d<int_u8> ima, ope;
+ io::pgm::load(ima, argv[1]);
+ ope = morpho::opening::structural(ima, win::rectangle2d(height, width));
+ io::pgm::save(ope, argv[4]);
+ }
+ break;
+ };
+
+
+ trace::exiting("main");
+}
Index: theo/exec/closing_isotropic.cc
--- theo/exec/closing_isotropic.cc (revision 3564)
+++ theo/exec/closing_isotropic.cc (working copy)
@@ -19,6 +19,7 @@
int main(int argc, char* argv[])
{
using namespace mln;
+ using value::int_u8;
if (argc != 4)
usage(argv);
@@ -46,6 +47,15 @@
}
break;
+ case filetype::pgm:
+ {
+ image2d<int_u8> ima, out;
+ io::pgm::load(ima, argv[1]);
+ out = morpho::closing::structural(ima, win::disk2d(2 * r + 1));
+ io::pgm::save(out, argv[3]);
+ }
+ break;
+
case filetype::dump:
{
image3d<bool> ima, out;
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-24 Frederic Bour <bour(a)lrde.epita.fr>
Correct new functions.
* fred/mln/core/image/thru_morpher.hh,
* fred/mln/fun/math/inf.hh,
* fred/mln/fun/math/sup.hh: Correct typo
* fred/mln/fun/spe/unary.hh,
* fred/mln/fun/unary.hh: Add composition with lresult.
* fred/tests/Makefile,
* fred/tests/thru.cc: Removed unnecessary include.
---
mln/core/image/thru_morpher.hh | 1
mln/fun/math/inf.hh | 2
mln/fun/math/sup.hh | 4 -
mln/fun/spe/unary.hh | 93 ++++++++++++++++++++++++++++++++++++++---
mln/fun/unary.hh | 38 +++++++++++++++-
tests/Makefile | 13 ++---
tests/thru.cc | 9 +--
7 files changed, 137 insertions(+), 23 deletions(-)
Index: trunk/milena/sandbox/fred/tests/thru.cc
===================================================================
--- trunk/milena/sandbox/fred/tests/thru.cc (revision 3563)
+++ trunk/milena/sandbox/fred/tests/thru.cc (revision 3564)
@@ -1,5 +1,5 @@
// Meta functions test
-#include <mln/fun/essential.hh>
+#include <mln/fun/v2v/convert.hh>
#include <mln/fun/math/cos.hh>
#include <mln/core/image/thru_morpher.hh>
#include <mln/fun/compose.hh>
@@ -28,10 +28,9 @@
debug::println(ima);
debug::println(thru(cos, ima));
- thru_image<I, fun::cos::with<fun::cos>::ret::result::with<float>::ret > ima2;
- ima2 = thru(cos(cos), ima);
+ mln_VAR(ima2, thru(cos(cos), ima));
- data::fill_with_image(ima2, (pw::value(tmp) - pw::cst(13.0f)) / pw::cst(12.0f) | tmp.domain());
+ data::fill_with_image(ima2, tmp);
- debug::println(ima);
+ debug::println(ima2);
}
\ No newline at end of file
Index: trunk/milena/sandbox/fred/tests/Makefile
===================================================================
--- trunk/milena/sandbox/fred/tests/Makefile (revision 3563)
+++ trunk/milena/sandbox/fred/tests/Makefile (revision 3564)
@@ -1,17 +1,16 @@
-TARGET=fun
-OBJS=$(TARGET).o
+TARGETS=fun.bin thru.bin cos.bin
OLENADIR=../../../..
MILENADIR=$(OLENADIR)/milena
-CXXFLAGS=-I$(MILENADIR) -I../ -DNDEBUG -O1 -ffast-math
+CXXFLAGS=-I$(MILENADIR) -I../ -DNDEBUG -O1
CXX=g++
LD=g++
LDFLAGS=
RM=rm
-$(TARGET): $(OBJS)
- $(LD) $(LDFLAGS) -o $@ $(OBJS)
+%.bin: %.o
+ $(LD) $(LDFLAGS) -o $@ $<
%.o: %.cc
$(CXX) $(CXXFLAGS) -c $<
@@ -19,7 +18,7 @@
%.o: %.hh
$(CXX) $(CXXFLAGS) -c $<
-all: $(TARGET)
+all: $(TARGETS)
clean:
- $(RM) -f $(TARGET) *.o *~
+ $(RM) -f $(TARGETS) *.o *~
Index: trunk/milena/sandbox/fred/mln/core/image/thru_morpher.hh
===================================================================
--- trunk/milena/sandbox/fred/mln/core/image/thru_morpher.hh (revision 3563)
+++ trunk/milena/sandbox/fred/mln/core/image/thru_morpher.hh (revision 3564)
@@ -72,7 +72,6 @@
data(I& ima, const F& f);
I ima_;
- // FIXME: value or pointer or whatever ?
F f_;
};
Index: trunk/milena/sandbox/fred/mln/fun/spe/unary.hh
===================================================================
--- trunk/milena/sandbox/fred/mln/fun/spe/unary.hh (revision 3563)
+++ trunk/milena/sandbox/fred/mln/fun/spe/unary.hh (revision 3564)
@@ -44,7 +44,8 @@
namespace internal
{
- template <typename Impl>
+ // Wrapper for bijective functions
+ template <typename Impl, typename T>
struct unary_modifier
{
typedef typename Impl::result result;
@@ -52,7 +53,43 @@
typedef typename Impl::lvalue lvalue;
typedef unary_modifier lresult;
- // FIXME: "argument& x" or "lvalue x" directly? ~~~
+ unary_modifier(const Impl& impl, T& x)
+ : x_(&x), impl_(&impl)
+ {
+ }
+
+ result to_result() const
+ {
+ return impl_->read(*x_);
+ };
+
+ operator result() const
+ {
+ return to_result();
+ };
+
+ const result& operator = (const result& r) const
+ {
+ argument x(*x_);
+ impl_->write(x, r);
+ *x_ = x;
+
+ return r;
+ }
+
+ private:
+ T *x_;
+ const Impl *impl_;
+ };
+
+ template <typename Impl>
+ struct unary_modifier<Impl, typename Impl::argument>
+ {
+ typedef typename Impl::result result;
+ typedef typename Impl::argument argument;
+ typedef typename Impl::lvalue lvalue;
+ typedef unary_modifier lresult;
+
unary_modifier(const Impl& impl, argument& x)
: x_(&x), impl_(&impl)
{
@@ -71,6 +108,7 @@
const result& operator = (const result& r) const
{
impl_->write(*x_, r);
+
return r;
}
@@ -79,6 +117,44 @@
const Impl *impl_;
};
+ template <typename Impl, typename Impl2, typename T>
+ struct unary_modifier<Impl, unary_modifier<Impl2, T> >
+ {
+ typedef typename Impl::result result;
+ typedef typename Impl::argument argument;
+ typedef typename Impl::lvalue lvalue;
+ typedef unary_modifier lresult;
+
+ // FIXME: "argument& x" or "lvalue x" directly? ~~~
+ unary_modifier(const Impl& impl, const unary_modifier<Impl2, T>& m)
+ : m_(m), impl_(&impl)
+ {
+ }
+
+ result to_result() const
+ {
+ return impl_->read(m_.to_result());
+ };
+
+ operator result() const
+ {
+ return to_result();
+ };
+
+ const result& operator = (const result& r) const
+ {
+ argument m(m_);
+ impl_->write(m, r);
+ m_ = m;
+
+ return r;
+ }
+
+ private:
+ const unary_modifier<Impl2, T> m_;
+ const Impl *impl_;
+ };
+
} // end of namespace mln::fun::internal
// Forward declaration (defined in mln/fun/unary.hh)
@@ -123,7 +199,14 @@
typedef typename impl::argument argument;
typedef typename impl::result result;
typedef typename impl::lvalue lvalue;
- typedef mln::fun::spe::internal::unary_modifier<impl> lresult;
+
+ template <typename U>
+ struct lresult_with
+ {
+ typedef mln::fun::spe::internal::unary_modifier<impl, U> ret;
+ };
+
+ typedef typename lresult_with<argument>::ret lresult;
unary_impl_set() {}
unary_impl_set(const typename super::init_param& p) : super(p) {}
@@ -190,8 +273,8 @@
} // end of namespace mln::fun
- template <typename Impl>
- std::ostream& operator << (std::ostream& o, const mln::fun::spe::internal::unary_modifier<Impl>& m)
+ template <typename Impl, typename T>
+ std::ostream& operator << (std::ostream& o, const mln::fun::spe::internal::unary_modifier<Impl, T>& m)
{
return o << m.to_result();
}
Index: trunk/milena/sandbox/fred/mln/fun/math/sup.hh
===================================================================
--- trunk/milena/sandbox/fred/mln/fun/math/sup.hh (revision 3563)
+++ trunk/milena/sandbox/fred/mln/fun/math/sup.hh (revision 3564)
@@ -46,8 +46,8 @@
namespace next
{
- template <typename T, typename T>
- struct set_binary_<mln::fun::inf, mln::Object, T, mln::Object, T>
+ template <typename T>
+ struct set_binary_<mln::fun::sup, mln::Object, T, mln::Object, T>
{
typedef set_binary_ ret;
typedef T result;
Index: trunk/milena/sandbox/fred/mln/fun/math/inf.hh
===================================================================
--- trunk/milena/sandbox/fred/mln/fun/math/inf.hh (revision 3563)
+++ trunk/milena/sandbox/fred/mln/fun/math/inf.hh (revision 3564)
@@ -46,7 +46,7 @@
namespace next
{
- template <typename T, typename T>
+ template <typename T>
struct set_binary_<mln::fun::inf, mln::Object, T, mln::Object, T>
{
typedef set_binary_ ret;
Index: trunk/milena/sandbox/fred/mln/fun/unary.hh
===================================================================
--- trunk/milena/sandbox/fred/mln/fun/unary.hh (revision 3563)
+++ trunk/milena/sandbox/fred/mln/fun/unary.hh (revision 3564)
@@ -101,7 +101,7 @@
typedef unary_with_lvalue_helper<false, M, T> super;
typedef typename super::function function;
- static typename function::lresult lcall(const M& m, T& x)
+ static typename function::template lresult_with<T>::ret lcall(const M& m, T& x)
{
function f(super::inst(m));
return f(x);
@@ -114,6 +114,33 @@
}
};
+ template <typename MF, typename MG, typename T>
+ struct unary_with_lvalue_helper<true, MF, mln::fun::spe::internal::unary_modifier<MG, T> >
+ : unary_with_lvalue_helper<false, MF, mln::fun::spe::internal::unary_modifier<MG, T> >
+ {
+ typedef unary_with_lvalue_helper<false, MF, typename MG::result > super;
+ typedef typename super::function function;
+
+ static typename function::template lresult_with<typename MG::result>::ret lcall(const MF& m, T& x)
+ {
+ function f(super::inst(m));
+ return f(x);
+ }
+
+ static typename function::template lresult_with< mln::fun::spe::internal::unary_modifier<MG, T> >::ret
+ lcall(const MF& m, const mln::fun::spe::internal::unary_modifier<MG, T>& x)
+ {
+ function f(super::inst(m));
+ return f(x);
+ }
+
+ static void set(const MF& m, typename function::lvalue v, const T& x)
+ {
+ function f(super::inst(m));
+ f.set(v, x);
+ }
+ };
+
template <typename M, typename T>
struct unary_with_helper
: unary_with_lvalue_helper<mln_trait_fun_is_assignable__1comma_(mln::fun::spe::unary<M, T>)::value, M, T>
@@ -139,11 +166,18 @@
}
template <typename T>
- typename with<T>::ret::lresult operator()(T& v) const
+ typename with<T>::ret::template lresult_with<T>::ret operator()(T& v) const
{
return with<T>::impl::lcall(exact(*this), v);
}
+ template <typename G, typename U>
+ typename with< mln::fun::spe::internal::unary_modifier<G, U> >::ret::lresult
+ operator()(const mln::fun::spe::internal::unary_modifier<G, U>& v) const
+ {
+ return with< mln::fun::spe::internal::unary_modifier<G, U> >::impl::lcall(exact(*this), v);
+ }
+
template <typename T, typename R>
void set(T& v, const R& r) const
{
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-03-24 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Conversion from util::array to image1d.
* mln/convert/from_to.hxx: Update from_to for image1d.
* mln/core/image/image1d.hh: Update from_to.
* mln/world/binary_2d/projected_histo.hh: Update.
---
convert/from_to.hxx | 5 +++++
core/image/image1d.hh | 15 +++++++++++++++
world/binary_2d/projected_histo.hh | 17 ++++++++++-------
3 files changed, 30 insertions(+), 7 deletions(-)
Index: trunk/milena/mln/world/binary_2d/projected_histo.hh
===================================================================
--- trunk/milena/mln/world/binary_2d/projected_histo.hh (revision 3562)
+++ trunk/milena/mln/world/binary_2d/projected_histo.hh (revision 3563)
@@ -32,9 +32,12 @@
///
/// FIXME: insert comment.
+# include <mln/core/concept/image.hh>
# include <mln/core/image/image1d.hh>
# include <mln/core/image/image2d.hh>
# include <mln/core/alias/dpoint2d.hh>
+# include <mln/geom/all.hh>
+# include <mln/opt/at.hh>
# include <mln/value/int_u12.hh>
# include <mln/util/couple.hh>
@@ -47,25 +50,25 @@
namespace binary_2d
{
+ template <typename I>
util::couple<image1d<float>, image1d<float> >
- projected_histo(const image2d<bool>& input, bool value = true)
+ projected_histo(const Image<I>& input_, bool value = true)
{
- const unsigned nrows = input.nrows();
+ mln_ch_value(I, bool) input = exact(input_);
+
+ const unsigned nrows = geom::nrows(input);
image1d<float> row_histo(nrows);
data::fill(row_histo, 0);
- const unsigned ncols = input.ncols();
+ const unsigned ncols = geom::ncols(input);
image1d<float> col_histo(ncols);
data::fill(col_histo, 0);
- mln_precondition(row_histo.nelements() == nrows);
- mln_precondition(col_histo.nelements() == ncols);
-
for (unsigned row = 0; row < nrows; ++row)
{
for (unsigned col = 0; col < ncols; ++col)
{
- if (input.at_(row, col) == value)
+ if (opt::at(input, geom::bbox(input).min_row() + row, geom::bbox(input).min_col() + col) == value)
{
++row_histo.at_(row);
++col_histo.at_(col);
Index: trunk/milena/mln/core/image/image1d.hh
===================================================================
--- trunk/milena/mln/core/image/image1d.hh (revision 3562)
+++ trunk/milena/mln/core/image/image1d.hh (revision 3563)
@@ -133,6 +133,10 @@
template <typename V, typename T>
void from_to_(const histo::array<V>& from, image1d<T>& to);
+ // util::array -> image1d.
+ template <typename V, typename T>
+ void from_to_(const util::array<V>& from, image1d<T>& to);
+
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
@@ -577,6 +581,17 @@
from_to(from[i], to(point1d(i)));
}
+ // util::array -> image1d.
+ template <typename V, typename T>
+ inline
+ void
+ from_to_(const util::array<V>& from, image1d<T>& to)
+ {
+ to.init_(make::box1d(from.nelements()), 0);
+ for (unsigned i = 0; i < from.nelements(); ++i)
+ from_to(from[i], to(point1d(i)));
+ }
+
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
Index: trunk/milena/mln/convert/from_to.hxx
===================================================================
--- trunk/milena/mln/convert/from_to.hxx (revision 3562)
+++ trunk/milena/mln/convert/from_to.hxx (revision 3563)
@@ -418,6 +418,11 @@
void
from_to_(const histo::array<V>& from, image1d<T>& to);
+ // util::array -> image1d
+ template <typename V, typename T>
+ void
+ from_to_(const util::array<V>& from, image1d<T>& to);
+
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
1
0