* binarization/sauvola.hh: New routine.
* src/binarization/Makefile.am,
* src/binarization/sauvola.cc,
* src/binarization/sauvola_pgm.cc: New examples.
---
scribo/ChangeLog | 10 +
scribo/binarization/sauvola.hh | 330 ++++++++++++++++++++++++++++++++
scribo/src/binarization/Makefile.am | 4 +
scribo/src/binarization/sauvola.cc | 61 ++++++
scribo/src/binarization/sauvola_pgm.cc | 61 ++++++
5 files changed, 466 insertions(+), 0 deletions(-)
create mode 100644 scribo/binarization/sauvola.hh
create mode 100644 scribo/src/binarization/sauvola.cc
create mode 100644 scribo/src/binarization/sauvola_pgm.cc
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 296bbd2..5dc8c5e 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,13 @@
+2009-08-28 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Add Sauvola's binarization.
+
+ * binarization/sauvola.hh: New routine.
+
+ * src/binarization/Makefile.am,
+ * src/binarization/sauvola.cc,
+ * src/binarization/sauvola_pgm.cc: New examples.
+
2009-08-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
* src/text_in_photo_invert.cc: New example.
diff --git a/scribo/binarization/sauvola.hh b/scribo/binarization/sauvola.hh
new file mode 100644
index 0000000..a726665
--- /dev/null
+++ b/scribo/binarization/sauvola.hh
@@ -0,0 +1,330 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 SCRIBO_BINARIZATION_SAUVOLA_HH
+# define SCRIBO_BINARIZATION_SAUVOLA_HH
+
+/// \file
+///
+/// Convert an image into a binary image.
+
+# include <algorithm>
+# include <cmath>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/value/int_u.hh>
+
+# include <mln/data/transform.hh>
+# include <mln/pw/all.hh>
+# include <mln/core/routine/duplicate.hh>
+
+
+
+
+namespace scribo
+{
+
+ namespace binarization
+ {
+
+ using namespace mln;
+
+ /*! \brief Convert an image into a binary image.
+
+ \input[in] An image.
+
+ \return A binary image.
+
+ */
+ template <typename I>
+ mln_ch_value(I,bool)
+ sauvola(const Image<I>& input);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ template <typename T>
+ class integral_image
+ {
+ public:
+
+ template<class F>
+ integral_image(const image2d<T>& i, F func)
+ : img_(0),
+ nrows_(i.nrows()),
+ ncols_(i.ncols())
+ {
+ img_ = (unsigned long long**)malloc(sizeof(unsigned long long*) * nrows_);
+ for (int n = 0; n < nrows_; ++n)
+ img_[n] = (unsigned long long*)malloc(sizeof(unsigned long long) * ncols_);
+
+ img_[0][0] = func(i.at_(0, 0));
+
+ for (int row = 1; row < nrows_; ++row)
+ img_[row][0] = (*this)(row - 1, 0) + func(i.at_(row, 0));
+
+ for (int col = 1; col < ncols_; ++col)
+ img_[0][col] = (*this)(0, col - 1)
+ + func(i.at_(0, col));
+
+ for (int row = 1; row < nrows_; ++row)
+ for (int col = 1; col < ncols_; ++col)
+ img_[row][col] = (*this)(row - 1, col)
+ + (*this)(row, col - 1)
+ - (*this)(row - 1, col - 1)
+ + func(i.at_(row, col));
+ }
+
+ ~integral_image()
+ {
+ for (int n = 0; n < nrows_; ++n)
+ free(img_[n]);
+ free(img_);
+ }
+
+ unsigned long long operator()(int row, int col) const
+ {
+ return img_[row][col];
+ }
+
+ private:
+ unsigned long long** img_;
+ int nrows_;
+ int ncols_;
+ };
+
+
+ struct rgb8_to_int_u8 : Function_v2v< rgb8_to_int_u8 >
+ {
+ typedef value::int_u8 result;
+ result operator()(const value::rgb8& c) const
+ {
+ return (c.red() + c.green() + c.blue()) / 3;
+ }
+ };
+
+
+ unsigned long long square_(const value::int_u8& val)
+ {
+ unsigned long long v = static_cast<unsigned long long>(val);
+ return v * v;
+ }
+
+ unsigned long long identity_(const value::int_u8& val)
+ {
+ return static_cast<unsigned long long>(val);
+ }
+
+ } // end of namespace scribo::binarization::internal
+
+
+
+
+ // Implementation
+
+
+ namespace impl
+ {
+
+ namespace generic
+ {
+
+ template <typename I>
+ inline
+ mln_ch_value(I, bool)
+ sauvola(const I& input)
+ {
+ trace::entering("scribo::binarization::impl::generic::sauvola");
+
+ typedef mln_value(I) V;
+
+ // Value of the window size
+ const unsigned int w = 11;
+
+ // Control the threshold value in the local window
+ // The higher, the lower the threshold form the local
+ // mean m(x, y). Badekas et al. said 0.34 was best.
+ const double k = 0.34;
+
+ // Maximum value of the standard deviation (128 for
+ // grayscale documents).
+ const double R = 128;
+
+ // Compute the sum of all intensities of input
+ internal::integral_image<V> simple(input, internal::identity_);
+
+ // Compute the sum of all squared intensities of input
+ internal::integral_image<V> squared(input, internal::square_);
+
+ int w_2 = w >> 1;
+
+ // Savaula Algorithm with I.I.
+
+ image2d<bool> output;
+ initialize(output, input);
+
+ const def::coord nrows = static_cast<def::coord>(input.nrows());
+ const def::coord ncols = static_cast<def::coord>(input.ncols());
+
+ for(def::coord row = 0; row < nrows; ++row)
+ for(def::coord col = 0; col < ncols; ++col)
+ {
+ int row_min = std::max(0, row - w_2);
+ int col_min = std::max(0, col - w_2);
+ int row_max = std::min(nrows - 1, row + w_2);
+ int col_max = std::min(ncols - 1, col + w_2);
+
+ double wh = (row_max - row_min + 1) * (col_max - col_min + 1);
+
+ // Mean.
+ double m_x_y_tmp = (simple(row_max, col_max)
+ + simple(row_min, col_min)
+ - simple(row_max, col_min)
+ - simple(row_min, col_max));
+
+ double m_x_y = m_x_y_tmp / wh;
+
+ // Standard deviation.
+ double s_x_y_tmp = (squared(row_max, col_max)
+ + squared(row_min, col_min)
+ - squared(row_max, col_min)
+ - squared(row_min, col_max));
+
+ double s_x_y = std::sqrt((s_x_y_tmp - (m_x_y_tmp * m_x_y_tmp) / wh) / (wh - 1.f));
+
+ // Thresholding.
+ double t_x_y = m_x_y * (1.0 + k * ((s_x_y / R) - 1.0));
+
+ output.at_(row, col) = (input.at_(row, col) < t_x_y);
+ }
+
+ trace::exiting("scribo::binarization::impl::generic::sauvola");
+ return output;
+ }
+
+ } // end of namespace scribo::binarization::impl::generic
+
+
+ template <typename I>
+ inline
+ mln_ch_value(I, bool)
+ sauvola_gl(const I& input)
+ {
+ return impl::generic::sauvola(input);
+ }
+
+
+ template <typename I>
+ inline
+ mln_ch_value(I, bool)
+ sauvola_rgb8(const I& input)
+ {
+ trace::entering("scribo::binarization::impl::sauvola_rgb8");
+
+ mln_ch_value(I, value::int_u8) gima;
+ gima = data::transform(input,
+ internal::rgb8_to_int_u8());
+
+ mln_ch_value(I, bool) output = impl::generic::sauvola(gima);
+
+ trace::exiting("scribo::binarization::impl::sauvola_rgb8");
+ return output;
+ }
+
+
+ } // end of namespace scribo::binarization::impl
+
+
+
+
+ // Dispatch
+
+ namespace internal
+ {
+
+ template <typename I, unsigned n>
+ inline
+ mln_ch_value(I, bool)
+ sauvola_dispatch(const value::int_u<n>&, const I& input)
+ {
+ return impl::sauvola_gl(input);
+ }
+
+ template <typename I>
+ inline
+ mln_ch_value(I, bool)
+ sauvola_dispatch(const value::rgb8&, const I& input)
+ {
+ return impl::sauvola_rgb8(input);
+ }
+
+ template <typename I>
+ inline
+ mln_ch_value(I, bool)
+ sauvola_dispatch(const mln_value(I)&, const I& input)
+ {
+ // No dispatch for this kind of value type.
+ mlc_abort(I)::check();
+
+ typedef mln_ch_value(I,bool) output_t;
+ return output_t();
+ }
+
+
+ } // end of namespace scribo::binarization::internal
+
+
+ template <typename I>
+ inline
+ mln_ch_value(I, bool)
+ sauvola(const Image<I>& input)
+ {
+ trace::entering("scribo::binarization::sauvola");
+
+ mln_precondition(I::dim == 2);
+ mln_precondition(exact(input).is_valid());
+
+ typedef mln_value(I) value_t;
+ mln_ch_value(I, bool)
+ output = internal::sauvola_dispatch(value_t(), exact(input));
+
+ trace::exiting("scribo::text::ppm2pbm");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::binarization
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_TEXT_PPM2PBM_HH
diff --git a/scribo/src/binarization/Makefile.am b/scribo/src/binarization/Makefile.am
index 5ba07fc..ab982dc 100644
--- a/scribo/src/binarization/Makefile.am
+++ b/scribo/src/binarization/Makefile.am
@@ -20,7 +20,11 @@
include $(top_srcdir)/scribo/scribo.mk
bin_PROGRAMS = \
+ sauvola \
+ sauvola_pgm \
simple
+sauvola_SOURCES = sauvola.cc
+sauvola_pgm_SOURCES = sauvola_pgm.cc
simple_SOURCES = simple.cc
diff --git a/scribo/src/binarization/sauvola.cc b/scribo/src/binarization/sauvola.cc
new file mode 100644
index 0000000..9b34597
--- /dev/null
+++ b/scribo/src/binarization/sauvola.cc
@@ -0,0 +1,61 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#include <mln/io/ppm/load.hh>
+#include <mln/io/pbm/save.hh>
+
+#include <scribo/binarization/sauvola.hh>
+#include <scribo/debug/usage.hh>
+
+const char *args_desc[][2] =
+{
+ { "input.ppm", "A color image." },
+ {0, 0}
+};
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+ using value::rgb8;
+
+ if (argc != 3)
+ return scribo::debug::usage(argv,
+ "Binarization of a color image based on Sauvola's algorithm.",
+ "input.ppm output.pbm",
+ args_desc, "A binary image.");
+
+ trace::entering("main");
+
+ image2d<rgb8> input;
+ io::ppm::load(input, argv[1]);
+
+
+ io::pbm::save(scribo::binarization::sauvola(input),
+ argv[2]);
+
+
+ trace::exiting("main");
+}
diff --git a/scribo/src/binarization/sauvola_pgm.cc b/scribo/src/binarization/sauvola_pgm.cc
new file mode 100644
index 0000000..cac71e1
--- /dev/null
+++ b/scribo/src/binarization/sauvola_pgm.cc
@@ -0,0 +1,61 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pbm/save.hh>
+
+#include <scribo/binarization/sauvola.hh>
+#include <scribo/debug/usage.hh>
+
+const char *args_desc[][2] =
+{
+ { "input.pgm", "A gray level image." },
+ {0, 0}
+};
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 3)
+ return scribo::debug::usage(argv,
+ "Binarization of a gray level image based on Sauvola's algorithm.",
+ "input.pgm output.pbm",
+ args_desc, "A binary image.");
+
+ trace::entering("main");
+
+ image2d<int_u8> input;
+ io::pgm::load(input, argv[1]);
+
+
+ io::pbm::save(scribo::binarization::sauvola(input),
+ argv[2]);
+
+
+ trace::exiting("main");
+}
--
1.5.6.5
---
scribo/ChangeLog | 4 +
scribo/src/text_in_photo_invert.cc | 249 ++++++++++++++++++++++++++++++++++++
2 files changed, 253 insertions(+), 0 deletions(-)
create mode 100644 scribo/src/text_in_photo_invert.cc
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 69af059..296bbd2 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,9 @@
2009-08-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ * src/text_in_photo_invert.cc: New example.
+
+2009-08-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add new filters.
* filter/all.hh: Add new includes.
diff --git a/scribo/src/text_in_photo_invert.cc b/scribo/src/text_in_photo_invert.cc
new file mode 100644
index 0000000..81a0e91
--- /dev/null
+++ b/scribo/src/text_in_photo_invert.cc
@@ -0,0 +1,249 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#include <libgen.h>
+#include <iostream>
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/labeling/colorize.hh>
+
+#include <mln/io/pbm/all.hh>
+#include <mln/io/pgm/all.hh>
+#include <mln/io/ppm/all.hh>
+
+#include <mln/math/min.hh>
+
+#include <mln/literal/colors.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/value/label_16.hh>
+
+#include <mln/draw/box.hh>
+
+#include <mln/logical/not.hh>
+
+#include <mln/labeling/superpose.hh>
+
+#include <scribo/primitive/extract/objects.hh>
+#include <scribo/primitive/group/apply.hh>
+#include <scribo/primitive/link/with_single_left_link.hh>
+#include <scribo/primitive/link/with_single_right_link.hh>
+#include <scribo/primitive/group/from_double_link.hh>
+#include <scribo/primitive/group/from_single_link.hh>
+#include <scribo/filter/objects_small.hh>
+#include <scribo/filter/objects_thin.hh>
+#include <scribo/filter/objects_thick.hh>
+#include <scribo/filter/object_groups_small.hh>
+
+#include <scribo/make/debug_filename.hh>
+#include <scribo/debug/save_bboxes_image.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
+
+#include <scribo/debug/usage.hh>
+
+const char *args_desc[][2] =
+{
+ { "input.pbm", "A binary image. 'True' for objects, 'False'\
+for the background." },
+ { "input_i.pbm", "A binary image. 'True' for objects, 'False'\
+for the background." },
+ {0, 0}
+};
+
+
+
+namespace mln
+{
+
+ template <typename V>
+ object_image(image2d<value::label_16>)
+ run(const image2d<V>& input)
+ {
+ using namespace scribo;
+
+ typedef image2d<value::label_16> L;
+
+ /// Finding objects.
+ value::label_16 nobjects;
+ object_image(L)
+ objects = scribo::primitive::extract::objects(input, c8(), nobjects);
+
+
+ /// First filtering.
+ object_image(L) filtered_objects
+ = scribo::filter::objects_small(objects, 6);
+
+ filtered_objects
+ = scribo::filter::objects_thin(filtered_objects, 1);
+
+ filtered_objects
+ = scribo::filter::objects_thick(filtered_objects,
+ math::min(input.ncols(), input.nrows()) / 6);
+
+
+ /// Finding links between potential objects
+ object_links<L> left_link
+ = primitive::link::with_single_left_link(filtered_objects, 30);
+ object_links<L> right_link
+ = primitive::link::with_single_right_link(filtered_objects, 30);
+
+
+
+ std::cout << "BEFORE - nobjects = " << nobjects << std::endl;
+ scribo::debug::save_linked_bboxes_image(input,
+ filtered_objects,
+ left_link, right_link,
+ literal::red, literal::cyan,
+ literal::yellow,
+ literal::green,
+ scribo::make::debug_filename("links.ppm"));
+
+
+
+
+ // Trying to group objects
+ object_groups<L>
+ groups = primitive::group::from_double_link(filtered_objects,
+ left_link, right_link);
+
+ // Remove objects part of groups with less than 3 objects.
+ util::array<bool>
+ to_be_kept = filter::object_groups_small(groups, 3);
+
+
+
+ // FOR DEBUGGING PURPOSE.
+#ifndef NOUT
+ image2d<value::rgb8> decision_image = data::convert(value::rgb8(), input);
+
+
+ for (unsigned i = 1; i < to_be_kept.size(); ++i)
+ {
+ if (!to_be_kept(i))
+ mln::draw::box(decision_image, filtered_objects.bbox(i), literal::red);
+ else
+ mln::draw::box(decision_image, filtered_objects.bbox(i), literal::green);
+ }
+#endif // ! NOUT
+
+
+ filtered_objects.relabel(to_be_kept);
+
+
+ // Objects have been removed we need to update object links again.
+ // This time a single link is enough since non-wanted objects have
+ // been removed.
+ left_link
+ = primitive::link::with_single_left_link(filtered_objects, 30);
+
+
+
+ // Grouping objects again.
+ groups = primitive::group::from_single_link(filtered_objects, left_link);
+
+ object_image(L)
+ grouped_objects = primitive::group::apply(filtered_objects, groups);
+
+#ifndef NOUT
+ for (unsigned i = 1; i <= grouped_objects.nlabels(); ++i)
+ mln::draw::box(decision_image, grouped_objects.bbox(i), literal::blue);
+
+ io::ppm::save(decision_image, scribo::make::debug_filename("decision_image.ppm"));
+#endif // ! NOUT
+
+
+ std::cout << "AFTER - nobjects = " << grouped_objects.nlabels() << std::endl;
+//
+
+ return grouped_objects;
+ }
+
+
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace scribo;
+ using namespace mln;
+
+ if (argc != 4)
+ return scribo::debug::usage(argv,
+ "Find text in a binarized photo.",
+ "input.pbm input_i.pbm output_dir",
+ args_desc,
+ "Several color images");
+
+
+ scribo::make::internal::debug_filename_prefix = argv[3];
+
+
+ trace::entering("main");
+
+ image2d<bool> input;
+ io::pbm::load(input, argv[1]);
+
+ typedef image2d<value::label_16> L;
+
+ value::label_16 new_nlabels;
+
+ object_image(L) out_1 = run(input);
+
+#ifndef NOUT
+ io::ppm::save(mln::labeling::colorize(value::rgb8(),
+ out_1,
+ new_nlabels),
+ scribo::make::debug_filename("out_normal.ppm"));
+#endif // ! NOUT
+
+
+ image2d<bool> input_i;
+ io::pbm::load(input_i, argv[2]);
+
+ object_image(L) out_2 = run(input_i);
+
+#ifndef NOUT
+ io::ppm::save(mln::labeling::colorize(value::rgb8(),
+ out_2,
+ new_nlabels),
+ scribo::make::debug_filename("out_inverted.ppm"));
+#endif // ! NOUT
+
+
+ L out = labeling::superpose(out_1, out_1.nlabels(),
+ out_2, out_2.nlabels(),
+ new_nlabels);
+
+
+ io::ppm::save(mln::labeling::colorize(value::rgb8(),
+ out,
+ new_nlabels),
+ scribo::make::debug_filename("out_combined.ppm"));
+
+
+ trace::exiting("main");
+}
--
1.5.6.5
* filter/all.hh: Add new includes.
* filter/object_links_non_aligned.hh,
* filter/object_links_non_h_aligned.hh,
* filter/object_links_non_v_aligned.hh: New filters.
* src/text/grouping/group_from_double_link_filter_non_aligned.cc:
New example.
* headers.mk,
* tests/unit_test/unit-tests.mk: Regen.
---
scribo/ChangeLog | 16 ++
scribo/filter/all.hh | 3 +
scribo/filter/object_links_non_aligned.hh | 136 ++++++++++++++++
scribo/filter/object_links_non_h_aligned.hh | 109 +++++++++++++
scribo/filter/object_links_non_v_aligned.hh | 122 +++++++++++++++
scribo/headers.mk | 18 +-
.../group_from_double_link_filter_non_aligned.cc | 165 ++++++++++++++++++++
scribo/tests/unit_test/unit-tests.mk | 36 ++--
8 files changed, 578 insertions(+), 27 deletions(-)
create mode 100644 scribo/filter/object_links_non_aligned.hh
create mode 100644 scribo/filter/object_links_non_h_aligned.hh
create mode 100644 scribo/filter/object_links_non_v_aligned.hh
create mode 100644 scribo/src/text/grouping/group_from_double_link_filter_non_aligned.cc
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index a7cd378..69af059 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,21 @@
2009-08-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add new filters.
+
+ * filter/all.hh: Add new includes.
+
+ * filter/object_links_non_aligned.hh,
+ * filter/object_links_non_h_aligned.hh,
+ * filter/object_links_non_v_aligned.hh: New filters.
+
+ * src/text/grouping/group_from_double_link_filter_non_aligned.cc:
+ New example.
+
+ * headers.mk,
+ * tests/unit_test/unit-tests.mk: Regen.
+
+2009-08-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Rename filters.
* filter/all.hh: Update includes.
diff --git a/scribo/filter/all.hh b/scribo/filter/all.hh
index 0b5bc11..f9ef9ce 100644
--- a/scribo/filter/all.hh
+++ b/scribo/filter/all.hh
@@ -42,6 +42,9 @@ namespace scribo
} // end of namespace scribo
# include <scribo/filter/object_groups_small.hh>
+# include <scribo/filter/object_links_non_aligned.hh>
+# include <scribo/filter/object_links_non_h_aligned.hh>
+# include <scribo/filter/object_links_non_v_aligned.hh>
# include <scribo/filter/objects_large.hh>
# include <scribo/filter/objects_small.hh>
# include <scribo/filter/objects_thick.hh>
diff --git a/scribo/filter/object_links_non_aligned.hh b/scribo/filter/object_links_non_aligned.hh
new file mode 100644
index 0000000..46a425e
--- /dev/null
+++ b/scribo/filter/object_links_non_aligned.hh
@@ -0,0 +1,136 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 SCRIBO_FILTER_OBJECT_LINKS_NON_ALIGNED_HH
+# define SCRIBO_FILTER_OBJECT_LINKS_NON_ALIGNED_HH
+
+/// \file
+///
+/// Invalidate links between two non aligned objects.
+
+
+# include <mln/util/array.hh>
+
+# include <scribo/core/macros.hh>
+# include <scribo/core/object_links.hh>
+# include <scribo/core/object_image.hh>
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+ /*! \brief Invalidate links between two non aligned objects.
+ Alignment is based on object bounding boxes.
+
+ \param[in] objects An object image.
+ \param[in] links Object links information.
+ \param[in] dim Choose the dimension on which applying the
+ filter.
+ \param[in] max_delta Maximum delta.
+
+
+ Exemple with dim == 1 (horizontal filter):
+
+ \verbatim
+ v
+ ------ ~ ~ ~
+ | | |\
+ ------ ~ ~ ~ |~ ~ | ~ ~ ~ \
+ | | | | ^ \
+ | x------------x | => delta, must be < to max_delta
+ | | | | v /
+ ------ ~ ~ ~ |~ ~ | ~ ~ ~ /
+ object1 | | |/
+ ------ ~ ~ ~
+ object2 ^
+
+ \endverbatim
+
+ */
+ template <typename L>
+ object_links<L>
+ object_links_non_aligned(const object_image(L)& objects,
+ const object_links<L>& links,
+ unsigned dim,
+ unsigned max_delta);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename L>
+ object_links<L>
+ object_links_non_aligned(const object_image(L)& objects,
+ const object_links<L>& links,
+ unsigned dim,
+ unsigned max_delta)
+ {
+ trace::entering("scribo::filter::object_links_non_aligned");
+
+ mln_precondition(objects.is_valid());
+
+
+ typedef typename object_image(L)::bbox_t bbox_t;
+ const mln::util::array<bbox_t>& bboxes = objects.bboxes();
+ object_links<L> output(links);
+
+ for_all_components(i, objects.bboxes())
+ {
+
+ unsigned
+ lnbh = bboxes(links[i]).pmax()[dim] - bboxes(links[i]).pmin()[dim],
+ lcurrent = bboxes(i).pmax()[dim] - bboxes(i).pmin()[dim],
+ hmin = i,
+ hmax = links[i];
+
+ if (lnbh < lcurrent)
+ {
+ hmin = links[i];
+ hmax = i;
+ }
+
+ if ((bboxes[hmin].pmin()[dim] - (float)bboxes[hmax].pmin()[dim]) > max_delta
+ || (bboxes[hmin].pmax()[dim] - (float) bboxes[hmax].pmax()[dim]) > max_delta)
+ output[i] = i;
+ }
+
+ trace::exiting("scribo::filter::object_links_non_aligned");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_FILTER_OBJECT_LINKS_NON_ALIGNED_HH
diff --git a/scribo/filter/object_links_non_h_aligned.hh b/scribo/filter/object_links_non_h_aligned.hh
new file mode 100644
index 0000000..cae84a9
--- /dev/null
+++ b/scribo/filter/object_links_non_h_aligned.hh
@@ -0,0 +1,109 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 SCRIBO_FILTER_OBJECT_LINKS_NON_H_ALIGNED_HH
+# define SCRIBO_FILTER_OBJECT_LINKS_NON_H_ALIGNED_HH
+
+/// \file
+///
+/// Invalidate links between two non horizontaly aligned objects.
+
+
+# include <mln/util/array.hh>
+
+# include <scribo/core/object_links.hh>
+# include <scribo/core/object_image.hh>
+# include <scribo/filter/object_links_non_aligned.hh>
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+
+ /*! \brief Invalidate links between two non horizontaly aligned objects.
+ Alignment is based on object bounding boxes.
+
+ \param[in] objects An object image.
+ \param[in] links Object links information.
+ \param[in] max_delta Maximum delta.
+
+ \result Filtered object links data.
+
+ \verbatim
+ v
+ ------ ~ ~ ~
+ | | |\
+ ------ ~ ~ ~ |~ ~ | ~ ~ ~ \
+ | | | | ^ \
+ | x- - - - - --x | => delta, must be < to max_delta
+ | | | | v /
+ ------ ~ ~ ~ |~ ~ | ~ ~ ~ /
+ object1 | | |/
+ ------ ~ ~ ~
+ object2 ^
+
+ \endverbatim
+
+
+ */
+ template <typename L>
+ object_links<L>
+ object_links_non_h_aligned(const object_image(L)& objects,
+ const object_links<L>& links,
+ float ratio);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename L>
+ object_links<L>
+ object_links_non_h_aligned(const object_image(L)& objects,
+ const object_links<L>& links,
+ float ratio)
+ {
+ trace::entering("scribo::filter::object_links_non_h_aligned");
+
+ mln_precondition(objects.is_valid());
+
+ object_links<L>
+ output = object_links_non_aligned(objects, links, 1, ratio);
+
+ trace::exiting("scribo::filter::object_links_non_h_aligned");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_FILTER_OBJECT_LINKS_NON_H_ALIGNED_HH
diff --git a/scribo/filter/object_links_non_v_aligned.hh b/scribo/filter/object_links_non_v_aligned.hh
new file mode 100644
index 0000000..bd2aeee
--- /dev/null
+++ b/scribo/filter/object_links_non_v_aligned.hh
@@ -0,0 +1,122 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 SCRIBO_FILTER_OBJECT_LINKS_NON_V_ALIGNED_HH
+# define SCRIBO_FILTER_OBJECT_LINKS_NON_V_ALIGNED_HH
+
+/// \file
+///
+/// Invalidate links between two non verticaly aligned objects.
+
+
+# include <mln/util/array.hh>
+
+# include <scribo/core/object_links.hh>
+# include <scribo/core/object_image.hh>
+# include <scribo/filter/object_links_non_aligned.hh>
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+ /*! \brief Invalidate links between two non verticaly aligned objects.
+ Alignment is based on object bounding boxes.
+
+ \param[in] objects An object image.
+ \param[in] links Object links information.
+ \param[in] max_delta Maximum delta.
+
+
+ \verbatim
+
+ delta (must be < to max_delta)
+ /\
+ / \
+ / \
+ >:-:<>:-:<
+ : :
+ : :
+ : ---:--
+ | |
+ : | x: | object1
+ | | |
+ : --|:--
+
+ : |:
+
+ : |:
+ -- ---
+ | ||
+ | |
+ | ||
+ | x| object2
+ | |
+ | |
+ | |
+ ------
+
+ \endverbatim
+
+ */
+ template <typename L>
+ object_links<L>
+ object_links_non_v_aligned(const object_image(L)& objects,
+ const object_links<L>& links,
+ float ratio);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename L>
+ object_links<L>
+ object_links_non_v_aligned(const object_image(L)& objects,
+ const object_links<L>& links,
+ float ratio)
+ {
+ trace::entering("scribo::object_links::object_links_non_v_aligned");
+
+ mln_precondition(objects.is_valid());
+
+ object_links<L>
+ output = object_links_non_aligned(objects, links, 0, ratio);
+
+ trace::exiting("scribo::filter::object_links_non_v_aligned");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_FILTER_OBJECT_LINKS_NON_V_ALIGNED_HH
diff --git a/scribo/headers.mk b/scribo/headers.mk
index c266c78..8ca14cf 100644
--- a/scribo/headers.mk
+++ b/scribo/headers.mk
@@ -21,12 +21,15 @@ nobase_scribo_HEADERS = \
./draw/bounding_box_links.hh \
./draw/bounding_boxes.hh \
./filter/all.hh \
-./filter/large_objects.hh \
-./filter/small_object_groups.hh \
-./filter/small_objects.hh \
-./filter/thick_objects.hh \
-./filter/thin_objects.hh \
-./fun/v2b/small_objects_filter.hh \
+./filter/object_groups_small.hh \
+./filter/object_links_non_aligned.hh \
+./filter/object_links_non_h_aligned.hh \
+./filter/object_links_non_v_aligned.hh \
+./filter/objects_large.hh \
+./filter/objects_small.hh \
+./filter/objects_thick.hh \
+./filter/objects_thin.hh \
+./fun/v2b/objects_small_filter.hh \
./make/all.hh \
./make/debug_filename.hh \
./make/influence_zone_graph.hh \
@@ -51,9 +54,6 @@ nobase_scribo_HEADERS = \
./primitive/extract/objects.hh \
./primitive/group/all.hh \
./primitive/group/apply.hh \
-./primitive/group/filter_non_aligned.hh \
-./primitive/group/filter_non_h_aligned.hh \
-./primitive/group/filter_non_v_aligned.hh \
./primitive/group/from_double_link.hh \
./primitive/group/from_graph.hh \
./primitive/group/from_single_link.hh \
diff --git a/scribo/src/text/grouping/group_from_double_link_filter_non_aligned.cc b/scribo/src/text/grouping/group_from_double_link_filter_non_aligned.cc
new file mode 100644
index 0000000..fce389e
--- /dev/null
+++ b/scribo/src/text/grouping/group_from_double_link_filter_non_aligned.cc
@@ -0,0 +1,165 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#include <iostream>
+
+#include <mln/core/image/image2d.hh>
+#include <mln/labeling/colorize.hh>
+#include <mln/debug/println.hh>
+#include <mln/util/array.hh>
+#include <mln/literal/colors.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/value/label_16.hh>
+
+#include <scribo/core/object_image.hh>
+
+#include <scribo/primitive/extract/objects.hh>
+#include <scribo/primitive/link/with_single_left_link.hh>
+#include <scribo/primitive/link/with_single_right_link.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
+#include <scribo/primitive/group/from_double_link.hh>
+#include <scribo/primitive/group/from_single_link.hh>
+#include <scribo/primitive/link/merge_double_link.hh>
+#include <scribo/primitive/group/apply.hh>
+#include <scribo/filter/objects_small.hh>
+
+#include <scribo/filter/object_links_non_h_aligned.hh>
+
+#include <scribo/debug/save_bboxes_image.hh>
+#include <scribo/make/debug_filename.hh>
+
+
+#include <scribo/debug/usage.hh>
+
+const char *args_desc[][2] =
+{
+ { "input.pbm", "A binary image. 'True' for objects, 'False'\
+for the background." },
+ { "hlmax", "Maximum distance between two grouped objects while browsing on the left." },
+ { "hrmax", "Maximum distance between two grouped objects while browsing on the right." },
+ { "hdelta_max", "Maximum horizontal distance between top/bottom corner of two grouped bboxes." },
+ { "prefix", "Output names prefix" },
+ {0, 0}
+};
+
+int main(int argc, char *argv[])
+{
+ using namespace scribo;
+ using namespace mln;
+
+ if (argc != 6)
+ return scribo::debug::usage(argv,
+ "Group potential text objects using a double validation link.",
+ "input.pbm hlmax hrmax hdelta_max prefix",
+ args_desc,
+ "Several images showing the process.");
+
+
+ scribo::make::internal::debug_filename_prefix = argv[5];
+
+ image2d<bool> input;
+ io::pbm::load(input, argv[1]);
+
+ value::label_16 nbboxes;
+ typedef image2d<value::label_16> L;
+ typedef object_image(L) text_t;
+
+ text_t text = primitive::extract::objects(input, c8(), nbboxes);
+
+ text = filter::objects_small(text, 4);
+
+ object_links<L> left_link
+ = primitive::link::with_single_left_link(text, atoi(argv[2]));
+ object_links<L> right_link
+ = primitive::link::with_single_right_link(text, atoi(argv[3]));
+
+ 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_bboxes_image(input,
+ text, left_link, right_link,
+ literal::red, literal::cyan, literal::yellow,
+ literal::green,
+ scribo::make::debug_filename("links.ppm"));
+
+ // With validation.
+ object_links<L> double_link
+ = primitive::link::merge_double_link(text,
+ left_link,
+ right_link);
+
+
+ text_t
+ grouped_text = primitive::group::apply(text, double_link);
+ std::cout << "AFTER double grouping - nbboxes = "
+ << grouped_text.bboxes().nelements() << std::endl;
+
+
+ io::ppm::save(mln::labeling::colorize(value::rgb8(),
+ grouped_text,
+ grouped_text.nlabels()),
+ scribo::make::debug_filename("label_color.ppm"));
+
+
+ scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("bboxes.ppm"));
+
+
+
+ // Filter non-correctly aligned grouped objects.
+
+ object_links<L> filtered_links
+ = filter::object_links_non_h_aligned(text, double_link, atoi(argv[4]));
+
+
+ text_t aligned_grouped_text
+ = primitive::group::apply(text, filtered_links);
+
+
+ std::cout << "AFTER filtering - Links may have been canceled - nbboxes = "
+ << aligned_grouped_text.bboxes().nelements() << std::endl;
+
+
+ io::ppm::save(mln::labeling::colorize(value::rgb8(),
+ aligned_grouped_text,
+ aligned_grouped_text.nlabels()),
+ scribo::make::debug_filename("label_color-filtered.ppm"));
+
+
+ scribo::debug::save_bboxes_image(input, aligned_grouped_text.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("bboxes-filtered.ppm"));
+
+}
diff --git a/scribo/tests/unit_test/unit-tests.mk b/scribo/tests/unit_test/unit-tests.mk
index 237581f..89c72d9 100644
--- a/scribo/tests/unit_test/unit-tests.mk
+++ b/scribo/tests/unit_test/unit-tests.mk
@@ -20,12 +20,15 @@ scribo_draw_all \
scribo_draw_bounding_box_links \
scribo_draw_bounding_boxes \
scribo_filter_all \
-scribo_filter_large_objects \
-scribo_filter_small_object_groups \
-scribo_filter_small_objects \
-scribo_filter_thick_objects \
-scribo_filter_thin_objects \
-scribo_fun_v2b_small_objects_filter \
+scribo_filter_object_groups_small \
+scribo_filter_object_links_non_aligned \
+scribo_filter_object_links_non_h_aligned \
+scribo_filter_object_links_non_v_aligned \
+scribo_filter_objects_large \
+scribo_filter_objects_small \
+scribo_filter_objects_thick \
+scribo_filter_objects_thin \
+scribo_fun_v2b_objects_small_filter \
scribo_make_all \
scribo_make_debug_filename \
scribo_make_influence_zone_graph \
@@ -50,9 +53,6 @@ scribo_primitive_extract_lines_v_thick \
scribo_primitive_extract_objects \
scribo_primitive_group_all \
scribo_primitive_group_apply \
-scribo_primitive_group_filter_non_aligned \
-scribo_primitive_group_filter_non_h_aligned \
-scribo_primitive_group_filter_non_v_aligned \
scribo_primitive_group_from_double_link \
scribo_primitive_group_from_graph \
scribo_primitive_group_from_single_link \
@@ -114,12 +114,15 @@ scribo_draw_all_SOURCES = scribo_draw_all.cc
scribo_draw_bounding_box_links_SOURCES = scribo_draw_bounding_box_links.cc
scribo_draw_bounding_boxes_SOURCES = scribo_draw_bounding_boxes.cc
scribo_filter_all_SOURCES = scribo_filter_all.cc
-scribo_filter_large_objects_SOURCES = scribo_filter_large_objects.cc
-scribo_filter_small_object_groups_SOURCES = scribo_filter_small_object_groups.cc
-scribo_filter_small_objects_SOURCES = scribo_filter_small_objects.cc
-scribo_filter_thick_objects_SOURCES = scribo_filter_thick_objects.cc
-scribo_filter_thin_objects_SOURCES = scribo_filter_thin_objects.cc
-scribo_fun_v2b_small_objects_filter_SOURCES = scribo_fun_v2b_small_objects_filter.cc
+scribo_filter_object_groups_small_SOURCES = scribo_filter_object_groups_small.cc
+scribo_filter_object_links_non_aligned_SOURCES = scribo_filter_object_links_non_aligned.cc
+scribo_filter_object_links_non_h_aligned_SOURCES = scribo_filter_object_links_non_h_aligned.cc
+scribo_filter_object_links_non_v_aligned_SOURCES = scribo_filter_object_links_non_v_aligned.cc
+scribo_filter_objects_large_SOURCES = scribo_filter_objects_large.cc
+scribo_filter_objects_small_SOURCES = scribo_filter_objects_small.cc
+scribo_filter_objects_thick_SOURCES = scribo_filter_objects_thick.cc
+scribo_filter_objects_thin_SOURCES = scribo_filter_objects_thin.cc
+scribo_fun_v2b_objects_small_filter_SOURCES = scribo_fun_v2b_objects_small_filter.cc
scribo_make_all_SOURCES = scribo_make_all.cc
scribo_make_debug_filename_SOURCES = scribo_make_debug_filename.cc
scribo_make_influence_zone_graph_SOURCES = scribo_make_influence_zone_graph.cc
@@ -144,9 +147,6 @@ scribo_primitive_extract_lines_v_thick_SOURCES = scribo_primitive_extract_lines_
scribo_primitive_extract_objects_SOURCES = scribo_primitive_extract_objects.cc
scribo_primitive_group_all_SOURCES = scribo_primitive_group_all.cc
scribo_primitive_group_apply_SOURCES = scribo_primitive_group_apply.cc
-scribo_primitive_group_filter_non_aligned_SOURCES = scribo_primitive_group_filter_non_aligned.cc
-scribo_primitive_group_filter_non_h_aligned_SOURCES = scribo_primitive_group_filter_non_h_aligned.cc
-scribo_primitive_group_filter_non_v_aligned_SOURCES = scribo_primitive_group_filter_non_v_aligned.cc
scribo_primitive_group_from_double_link_SOURCES = scribo_primitive_group_from_double_link.cc
scribo_primitive_group_from_graph_SOURCES = scribo_primitive_group_from_graph.cc
scribo_primitive_group_from_single_link_SOURCES = scribo_primitive_group_from_single_link.cc
--
1.5.6.5
* core/object_groups.hh,
* core/object_links.hh: New.
---
scribo/ChangeLog | 7 ++
scribo/core/object_groups.hh | 125 ++++++++++++++++++++++++++++++++++++++++++
scribo/core/object_links.hh | 114 ++++++++++++++++++++++++++++++++++++++
3 files changed, 246 insertions(+), 0 deletions(-)
create mode 100644 scribo/core/object_groups.hh
create mode 100644 scribo/core/object_links.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 23c8c0d..24f7305 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Introduce new structures for objects links and groups.
+
+ * core/object_groups.hh,
+ * core/object_links.hh: New.
+
2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
New object grouping routine based on a rag.
diff --git a/scribo/core/object_groups.hh b/scribo/core/object_groups.hh
new file mode 100644
index 0000000..3e49942
--- /dev/null
+++ b/scribo/core/object_groups.hh
@@ -0,0 +1,125 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 SCRIBO_CORE_OBJECT_GROUPS_HH
+# define SCRIBO_CORE_OBJECT_GROUPS_HH
+
+/// \file
+///
+/// \brief Object groups representation.
+///
+/// \fixme Should not inherit from util::array.
+
+# include <mln/util/array.hh>
+
+# include <scribo/core/object_links.hh>
+# include <scribo/core/object_image.hh>
+
+namespace scribo
+{
+
+ using namespace mln;
+
+
+ /// \brief Object group representation.
+ //
+ template <typename L>
+ class object_groups
+ : public mln::util::array<unsigned>
+ {
+ typedef mln::util::array<unsigned> super_t;
+
+ public:
+ object_groups(const object_image(L)& objects);
+ object_groups(const object_image(L)& objects, unsigned n);
+ object_groups(const object_image(L)& objects, unsigned n, unsigned value);
+
+ const void* objects_id_() const;
+ const object_image(L)& object_image_() const;
+
+ void init_(const object_links<L>& links);
+
+ private:
+ object_image(L) objects_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L>
+ object_groups<L>::object_groups(const object_image(L)& objects)
+ : objects_(objects)
+ {
+
+ }
+
+
+ template <typename L>
+ object_groups<L>::object_groups(const object_image(L)& objects, unsigned n)
+ : super_t(n), objects_(objects)
+ {
+
+ }
+
+
+ template <typename L>
+ object_groups<L>::object_groups(const object_image(L)& objects,
+ unsigned n, unsigned value)
+ : super_t(n, value), objects_(objects)
+ {
+
+ }
+
+ template <typename L>
+ const void*
+ object_groups<L>::objects_id_() const
+ {
+ return objects_.id_();
+ }
+
+ template <typename L>
+ const object_image(L)&
+ object_groups<L>::object_image_() const
+ {
+ return objects_;
+ }
+
+
+ template <typename L>
+ void
+ object_groups<L>::init_(const object_links<L>& links)
+ {
+ objects_ = links.object_image_();
+ this->hook_std_vector_() = links.std_vector();
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_CORE_OBJECT_GROUPS_HH
diff --git a/scribo/core/object_links.hh b/scribo/core/object_links.hh
new file mode 100644
index 0000000..aa70bf8
--- /dev/null
+++ b/scribo/core/object_links.hh
@@ -0,0 +1,114 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 SCRIBO_CORE_OBJECT_LINKS_HH
+# define SCRIBO_CORE_OBJECT_LINKS_HH
+
+/// \file
+///
+/// \brief Object links representation.
+///
+/// \fixme Should not inherit from util::array.
+
+# include <mln/util/array.hh>
+
+# include <scribo/core/object_image.hh>
+
+
+namespace scribo
+{
+
+ using namespace mln;
+
+ /// \brief Object group representation.
+ //
+ template <typename L>
+ class object_links
+ : public mln::util::array<unsigned>
+ {
+ typedef mln::util::array<unsigned> super_t;
+
+ public:
+ object_links(const object_image(L)& objects);
+ object_links(const object_image(L)& objects, unsigned n);
+ object_links(const object_image(L)& objects, unsigned n, unsigned value);
+
+
+ const void* objects_id_() const;
+ const object_image(L)& object_image_() const;
+
+ private:
+ object_image(L) objects_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L>
+ object_links<L>::object_links(const object_image(L)& objects)
+ : objects_(objects)
+ {
+
+ }
+
+ template <typename L>
+ object_links<L>::object_links(const object_image(L)& objects, unsigned n)
+ : super_t(n), objects_(objects)
+ {
+
+ }
+
+
+ template <typename L>
+ object_links<L>::object_links(const object_image(L)& objects,
+ unsigned n, unsigned value)
+ : super_t(n, value), objects_(objects)
+ {
+
+ }
+
+
+ template <typename L>
+ const void *
+ object_links<L>::objects_id_() const
+ {
+ return objects_.id_();
+ }
+
+ template <typename L>
+ const object_image(L)&
+ object_links<L>::object_image_() const
+ {
+ return objects_;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_CORE_OBJECT_LINKS_HH
--
1.5.6.5