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
March 2009
- 9 participants
- 202 discussions
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add into scribo a simple binarization.
* scribo/binarization: New directory.
* scribo/binarization/simple.hh: New.
* scribo/src/binarization: New directory.
* scribo/src/Makefile.am: Update.
* scribo/src/binarization/Makefile.am: New.
* scribo/src/binarization/simple.cc: New.
binarization/simple.hh | 178 +++++++++++++++++++++++++++++++++++++++++++
src/Makefile.am | 3
src/binarization/Makefile.am | 9 ++
src/binarization/simple.cc | 36 ++++++++
4 files changed, 226 insertions(+)
Index: scribo/src/binarization/Makefile.am
--- scribo/src/binarization/Makefile.am (revision 0)
+++ scribo/src/binarization/Makefile.am (revision 0)
@@ -0,0 +1,9 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/sandbox/scribo/scribo.mk
+
+bin_PROGRAMS = \
+ simple
+
+simple_SOURCES = simple.cc
+
Index: scribo/src/binarization/simple.cc
--- scribo/src/binarization/simple.cc (revision 0)
+++ scribo/src/binarization/simple.cc (revision 0)
@@ -0,0 +1,36 @@
+#include <scribo/binarization/simple.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pbm/save.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.pgm output.pbm" << std::endl
+ << " Simple binarization in SCRIBO." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 3)
+ usage(argv);
+
+ trace::entering("main");
+
+ image2d<int_u8> input;
+ io::pgm::load(input, argv[1]);
+
+
+ io::pbm::save(scribo::binarization::simple(input),
+ argv[2]);
+
+
+ trace::exiting("main");
+}
Index: scribo/src/Makefile.am
--- scribo/src/Makefile.am (revision 3594)
+++ scribo/src/Makefile.am (working copy)
@@ -2,6 +2,9 @@
include $(top_srcdir)/milena/sandbox/scribo/scribo.mk
+SUBDIRS = \
+ binarization
+
bin_PROGRAMS = \
dmap \
extract_text_single_link \
Index: scribo/binarization/simple.hh
--- scribo/binarization/simple.hh (revision 0)
+++ scribo/binarization/simple.hh (revision 0)
@@ -0,0 +1,178 @@
+// Copyright (C) 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 SCRIBO_BINARIZATION_SIMPLE_HH
+# define SCRIBO_BINARIZATION_SIMPLE_HH
+
+/// \file scribo/binarization/simple.hh
+///
+/// Simple binarization of a gray-level document.
+
+# include <mln/core/image/image1d.hh>
+# include <mln/core/alias/neighb1d.hh>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/core/alias/neighb2d.hh>
+
+# include <mln/core/routine/duplicate.hh>
+# include <mln/core/image/image_if.hh>
+# include <mln/pw/all.hh>
+
+# include <mln/histo/compute.hh>
+# include <mln/debug/histo.hh>
+# include <mln/convert/from_to.hh>
+
+# include <mln/morpho/elementary/gradient_external.hh>
+# include <mln/morpho/closing/height.hh>
+# include <mln/morpho/closing/volume.hh>
+# include <mln/morpho/watershed/flooding.hh>
+
+# include <mln/linear/gaussian_1d.hh>
+# include <mln/labeling/regional_minima.hh>
+# include <mln/labeling/compute.hh>
+# include <mln/value/label_8.hh>
+# include <mln/accu/center.hh>
+
+
+
+namespace scribo
+{
+
+ namespace binarization
+ {
+
+ using namespace mln;
+
+ /// Simple binarization of a gray-level document.
+ /*!
+ *
+ * \param[in] input_ A binary image.
+ * \param[in] nbh_ The neighborhood used for labeling image components.
+ * \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
+ * opening
+ *
+ * \return pair of array of bounding boxes. The first array holds the
+ * vertical lines bounding boxes and the second one the
+ * horizontal lines bounding boxes.
+ */
+ template <typename I>
+ mln_ch_value(I, bool)
+ simple(const Image<I>& input);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ inline
+ mln_ch_value(I, bool)
+ simple(const Image<I>& input_)
+ {
+ trace::entering("scribo::binarization::simple");
+
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ const float sigma = 5; // FIXME: hard-coded!
+
+ typedef mln_value(I) V;
+ histo::array<V> h;
+
+ {
+ mln_concrete(I) g;
+ g = morpho::elementary::gradient_external(input, c4());
+ g = morpho::closing::height(g, c4(), 5); // FIXME: hard-coded!
+
+ unsigned nbasins;
+ mln_ch_value(I, unsigned) w = morpho::watershed::flooding(g, c4(), nbasins);
+ h = histo::compute(input | (pw::value(w) == pw::cst(0)));
+ }
+
+
+ util::array<point1d> c;
+ value::label_8 n;
+
+ {
+ image1d<unsigned> h_, hs_;
+ image1d<value::label_8> l;
+
+ convert::from_to(h, h_);
+ hs_ = linear::gaussian_1d(h_, sigma, 0);
+ l = labeling::regional_minima(hs_, c2(), n);
+
+ if (n < 3)
+ {
+ std::cerr << "This method has not worked properly!" << std::endl;
+
+ debug::histo(h, "tmp_h.txt");
+
+ std::ofstream file("tmp_hs.txt");
+ mln_piter(box1d) p(h_.domain());
+ for_all(p)
+ file << p.ind() << ' ' << hs_(p) << std::endl;
+ file.close();
+
+ std::abort();
+ }
+
+ accu::center<point1d, point1d> a;
+ c = labeling::compute(a, l, n);
+ c[0] = point1d(0); // Force a neutral value for the non-label value (0).
+ }
+
+ int threshold;
+
+ {
+ std::vector<int> v;
+ for (unsigned i = 0; i <= n; ++i)
+ v.push_back(c[i].ind());
+ std::sort(v.begin(), v.end());
+ threshold = v[n.prev()];
+
+ // std::cout << "threshold = " << threshold << std::endl;
+ }
+
+ mln_ch_value(I, bool) output;
+ output = duplicate((pw::value(input) > pw::cst(threshold)) | input.domain());
+
+ trace::exiting("scribo::binarization::simple");
+ return output;
+ }
+
+# endif // !MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::binarization
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_BINARIZATION_SIMPLE_HH
1
0
30 Mar '09
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-30 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Add time smoothing in IGR and drafts of space smoothing.
* fabien/igr/Makefile.rules: New file to centralize rules.
* fabien/igr/img/slice_7.pgm: Remove.
* fabien/igr/img: Remove.
* fabien/igr/space_smooth/Makefile: New.
* fabien/igr/space_smooth/linear.cc: Implements linear space smoothing.
* fabien/igr/space_smooth/median.cc: Draft.
* fabien/igr/space_smooth/morpho.cc: Draft.
* fabien/igr/time_smooth/Makefile: New.
* fabien/igr/time_smooth/linear.cc: Implements linear time smoothing.
* fabien/igr/time_smooth/median.cc: Implements median time smoothing.
* fabien/igr/time_smooth/morpho.cc: Implements morpho time smoothing.
---
Makefile.rules | 9 ++++
space_smooth/Makefile | 15 +++++++
space_smooth/linear.cc | 75 ++++++++++++++++++++++++++++++++++++
space_smooth/median.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++
space_smooth/morpho.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++
time_smooth/Makefile | 15 +++++++
time_smooth/linear.cc | 77 ++++++++++++++++++++++++++++++++++++
time_smooth/median.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++
time_smooth/morpho.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++
9 files changed, 599 insertions(+)
Index: trunk/milena/sandbox/fabien/igr/space_smooth/median.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/space_smooth/median.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/space_smooth/median.cc (revision 3594)
@@ -0,0 +1,102 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/core/image/cast_image.hh>
+#include <mln/core/image/slice_image.hh>
+#include <mln/core/routine/duplicate.hh>
+
+#include <mln/value/int_u12.hh>
+
+#include <mln/io/dicom/load.hh>
+#include <mln/io/plot/save.hh>
+
+#include <mln/accu/median_h.hh>
+#include <mln/util/array.hh>
+
+
+using namespace mln;
+using value::int_u12;
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << "input" << std::endl;
+ return 1;
+ }
+
+ ///////////////////
+ // //
+ // Image loading //
+ // //
+ ///////////////////
+ image3d<int_u12> input;
+ io::dicom::load(input, argv[1]);
+ image2d<util::array<int_u12> > ima_arr(input.nrows(), input.ncols());
+ for (int i = 0; i < input.nslices(); ++i)
+ {
+ image2d<int_u12> tmp_slice = duplicate(slice(input, i));
+ mln_piter_(image2d<int_u12>) p(tmp_slice.domain());
+ for_all(p)
+ {
+ ima_arr(p).append(tmp_slice(p));
+ }
+ }
+
+ ////////////
+ // //
+ // Median //
+ // //
+ ////////////
+ image2d<util::array<int_u12> > ima_median3;
+ image2d<util::array<int_u12> > ima_median5;
+ initialize(ima_median3, ima_arr);
+ initialize(ima_median5, ima_arr);
+ mln_piter_(image2d<int_u12>) p(ima_median3.domain());
+ accu::median_h<int_u12> accu_med;
+ for_all(p)
+ {
+ // Median 3
+ ima_median3(p).append(ima_arr(p)[0]);
+ for (unsigned i = 1; i < ima_arr(p).nelements() - 1; ++i)
+ {
+ accu_med.init();
+ accu_med.take(ima_arr(p)[i - 1]);
+ accu_med.take(ima_arr(p)[i]);
+ accu_med.take(ima_arr(p)[i + 1]);
+ ima_median3(p).append(accu_med.to_result());
+ }
+ ima_median3(p).append(ima_arr(p)[ima_arr(p).nelements() - 1]);
+
+ // Median 5
+ ima_median5(p).append(ima_arr(p)[0]);
+ ima_median5(p).append(ima_arr(p)[1]);
+ for (unsigned i = 2; i < ima_arr(p).nelements() - 2; ++i)
+ {
+ accu_med.init();
+ accu_med.take(ima_arr(p)[i - 2]);
+ accu_med.take(ima_arr(p)[i - 1]);
+ accu_med.take(ima_arr(p)[i]);
+ accu_med.take(ima_arr(p)[i + 1]);
+ accu_med.take(ima_arr(p)[i + 2]);
+ ima_median5(p).append(accu_med.to_result());
+ }
+ ima_median5(p).append(ima_arr(p)[ima_arr(p).nelements() - 2]);
+ ima_median5(p).append(ima_arr(p)[ima_arr(p).nelements() - 1]);
+ }
+
+ /////////////
+ // //
+ // Outputs //
+ // //
+ /////////////
+ io::plot::save(ima_median3(point2d(160, 120)), "median3_tumeur.plot");
+ io::plot::save(ima_median3(point2d(34, 94)), "median3_air.plot");
+ io::plot::save(ima_median3(point2d(122, 115)), "median3_poumon.plot");
+ io::plot::save(ima_median5(point2d(160, 120)), "median5_tumeur.plot");
+ io::plot::save(ima_median5(point2d(34, 94)), "median5_air.plot");
+ io::plot::save(ima_median5(point2d(122, 115)), "median5_poumon.plot");
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/space_smooth/morpho.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/space_smooth/morpho.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/space_smooth/morpho.cc (revision 3594)
@@ -0,0 +1,102 @@
+#include <mln/core/image/image1d.hh>
+#include <mln/core/alias/neighb1d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/core/image/cast_image.hh>
+#include <mln/core/image/slice_image.hh>
+#include <mln/core/routine/duplicate.hh>
+
+#include <mln/value/int_u12.hh>
+
+#include <mln/io/dicom/load.hh>
+#include <mln/io/plot/save.hh>
+
+#include <mln/accu/median_h.hh>
+#include <mln/convert/from_to.hh>
+#include <mln/morpho/closing/area.hh>
+#include <mln/morpho/opening/area.hh>
+#include <mln/util/array.hh>
+
+/*#include <mln/draw/line.hh>
+#include <mln/io/magick/save.hh>
+#include <mln/level/convert.hh>
+#include <mln/level/stretch.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/literal/all.hh>
+using mln::value::rgb8;
+using mln::value::int_u8;*/
+
+
+using namespace mln;
+using value::int_u12;
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << "input" << std::endl;
+ return 1;
+ }
+
+ ///////////////////
+ // //
+ // Image loading //
+ // //
+ ///////////////////
+ image3d<int_u12> input;
+ io::dicom::load(input, argv[1]);
+ image2d<util::array<int_u12> > ima_arr(input.nrows(), input.ncols());
+ for (int i = 0; i < input.nslices(); ++i)
+ {
+ image2d<int_u12> tmp_slice = duplicate(slice(input, i));
+ mln_piter_(image2d<int_u12>) p(tmp_slice.domain());
+ for_all(p)
+ {
+ ima_arr(p).append(tmp_slice(p));
+ }
+ }
+
+ ////////////
+ // //
+ // Morpho //
+ // //
+ ////////////
+ image2d<image1d<int_u12> > ima_morpho;
+ initialize(ima_morpho, ima_arr);
+ mln_piter_(image2d<int_u12>) p(ima_morpho.domain());
+ accu::median_h<int_u12> accu_med;
+ for_all(p)
+ {
+ image1d<int_u12> tmp_ima;
+ convert::from_to(ima_arr(p), tmp_ima);
+ tmp_ima = morpho::closing::area(tmp_ima, c2(), 3);
+ tmp_ima = morpho::opening::area(tmp_ima, c2(), 3);
+ ima_morpho(p) = tmp_ima;
+ }
+
+ /////////////
+ // //
+ // Outputs //
+ // //
+ /////////////
+ /*image2d<rgb8> ima_color = level::convert(rgb8(), level::stretch(int_u8(), slice(input, 0)));
+ algebra::vec<2, unsigned int> vmin;
+ algebra::vec<2, unsigned int> vmax;
+ vmin[0] = 160;
+ vmin[1] = 120;
+ vmax[0] = 122;
+ vmax[1] = 115;
+ mln_site_(image2d<bool>) pbeg(vmin);
+ mln_site_(image2d<bool>) pend(vmax);
+ draw::line(ima_color, pbeg, pend, literal::red);
+ io::magick::save(ima_color, "test.png");*/
+
+ io::plot::save(ima_morpho(point2d(160, 120)), "morpho_tumeur.plot");
+ io::plot::save(ima_morpho(point2d(34, 94)), "morpho_air.plot");
+ io::plot::save(ima_morpho(point2d(122, 115)), "morpho_poumon.plot");
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/space_smooth/Makefile
===================================================================
--- trunk/milena/sandbox/fabien/igr/space_smooth/Makefile (revision 0)
+++ trunk/milena/sandbox/fabien/igr/space_smooth/Makefile (revision 3594)
@@ -0,0 +1,15 @@
+include ../Makefile.rules
+
+
+linear: linear.cc
+ ${CXX} -I../../../../ ${DICOM} ${CXXFLAGS} $^ -o linear
+
+median: median.cc
+ ${CXX} -I../../../../ ${DICOM} ${CXXFLAGS} $^ -o median
+
+morpho: morpho.cc
+ ${CXX} -I../../../../ ${DICOM} ${MAGICK} ${CXXFLAGS} $^ -o morpho
+
+clean:
+ rm -rf *.dump *.p?m *.plot *.log *.csv *.dSYM
+ rm linear median morpho
Index: trunk/milena/sandbox/fabien/igr/space_smooth/linear.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/space_smooth/linear.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/space_smooth/linear.cc (revision 3594)
@@ -0,0 +1,75 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/core/image/cast_image.hh>
+#include <mln/core/image/slice_image.hh>
+#include <mln/core/routine/duplicate.hh>
+
+#include <mln/value/int_u12.hh>
+
+#include <mln/io/dicom/load.hh>
+#include <mln/io/plot/save.hh>
+
+#include <mln/accu/median_h.hh>
+#include <mln/linear/convolve.hh>
+#include <mln/make/w_window2d.hh>
+#include <mln/util/array.hh>
+
+
+using namespace mln;
+using value::int_u12;
+
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << "input" << std::endl;
+ return 1;
+ }
+
+ ///////////////////
+ // //
+ // Image loading //
+ // //
+ ///////////////////
+ image3d<int_u12> input;
+ io::dicom::load(input, argv[1]);
+ util::array<image2d<int_u12> > arr_ima;
+ for (int i = 0; i < input.nslices(); ++i)
+ {
+ image2d<int_u12> tmp_slice = duplicate(slice(input, i));
+ arr_ima.append(tmp_slice);
+ }
+
+ ////////////////////////
+ // //
+ // Linear convolution //
+ // //
+ ////////////////////////
+ float ws[] = { 0, 1/8, 0,
+ 1/8, 1/2, 1/8,
+ 0, 1/8, 0 };
+
+ util::array<image2d<float> > ima_linear;
+ for (unsigned i = 1; i < arr_ima.nelements(); ++i)
+ ima_linear.append(linear::convolve(arr_ima[i], make::w_window2d(ws)));
+
+ /////////////
+ // //
+ // Outputs //
+ // //
+ /////////////
+ image2d<util::array<float> > ima_result(input.nrows(), input.ncols());
+ mln_piter_(image2d<util::array<float> >) p(ima_linear[0].domain());
+ for_all(p)
+ for (int i = 0; i < ima_linear.nelements(); ++i)
+ ima_result(p).append(ima_linear[i](p));
+
+ io::plot::save(ima_result(point2d(160, 120)), "linear_tumeur.plot");
+ io::plot::save(ima_result(point2d(34, 94)), "linear_air.plot");
+ io::plot::save(ima_result(point2d(122, 115)), "linear_poumon.plot");
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/time_smooth/median.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/time_smooth/median.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/time_smooth/median.cc (revision 3594)
@@ -0,0 +1,102 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/core/image/cast_image.hh>
+#include <mln/core/image/slice_image.hh>
+#include <mln/core/routine/duplicate.hh>
+
+#include <mln/value/int_u12.hh>
+
+#include <mln/io/dicom/load.hh>
+#include <mln/io/plot/save.hh>
+
+#include <mln/accu/median_h.hh>
+#include <mln/util/array.hh>
+
+
+using namespace mln;
+using value::int_u12;
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << "input" << std::endl;
+ return 1;
+ }
+
+ ///////////////////
+ // //
+ // Image loading //
+ // //
+ ///////////////////
+ image3d<int_u12> input;
+ io::dicom::load(input, argv[1]);
+ image2d<util::array<int_u12> > ima_arr(input.nrows(), input.ncols());
+ for (int i = 0; i < input.nslices(); ++i)
+ {
+ image2d<int_u12> tmp_slice = duplicate(slice(input, i));
+ mln_piter_(image2d<int_u12>) p(tmp_slice.domain());
+ for_all(p)
+ {
+ ima_arr(p).append(tmp_slice(p));
+ }
+ }
+
+ ////////////
+ // //
+ // Median //
+ // //
+ ////////////
+ image2d<util::array<int_u12> > ima_median3;
+ image2d<util::array<int_u12> > ima_median5;
+ initialize(ima_median3, ima_arr);
+ initialize(ima_median5, ima_arr);
+ mln_piter_(image2d<int_u12>) p(ima_median3.domain());
+ accu::median_h<int_u12> accu_med;
+ for_all(p)
+ {
+ // Median 3
+ ima_median3(p).append(ima_arr(p)[0]);
+ for (unsigned i = 1; i < ima_arr(p).nelements() - 1; ++i)
+ {
+ accu_med.init();
+ accu_med.take(ima_arr(p)[i - 1]);
+ accu_med.take(ima_arr(p)[i]);
+ accu_med.take(ima_arr(p)[i + 1]);
+ ima_median3(p).append(accu_med.to_result());
+ }
+ ima_median3(p).append(ima_arr(p)[ima_arr(p).nelements() - 1]);
+
+ // Median 5
+ ima_median5(p).append(ima_arr(p)[0]);
+ ima_median5(p).append(ima_arr(p)[1]);
+ for (unsigned i = 2; i < ima_arr(p).nelements() - 2; ++i)
+ {
+ accu_med.init();
+ accu_med.take(ima_arr(p)[i - 2]);
+ accu_med.take(ima_arr(p)[i - 1]);
+ accu_med.take(ima_arr(p)[i]);
+ accu_med.take(ima_arr(p)[i + 1]);
+ accu_med.take(ima_arr(p)[i + 2]);
+ ima_median5(p).append(accu_med.to_result());
+ }
+ ima_median5(p).append(ima_arr(p)[ima_arr(p).nelements() - 2]);
+ ima_median5(p).append(ima_arr(p)[ima_arr(p).nelements() - 1]);
+ }
+
+ /////////////
+ // //
+ // Outputs //
+ // //
+ /////////////
+ io::plot::save(ima_median3(point2d(160, 120)), "median3_tumeur.plot");
+ io::plot::save(ima_median3(point2d(34, 94)), "median3_air.plot");
+ io::plot::save(ima_median3(point2d(122, 115)), "median3_poumon.plot");
+ io::plot::save(ima_median5(point2d(160, 120)), "median5_tumeur.plot");
+ io::plot::save(ima_median5(point2d(34, 94)), "median5_air.plot");
+ io::plot::save(ima_median5(point2d(122, 115)), "median5_poumon.plot");
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/time_smooth/morpho.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/time_smooth/morpho.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/time_smooth/morpho.cc (revision 3594)
@@ -0,0 +1,102 @@
+#include <mln/core/image/image1d.hh>
+#include <mln/core/alias/neighb1d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/core/image/cast_image.hh>
+#include <mln/core/image/slice_image.hh>
+#include <mln/core/routine/duplicate.hh>
+
+#include <mln/value/int_u12.hh>
+
+#include <mln/io/dicom/load.hh>
+#include <mln/io/plot/save.hh>
+
+#include <mln/accu/median_h.hh>
+#include <mln/convert/from_to.hh>
+#include <mln/morpho/closing/area.hh>
+#include <mln/morpho/opening/area.hh>
+#include <mln/util/array.hh>
+
+/*#include <mln/draw/line.hh>
+#include <mln/io/magick/save.hh>
+#include <mln/level/convert.hh>
+#include <mln/level/stretch.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/literal/all.hh>
+using mln::value::rgb8;
+using mln::value::int_u8;*/
+
+
+using namespace mln;
+using value::int_u12;
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << "input" << std::endl;
+ return 1;
+ }
+
+ ///////////////////
+ // //
+ // Image loading //
+ // //
+ ///////////////////
+ image3d<int_u12> input;
+ io::dicom::load(input, argv[1]);
+ image2d<util::array<int_u12> > ima_arr(input.nrows(), input.ncols());
+ for (int i = 0; i < input.nslices(); ++i)
+ {
+ image2d<int_u12> tmp_slice = duplicate(slice(input, i));
+ mln_piter_(image2d<int_u12>) p(tmp_slice.domain());
+ for_all(p)
+ {
+ ima_arr(p).append(tmp_slice(p));
+ }
+ }
+
+ ////////////
+ // //
+ // Morpho //
+ // //
+ ////////////
+ image2d<image1d<int_u12> > ima_morpho;
+ initialize(ima_morpho, ima_arr);
+ mln_piter_(image2d<int_u12>) p(ima_morpho.domain());
+ accu::median_h<int_u12> accu_med;
+ for_all(p)
+ {
+ image1d<int_u12> tmp_ima;
+ convert::from_to(ima_arr(p), tmp_ima);
+ tmp_ima = morpho::closing::area(tmp_ima, c2(), 3);
+ tmp_ima = morpho::opening::area(tmp_ima, c2(), 3);
+ ima_morpho(p) = tmp_ima;
+ }
+
+ /////////////
+ // //
+ // Outputs //
+ // //
+ /////////////
+ /*image2d<rgb8> ima_color = level::convert(rgb8(), level::stretch(int_u8(), slice(input, 0)));
+ algebra::vec<2, unsigned int> vmin;
+ algebra::vec<2, unsigned int> vmax;
+ vmin[0] = 160;
+ vmin[1] = 120;
+ vmax[0] = 122;
+ vmax[1] = 115;
+ mln_site_(image2d<bool>) pbeg(vmin);
+ mln_site_(image2d<bool>) pend(vmax);
+ draw::line(ima_color, pbeg, pend, literal::red);
+ io::magick::save(ima_color, "test.png");*/
+
+ io::plot::save(ima_morpho(point2d(160, 120)), "morpho_tumeur.plot");
+ io::plot::save(ima_morpho(point2d(34, 94)), "morpho_air.plot");
+ io::plot::save(ima_morpho(point2d(122, 115)), "morpho_poumon.plot");
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/time_smooth/Makefile
===================================================================
--- trunk/milena/sandbox/fabien/igr/time_smooth/Makefile (revision 0)
+++ trunk/milena/sandbox/fabien/igr/time_smooth/Makefile (revision 3594)
@@ -0,0 +1,15 @@
+include ../Makefile.rules
+
+
+linear: linear.cc
+ ${CXX} -I../../../../ ${DICOM} ${CXXFLAGS} $^ -o linear
+
+median: median.cc
+ ${CXX} -I../../../../ ${DICOM} ${CXXFLAGS} $^ -o median
+
+morpho: morpho.cc
+ ${CXX} -I../../../../ ${DICOM} ${MAGICK} ${CXXFLAGS} $^ -o morpho
+
+clean:
+ rm -rf *.dump *.p?m *.plot *.log *.csv *.dSYM
+ rm linear median morpho
Index: trunk/milena/sandbox/fabien/igr/time_smooth/linear.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/time_smooth/linear.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/time_smooth/linear.cc (revision 3594)
@@ -0,0 +1,77 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/core/image/cast_image.hh>
+#include <mln/core/image/slice_image.hh>
+#include <mln/core/routine/duplicate.hh>
+
+#include <mln/value/int_u12.hh>
+
+#include <mln/io/dicom/load.hh>
+#include <mln/io/plot/save.hh>
+
+#include <mln/accu/median_h.hh>
+#include <mln/util/array.hh>
+
+
+using namespace mln;
+using value::int_u12;
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << "input" << std::endl;
+ return 1;
+ }
+
+ ///////////////////
+ // //
+ // Image loading //
+ // //
+ ///////////////////
+ image3d<int_u12> input;
+ io::dicom::load(input, argv[1]);
+ image2d<util::array<int_u12> > ima_arr(input.nrows(), input.ncols());
+ for (int i = 0; i < input.nslices(); ++i)
+ {
+ image2d<int_u12> tmp_slice = duplicate(slice(input, i));
+ mln_piter_(image2d<int_u12>) p(tmp_slice.domain());
+ for_all(p)
+ {
+ ima_arr(p).append(tmp_slice(p));
+ }
+ }
+
+ ////////////////////////
+ // //
+ // Linear convolution //
+ // //
+ ////////////////////////
+ image2d<util::array<int_u12> > ima_linear;
+ initialize(ima_linear, ima_arr);
+ mln_piter_(image2d<int_u12>) p(ima_linear.domain());
+ accu::median<int_u12> accu_med;
+ for_all(p)
+ {
+ ima_linear(p).append(ima_arr(p)[0]);
+ for (unsigned i = 1; i < ima_arr(p).nelements() - 1; ++i)
+ ima_linear(p).append(0.25 * ima_arr(p)[i - 1] + 0.5 * ima_arr(p)[i] + 0.25 * ima_arr(p)[i + 1]);
+ ima_linear(p).append(ima_arr(p)[ima_arr(p).nelements() - 1]);
+ }
+
+ /////////////
+ // //
+ // Outputs //
+ // //
+ /////////////
+ io::plot::save(ima_arr(point2d(160, 120)), "ref_tumeur.plot");
+ io::plot::save(ima_linear(point2d(160, 120)), "linear_tumeur.plot");
+ io::plot::save(ima_arr(point2d(34, 94)), "ref_air.plot");
+ io::plot::save(ima_linear(point2d(34, 94)), "linear_air.plot");
+ io::plot::save(ima_arr(point2d(122, 115)), "ref_poumon.plot");
+ io::plot::save(ima_linear(point2d(122, 115)), "linear_poumon.plot");
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/Makefile.rules
===================================================================
--- trunk/milena/sandbox/fabien/igr/Makefile.rules (revision 0)
+++ trunk/milena/sandbox/fabien/igr/Makefile.rules (revision 3594)
@@ -0,0 +1,9 @@
+CXX = llvm-g++
+CXXFLAGS = -DNDEBUG -O4
+
+DICOM_INC = -I/usr/local/include/gdcm-2.0
+DICOM_LIBS = -lgdcmCommon -lgdcmDICT -lgdcmDSED -lgdcmIOD -lgdcmMSFF -lgdcmexpat -lgdcmjpeg12 -lgdcmjpeg16 -lgdcmjpeg8 -lgdcmopenjpeg -lgdcmuuid -lgdcmzlib \
+ -framework CoreFoundation
+DICOM = ${DICOM_INC} ${DICOM_LIBS}
+
+MAGICK = `Magick++-config --cppflags --ldflags --libs`
1
0
* mln/core/concept/image.hh: Add an invalid operator= in order to
avoid wrong assignment. See sandbox/bug/concept_and_assignment.cc.
---
milena/ChangeLog | 7 +++++++
milena/mln/core/concept/image.hh | 19 ++++++++++++++++++-
2 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 3ece40a..8753025 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,12 @@
2009-03-30 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Avoid invalid assigments with image concept.
+
+ * mln/core/concept/image.hh: Add an invalid operator= in order to
+ avoid wrong assignment. See sandbox/bug/concept_and_assignment.cc.
+
+2009-03-30 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add math::sin and math::pi.
* mln/math/all.hh: add new includes.
diff --git a/milena/mln/core/concept/image.hh b/milena/mln/core/concept/image.hh
index e2bc4f8..6b23192 100644
--- a/milena/mln/core/concept/image.hh
+++ b/milena/mln/core/concept/image.hh
@@ -43,6 +43,7 @@
# include <mln/trait/concrete.hh> // FIXME: Should be in all.hh!
# include <mln/trait/images.hh>
+# include <mln/metal/abort.hh>
# include <mln/metal/is_a.hh>
# include <mln/metal/equal.hh>
@@ -73,6 +74,9 @@ namespace mln
{
typedef Image<void> category;
+ template <typename J>
+ Image<E>& operator=(const J& rhs);
+
/*
// provided by internal::image_base:
@@ -110,7 +114,6 @@ namespace mln
};
-
namespace convert
{
@@ -176,6 +179,20 @@ namespace mln
} // end of namespace mln::internal
+ template <typename E>
+ template <typename J>
+ inline
+ Image<E>&
+ Image<E>::operator=(const J&)
+ {
+ /// You are assigning an image of a concrete type to
+ /// an image with a concept type. It does NOT work.
+ ///
+ /// You forgot a call to exact() on the left operand!
+ mlc_abort(E)::check();
+ return *this;
+ }
+
template <typename E>
inline
--
1.5.6.5
1
0
* mln/math/all.hh: add new includes.
* mln/math/pi.hh: add constant.
* mln/math/sin.hh: Add math::sin().
---
milena/ChangeLog | 10 +++++++
milena/mln/math/all.hh | 11 ++++---
milena/mln/math/{all.hh => pi.hh} | 38 ++++++++++------------------
milena/mln/math/{all.hh => sin.hh} | 48 +++++++++++++++++++----------------
4 files changed, 56 insertions(+), 51 deletions(-)
copy milena/mln/math/{all.hh => pi.hh} (67%)
copy milena/mln/math/{all.hh => sin.hh} (68%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index bd1f274..3ece40a 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,13 @@
+2009-03-30 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Add math::sin and math::pi.
+
+ * mln/math/all.hh: add new includes.
+
+ * mln/math/pi.hh: add constant.
+
+ * mln/math/sin.hh: Add math::sin().
+
2009-03-30 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Add a plot format save() routine.
diff --git a/milena/mln/math/all.hh b/milena/mln/math/all.hh
index ce8b3b2..60d528c 100644
--- a/milena/mln/math/all.hh
+++ b/milena/mln/math/all.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,10 +28,9 @@
#ifndef MLN_MATH_ALL_HH
# define MLN_MATH_ALL_HH
-/*! \file mln/math/all.hh
- *
- * \brief File that includes all mathematical routines.
- */
+/// \file mln/math/all.hh
+///
+/// File that includes all mathematical routines.
namespace mln
@@ -49,7 +48,9 @@ namespace mln
# include <mln/math/max.hh>
# include <mln/math/min.hh>
# include <mln/math/round.hh>
+# include <mln/math/pi.hh>
# include <mln/math/sign.hh>
+# include <mln/math/sin.hh>
# include <mln/math/sqr.hh>
# include <mln/math/sqrt.hh>
# include <mln/math/cos.hh>
diff --git a/milena/mln/math/all.hh b/milena/mln/math/pi.hh
similarity index 67%
copy from milena/mln/math/all.hh
copy to milena/mln/math/pi.hh
index ce8b3b2..08f6d07 100644
--- a/milena/mln/math/all.hh
+++ b/milena/mln/math/pi.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// Copyright (C) 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
@@ -25,36 +26,25 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_MATH_ALL_HH
-# define MLN_MATH_ALL_HH
-
-/*! \file mln/math/all.hh
- *
- * \brief File that includes all mathematical routines.
- */
-
+#ifndef MLN_MATH_PI_HH
+# define MLN_MATH_PI_HH
namespace mln
{
- /// Namespace of mathematical routines.
- namespace math {}
+ namespace math
+ {
+
+ extern const double pi;
-}
+# ifndef MLN_INCLUDE_ONLY
+ const double pi = 3.1415926535;
-# include <mln/math/abs.hh>
-# include <mln/math/diff_abs.hh>
-# include <mln/math/jacobi.hh>
-# include <mln/math/max.hh>
-# include <mln/math/min.hh>
-# include <mln/math/round.hh>
-# include <mln/math/sign.hh>
-# include <mln/math/sqr.hh>
-# include <mln/math/sqrt.hh>
-# include <mln/math/cos.hh>
-# include <mln/math/acos.hh>
+# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace mln::math
+} // end of namespace mln
-#endif // ! MLN_MATH_ALL_HH
+#endif // ! MLN_MATH_PI_HH
diff --git a/milena/mln/math/all.hh b/milena/mln/math/sin.hh
similarity index 68%
copy from milena/mln/math/all.hh
copy to milena/mln/math/sin.hh
index ce8b3b2..b39ee08 100644
--- a/milena/mln/math/all.hh
+++ b/milena/mln/math/sin.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2009 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,36 +25,40 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_MATH_ALL_HH
-# define MLN_MATH_ALL_HH
+#ifndef MLN_MATH_SIN_HH
+# define MLN_MATH_SIN_HH
-/*! \file mln/math/all.hh
- *
- * \brief File that includes all mathematical routines.
- */
+/// \file mln/math/sin.hh
+///
+/// Define the sininus (sin) routine.
+
+# include <cmath>
namespace mln
{
- /// Namespace of mathematical routines.
- namespace math {}
+ namespace math
+ {
+
+ template <typename T>
+ T sin(const T& v);
+
+
+# ifndef MLN_INCLUDE_ONLY
-}
+ template <typename T>
+ inline
+ T sin(const T& v)
+ {
+ return std::sin(v);
+ }
+# endif // ! MLN_INCLUDE_ONLY
-# include <mln/math/abs.hh>
-# include <mln/math/diff_abs.hh>
-# include <mln/math/jacobi.hh>
-# include <mln/math/max.hh>
-# include <mln/math/min.hh>
-# include <mln/math/round.hh>
-# include <mln/math/sign.hh>
-# include <mln/math/sqr.hh>
-# include <mln/math/sqrt.hh>
-# include <mln/math/cos.hh>
-# include <mln/math/acos.hh>
+ } // end of namespace mln::math
+} // end of namespace mln
-#endif // ! MLN_MATH_ALL_HH
+#endif // ! MLN_MATH_SIN_HH
--
1.5.6.5
1
0
* scribo/all.hh,
* scribo/core/all.hh,
* scribo/debug/all.hh,
* scribo/deskew/all.hh,
* scribo/draw/all.hh,
* scribo/filter/all.hh,
* scribo/make/all.hh,
* scribo/table/all.hh,
* scribo/text/all.hh,
* scribo/table/internal/all.hh,
* scribo/text/grouping/all.hh,
* scribo/text/grouping/internal/all.hh,
* scribo/util/all.hh: Add 'all' includes.
* scribo/debug/save_linked_textbboxes_image.hh,
* scribo/draw/bounding_box_links.hh,
* scribo/filter/large_components.hh,
* scribo/filter/small_components.hh,
* scribo/filter/thick_bboxes.hh,
* scribo/filter/thin_bboxes.hh,
* scribo/make/text.hh,
* scribo/src/photo_basic.cc,
* scribo/src/table_rebuild_rank.cc,
* scribo/table/align_lines_horizontaly.hh,
* scribo/table/align_lines_verticaly.hh,
* scribo/table/connect_horizontal_lines.hh,
* scribo/table/connect_vertical_lines.hh,
* scribo/table/erase.hh,
* scribo/table/extract_lines_with_opening.hh,
* scribo/table/extract_lines_with_rank.hh,
* scribo/table/internal/align_lines.hh,
* scribo/table/rebuild.hh,
* scribo/table/repair_horizontal_lines.hh,
* scribo/table/repair_vertical_lines.hh,
* scribo/text/extract_bboxes.hh,
* scribo/text/extract_lines.hh,
* scribo/text/grouping/group_from_double_link.hh,
* scribo/text/grouping/group_from_graph.hh,
* scribo/text/grouping/group_from_single_link.hh,
* scribo/text/grouping/group_with_graph.hh,
* scribo/text/grouping/internal/find_graph_link.hh,
* scribo/text/grouping/internal/find_left_link.hh,
* scribo/text/grouping/internal/find_right_link.hh,
* scribo/text/grouping/internal/is_link_valid.hh,
* scribo/text/recognition.hh,
* scribo/util/text.hh: Update doc.
---
milena/sandbox/ChangeLog | 51 ++++++
milena/sandbox/scribo/all.hh | 52 ++++++
milena/sandbox/scribo/core/all.hh | 51 ++++++
milena/sandbox/scribo/debug/all.hh | 51 ++++++
.../scribo/debug/save_linked_textbboxes_image.hh | 41 +++++-
milena/sandbox/scribo/deskew/all.hh | 48 ++++++
milena/sandbox/scribo/draw/all.hh | 49 ++++++
milena/sandbox/scribo/draw/bounding_box_links.hh | 165 ++++++++++----------
milena/sandbox/scribo/filter/all.hh | 51 ++++++
milena/sandbox/scribo/filter/large_components.hh | 27 +++-
milena/sandbox/scribo/filter/small_components.hh | 33 +++--
milena/sandbox/scribo/filter/thick_bboxes.hh | 45 +++++-
milena/sandbox/scribo/filter/thin_bboxes.hh | 43 +++++-
milena/sandbox/scribo/make/all.hh | 51 ++++++
milena/sandbox/scribo/make/text.hh | 33 +++--
milena/sandbox/scribo/src/photo_basic.cc | 4 +-
milena/sandbox/scribo/src/table_rebuild_rank.cc | 14 ++-
.../scribo/table/align_lines_horizontaly.hh | 8 +-
.../sandbox/scribo/table/align_lines_verticaly.hh | 8 +-
milena/sandbox/scribo/table/all.hh | 59 +++++++
.../scribo/table/connect_horizontal_lines.hh | 18 ++-
.../sandbox/scribo/table/connect_vertical_lines.hh | 10 +-
milena/sandbox/scribo/table/erase.hh | 20 ++--
.../scribo/table/extract_lines_with_opening.hh | 20 ++-
.../scribo/table/extract_lines_with_rank.hh | 21 ++-
.../sandbox/scribo/table/internal/align_lines.hh | 28 ++--
milena/sandbox/scribo/table/internal/all.hh | 57 +++++++
milena/sandbox/scribo/table/rebuild.hh | 62 +++++---
.../scribo/table/repair_horizontal_lines.hh | 10 +-
.../sandbox/scribo/table/repair_vertical_lines.hh | 10 +-
milena/sandbox/scribo/text/all.hh | 51 ++++++
milena/sandbox/scribo/text/extract_bboxes.hh | 13 +-
milena/sandbox/scribo/text/extract_lines.hh | 10 +-
milena/sandbox/scribo/text/grouping/all.hh | 64 ++++++++
.../scribo/text/grouping/group_from_double_link.hh | 23 ++-
.../scribo/text/grouping/group_from_graph.hh | 26 +++-
.../scribo/text/grouping/group_from_single_link.hh | 11 +-
.../scribo/text/grouping/group_with_graph.hh | 10 +-
.../{group_with_graph.hh => internal/all.hh} | 73 +++-------
.../text/grouping/internal/find_graph_link.hh | 10 +-
.../text/grouping/internal/find_left_link.hh | 15 +-
.../text/grouping/internal/find_right_link.hh | 15 +-
.../is_link_valid.hh} | 73 ++++-----
milena/sandbox/scribo/text/recognition.hh | 89 +++++------
milena/sandbox/scribo/util/all.hh | 48 ++++++
milena/sandbox/scribo/util/text.hh | 35 ++++-
46 files changed, 1319 insertions(+), 387 deletions(-)
create mode 100644 milena/sandbox/scribo/all.hh
create mode 100644 milena/sandbox/scribo/core/all.hh
create mode 100644 milena/sandbox/scribo/debug/all.hh
create mode 100644 milena/sandbox/scribo/deskew/all.hh
create mode 100644 milena/sandbox/scribo/draw/all.hh
create mode 100644 milena/sandbox/scribo/filter/all.hh
create mode 100644 milena/sandbox/scribo/make/all.hh
create mode 100644 milena/sandbox/scribo/table/all.hh
create mode 100644 milena/sandbox/scribo/table/internal/all.hh
create mode 100644 milena/sandbox/scribo/text/all.hh
create mode 100644 milena/sandbox/scribo/text/grouping/all.hh
copy milena/sandbox/scribo/text/grouping/{group_with_graph.hh => internal/all.hh} (54%)
copy milena/sandbox/scribo/text/grouping/{group_with_graph.hh => internal/is_link_valid.hh} (53%)
create mode 100644 milena/sandbox/scribo/util/all.hh
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 881982d..82b2cbc 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,3 +1,54 @@
+2009-03-30 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Update Scribo's code.
+
+ * scribo/all.hh,
+ * scribo/core/all.hh,
+ * scribo/debug/all.hh,
+ * scribo/deskew/all.hh,
+ * scribo/draw/all.hh,
+ * scribo/filter/all.hh,
+ * scribo/make/all.hh,
+ * scribo/table/all.hh,
+ * scribo/text/all.hh,
+ * scribo/table/internal/all.hh,
+ * scribo/text/grouping/all.hh,
+ * scribo/text/grouping/internal/all.hh,
+ * scribo/util/all.hh: Add 'all' includes.
+
+ * scribo/debug/save_linked_textbboxes_image.hh,
+ * scribo/draw/bounding_box_links.hh,
+ * scribo/filter/large_components.hh,
+ * scribo/filter/small_components.hh,
+ * scribo/filter/thick_bboxes.hh,
+ * scribo/filter/thin_bboxes.hh,
+ * scribo/make/text.hh,
+ * scribo/src/photo_basic.cc,
+ * scribo/src/table_rebuild_rank.cc,
+ * scribo/table/align_lines_horizontaly.hh,
+ * scribo/table/align_lines_verticaly.hh,
+ * scribo/table/connect_horizontal_lines.hh,
+ * scribo/table/connect_vertical_lines.hh,
+ * scribo/table/erase.hh,
+ * scribo/table/extract_lines_with_opening.hh,
+ * scribo/table/extract_lines_with_rank.hh,
+ * scribo/table/internal/align_lines.hh,
+ * scribo/table/rebuild.hh,
+ * scribo/table/repair_horizontal_lines.hh,
+ * scribo/table/repair_vertical_lines.hh,
+ * scribo/text/extract_bboxes.hh,
+ * scribo/text/extract_lines.hh,
+ * scribo/text/grouping/group_from_double_link.hh,
+ * scribo/text/grouping/group_from_graph.hh,
+ * scribo/text/grouping/group_from_single_link.hh,
+ * scribo/text/grouping/group_with_graph.hh,
+ * scribo/text/grouping/internal/find_graph_link.hh,
+ * scribo/text/grouping/internal/find_left_link.hh,
+ * scribo/text/grouping/internal/find_right_link.hh,
+ * scribo/text/grouping/internal/is_link_valid.hh,
+ * scribo/text/recognition.hh,
+ * scribo/util/text.hh: Update doc.
+
2009-03-30 Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Write a solution for a common mistake.
diff --git a/milena/sandbox/scribo/all.hh b/milena/sandbox/scribo/all.hh
new file mode 100644
index 0000000..80c4bbf
--- /dev/null
+++ b/milena/sandbox/scribo/all.hh
@@ -0,0 +1,52 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_ALL_HH
+# define SCRIBO_ALL_HH
+
+/// \file scribo/all.hh
+///
+/// Include all headers located in scribo/.
+
+
+/// Namespace of the whole project.
+namespace scribo
+{
+
+} // end of namespace scribo
+
+# include <scribo/draw/all.hh>
+# include <scribo/table/all.hh>
+# include <scribo/util/all.hh>
+# include <scribo/filter/all.hh>
+# include <scribo/make/all.hh>
+# include <scribo/text/all.hh>
+# include <scribo/core/all.hh>
+# include <scribo/debug/all.hh>
+# include <scribo/deskew/all.hh>
+
+#endif // ! SCRIBO_ALL_HH
diff --git a/milena/sandbox/scribo/core/all.hh b/milena/sandbox/scribo/core/all.hh
new file mode 100644
index 0000000..f2ae0d6
--- /dev/null
+++ b/milena/sandbox/scribo/core/all.hh
@@ -0,0 +1,51 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_CORE_ALL_HH
+# define SCRIBO_CORE_ALL_HH
+
+/// \file scribo/core/all.hh
+///
+/// Include all headers located in scribo/core.
+
+namespace scribo
+{
+
+ /// Namespace of core routines.
+ namespace core
+ {
+
+ } // end of namespace scribo::core
+
+} // end of namespace scribo
+
+#include <scribo/core/component_bboxes.hh>
+#include <scribo/core/macros.hh>
+#include <scribo/core/central_sites.hh>
+#include <scribo/core/erase_bboxes.hh>
+
+#endif // ! SCRIBO_CORE_ALL_HH
diff --git a/milena/sandbox/scribo/debug/all.hh b/milena/sandbox/scribo/debug/all.hh
new file mode 100644
index 0000000..1af548d
--- /dev/null
+++ b/milena/sandbox/scribo/debug/all.hh
@@ -0,0 +1,51 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_DEBUG_ALL_HH
+# define SCRIBO_DEBUG_ALL_HH
+
+/// \file scribo/debug/all.hh
+///
+/// Include all headers located in scribo/debug.
+
+namespace scribo
+{
+
+ /// Namespace of debug routines.
+ namespace debug
+ {
+
+ } // end of namespace scribo::debug
+
+} // end of namespace scribo
+
+# include <scribo/debug/save_label_image.hh>
+# include <scribo/debug/save_linked_textbboxes_image.hh>
+# include <scribo/debug/save_table_image.hh>
+# include <scribo/debug/save_textbboxes_image.hh>
+
+#endif // ! SCRIBO_DEBUG_ALL_HH
diff --git a/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh b/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh
index 1b53262..32c31b8 100644
--- a/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh
+++ b/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh
@@ -56,7 +56,14 @@ namespace scribo
using namespace mln;
- /// Save the bounding box links image.
+ /// Save the line of text links image.
+ ///
+ /// \param[in,out] input The binary from where the text is extracted.
+ /// \param[in] text The lines of text.
+ /// \param[in] link_array Lines of text links.
+ /// \param[in] box_value Value used to draw line bounding boxes.
+ /// \param[in] link_value Value used to draw line links.
+ /// \param[in] filename The target file name.
template <typename I, typename L>
void
save_linked_textbboxes_image(const Image<I>& input,
@@ -66,17 +73,37 @@ namespace scribo
const value::rgb8& link_value,
const std::string& filename);
-
+ /// Save the line of text left and right links image.
+ ///
+ /// \param[in,out] input The binary from where the text is extracted.
+ /// \param[in] text The lines of text.
+ /// \param[in] left_link Lines of text left links.
+ /// \param[in] right_link Lines of text right links.
+ /// \param[in] box_value Value used to draw line bounding boxes.
+ /// \param[in] link_value Value used to draw line links.
+ /// \param[in] filename The target file name.
template <typename I, typename L>
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_array,
+ const mln::util::array<unsigned>& right_link,
const value::rgb8& box_value,
const value::rgb8& link_value,
const std::string& filename);
+ /// Save the line of text left and right links image.
+ /// Draw also validated links.
+ ///
+ /// \param[in,out] input The binary from where the text is extracted.
+ /// \param[in] text The lines of text.
+ /// \param[in] left_link Lines of text left links.
+ /// \param[in] right_link Lines of text right links.
+ /// \param[in] box_value Value used to draw line bounding boxes.
+ /// \param[in] left_link_value Value used to draw line left links.
+ /// \param[in] right_link_value Value used to draw line left links.
+ /// \param[in] validated_link_value Value used to draw line validated links.
+ /// \param[in] filename The target file name.
template <typename I, typename L>
inline
void
@@ -91,6 +118,14 @@ namespace scribo
const std::string& filename);
+ /// Save the line link graph image.
+ ///
+ /// \param[in,out] input The binary from where the text is extracted.
+ /// \param[in] text The lines of text.
+ /// \param[in] g The link graph.
+ /// \param[in] box_value Value used to draw line bounding boxes.
+ /// \param[in] link_value Value used to draw line links.
+ /// \param[in] filename The target file name.
template <typename I, typename L, typename G>
void
save_linked_textbboxes_image(const Image<I>& input,
diff --git a/milena/sandbox/scribo/deskew/all.hh b/milena/sandbox/scribo/deskew/all.hh
new file mode 100644
index 0000000..8e15e9c
--- /dev/null
+++ b/milena/sandbox/scribo/deskew/all.hh
@@ -0,0 +1,48 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_DESKEW_ALL_HH
+# define SCRIBO_DESKEW_ALL_HH
+
+/// \file scribo/deskew/all.hh
+///
+/// Include all headers located in scribo/deskew.
+
+namespace scribo
+{
+
+ /// Namespace of deskew routines.
+ namespace deskew
+ {
+
+ } // end of namespace scribo::deskew
+
+} // end of namespace scribo
+
+# include <scribo/deskew/hough.hh>
+
+#endif // ! SCRIBO_DESKEW_ALL_HH
diff --git a/milena/sandbox/scribo/draw/all.hh b/milena/sandbox/scribo/draw/all.hh
new file mode 100644
index 0000000..961fd78
--- /dev/null
+++ b/milena/sandbox/scribo/draw/all.hh
@@ -0,0 +1,49 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_DRAW_ALL_HH
+# define SCRIBO_DRAW_ALL_HH
+
+/// \file scribo/draw/all.hh
+///
+/// Include all headers located in scribo/draw.
+
+namespace scribo
+{
+
+ /// Namespace of drawing routines.
+ namespace draw
+ {
+
+ } // end of namespace scribo::draw
+
+} // end of namespace scribo
+
+# include <scribo/draw/bounding_boxes.hh>
+# include <scribo/draw/bounding_box_links.hh>
+
+#endif // ! SCRIBO_DRAW_ALL_HH
diff --git a/milena/sandbox/scribo/draw/bounding_box_links.hh b/milena/sandbox/scribo/draw/bounding_box_links.hh
index b7f410a..9230ba0 100644
--- a/milena/sandbox/scribo/draw/bounding_box_links.hh
+++ b/milena/sandbox/scribo/draw/bounding_box_links.hh
@@ -39,6 +39,7 @@
# include <mln/canvas/browsing/depth_first_search.hh>
# include <scribo/core/macros.hh>
+# include <scribo/text/grouping/internal/is_link_valid.hh>
namespace scribo
{
@@ -48,7 +49,13 @@ namespace scribo
using namespace mln;
- /// Draw a list of bounding box links.
+ /// Draw a list of bounding box links. Draw links from the bounding
+ /// box centers.
+ ///
+ /// \param[in,out] input_ An image where to draw.
+ /// \param[in] bboxes Bounding boxes.
+ /// \param[in] link_array Bounding box links.
+ /// \param[in] value Value used to draw links.
template <typename I>
void
bounding_box_links(Image<I>& input_,
@@ -56,6 +63,13 @@ namespace scribo
const mln::util::array<unsigned>& link_array,
const mln_value(I)& value);
+
+ /// Draw a list of bounding box links from their mass centers.
+ ///
+ /// \param[in,out] input_ An image where to draw.
+ /// \param[in] mass_centers Bounding boxes mass centers.
+ /// \param[in] link_array Bounding box links.
+ /// \param[in] value Value used to draw links.
template <typename I>
inline
void
@@ -64,23 +78,17 @@ namespace scribo
const mln::util::array<unsigned>& link_array,
const mln_value(I)& value);
- template <typename I>
- 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)& 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);
+ /// Draw left, right and validated lists of bounding box links.
+ /// Draw from the bounding box centers.
+ ///
+ /// \param[in,out] input_ An image where to draw.
+ /// \param[in] bboxes Bounding boxes.
+ /// \param[in] left_link Bounding box left links.
+ /// \param[in] right_link Bounding box right links.
+ /// \param[in] left_link_value Value used to draw left links.
+ /// \param[in] right_link_value Value used to draw right links.
+ /// \param[in] validated_link_value Value used to draw validated links.
template <typename I>
inline
void
@@ -92,6 +100,17 @@ namespace scribo
const mln_value(I)& right_link_value,
const mln_value(I)& validated_link_value);
+
+ /// Draw left, right and validated lists of bounding box links.
+ /// Draw from the bounding box mass centers.
+ ///
+ /// \param[in,out] input_ An image where to draw.
+ /// \param[in] mass_centers Bounding box mass centers.
+ /// \param[in] left_link Bounding box left links.
+ /// \param[in] right_link Bounding box right links.
+ /// \param[in] left_link_value Value used to draw left links.
+ /// \param[in] right_link_value Value used to draw right links.
+ /// \param[in] validated_link_value Value used to draw validated links.
template <typename I>
inline
void
@@ -103,12 +122,20 @@ namespace scribo
const mln_value(I)& right_link_value,
const mln_value(I)& validated_link_value);
+
+ /// Draw a graph of bounding box links.
+ /// Draw from bounding box centers.
+ ///
+ /// \param[in,out] input_ An image where to draw.
+ /// \param[in] bboxes Bounding boxes.
+ /// \param[in] g_ The link graph.
+ /// \param[in] link_value The value used to draw the links.
template <typename I, typename G>
inline
void
- bounding_box_links(Image<I>& input,
+ bounding_box_links(Image<I>& input_,
const mln::util::array< box<mln_site(I)> >& bboxes,
- const Graph<G>& g,
+ const Graph<G>& g_,
const mln_value(I)& link_value);
@@ -117,31 +144,47 @@ namespace scribo
namespace internal
{
+
+ /// Draw a link graph in an image.
/// Functor to be passed to depth_first_search.
template <typename I>
struct draw_graph_edges_functor
{
+ /// Constructor
+ ///
+ /// \param[in,out] ima The image where to draw.
+ /// \param[in] textbboxes The line of text bounding boxes.
+ /// \param[in] value The value used to draw the links.
draw_graph_edges_functor(I& ima,
const mln::util::array<box<mln_site(I)> >& textbboxes,
const mln_value(I)& value)
: ima_(ima), textbboxes_(textbboxes), value_(value)
{}
+ /// Initialize the functor.
+ ///
+ /// \param[in] g The graph this functor will work on.
template <typename G>
void
init(const Graph<G>& g)
{ deja_vu.resize(exact(g).v_nmax(), false); }
+ /// All components/vertices have been treated.
void final()
{}
+ /// Starting to process a new component.
void next_component()
{}
+ /// A new component have been found through the vertex with
+ /// the given id.
void new_component_from_vertex(unsigned)
{}
+
+ /// A new vertex neighbor have been found and will be treated.
void added_to_queue(unsigned id)
{
deja_vu[id] = true;
@@ -149,19 +192,31 @@ namespace scribo
textbboxes_[id].center(), value_);
}
+ /// Treating a new vertex.
void process_vertex(unsigned id)
{ current_vertex = id; }
+ /// Does this vertex with id \p id have to be treated?
bool to_be_treated(unsigned id)
{ return ! deja_vu[id]; }
+ /// Does this vertex neighbor have to be treated?
bool to_be_queued(unsigned id)
{ return to_be_treated(id); }
+ /// The image where to draw.
I& ima_;
+
+ /// Line of text bounding boxes.
const mln::util::array<box<mln_site(I)> >& textbboxes_;
+
+ /// Value to be used to draw links.
mln_value(I) value_;
+
+ /// Current vertex being processed.
unsigned current_vertex;
+
+ /// Store whether a vertex has been already seen or not.
std::vector<bool> deja_vu;
};
@@ -224,62 +279,6 @@ namespace scribo
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)& value)
- {
- trace::entering("scribo::draw::bounding_box_links");
-
- 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");
-
- 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,
@@ -308,11 +307,13 @@ namespace scribo
mass_centers[right_link[i]] + dright,
right_link_value);
- unsigned nbh = right_link[left_link[i]];
- if (nbh == i && left_link[i] != i)
+ mln::util::couple<bool, unsigned>
+ nbh = text::grouping::internal::is_link_valid(left_link, right_link, i);
+
+ if (nbh.first())
mln::draw::line(input,
mass_centers[i],
- mass_centers[left_link[i]],
+ mass_centers[nbh.second()],
validated_link_value);
input(mass_centers[i]) = validated_link_value;
@@ -353,11 +354,13 @@ namespace scribo
bboxes[right_link[i]].center() + dright,
right_link_value);
- unsigned nbh = right_link[left_link[i]];
- if (nbh == i && left_link[i] != i)
+ mln::util::couple<bool, unsigned>
+ nbh = text::grouping::internal::is_link_valid(left_link, right_link, i);
+
+ if (nbh.first())
mln::draw::line(input,
bboxes[i].center(),
- bboxes[left_link[i]].center(),
+ bboxes[nbh.second()].center(),
validated_link_value);
}
diff --git a/milena/sandbox/scribo/filter/all.hh b/milena/sandbox/scribo/filter/all.hh
new file mode 100644
index 0000000..cd87b0d
--- /dev/null
+++ b/milena/sandbox/scribo/filter/all.hh
@@ -0,0 +1,51 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_FILTER_ALL_HH
+# define SCRIBO_FILTER_ALL_HH
+
+/// \file scribo/filter/all.hh
+///
+/// Include all headers located in scribo/filter.
+
+namespace scribo
+{
+
+ /// Namespace of filtering rountines.
+ namespace filter
+ {
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+# include <scribo/filter/thin_bboxes.hh>
+# include <scribo/filter/small_components.hh>
+# include <scribo/filter/large_components.hh>
+# include <scribo/filter/thick_bboxes.hh>
+
+#endif // ! SCRIBO_FILTER_ALL_HH
diff --git a/milena/sandbox/scribo/filter/large_components.hh b/milena/sandbox/scribo/filter/large_components.hh
index 7b4964b..814f4ed 100644
--- a/milena/sandbox/scribo/filter/large_components.hh
+++ b/milena/sandbox/scribo/filter/large_components.hh
@@ -78,7 +78,7 @@ namespace scribo
/// \return updated text data.
template <typename I>
scribo::util::text<I>
- small_components(const scribo::util::text<I>& text,
+ large_components(const scribo::util::text<I>& text,
unsigned min_size);
@@ -90,28 +90,39 @@ namespace scribo
{
- /// Filter Functor. Return false for all components which are too
- /// large.
+ /// Filter Functor.
+ /// Return false for all components which are too large.
template <typename R>
struct filter_large_components_functor
: Function_l2b< filter_large_components_functor<R> >
{
- filter_large_components_functor(const mln::util::array<R>& nsitecomp,
+
+ /// Constructor
+ ///
+ /// \param[in] compbboxes Component bounding boxes.
+ /// \param[in] max_size Maximum component size.
+ filter_large_components_functor(const mln::util::array<R>& compbboxes,
unsigned max_size)
- : nsitecomp_(nsitecomp), max_size_(max_size)
+ : compbboxes_(compbboxes), max_size_(max_size)
{
}
- /// Return false if the components area is strictly inferior to
+ /// Check if the component is large enough.
+ ///
+ /// \param l A label.
+ ///
+ /// \return false if the component area is strictly inferion to
/// \p max_size_.
bool operator()(const value::label_16& l) const
{
- return nsitecomp_[l] <= max_size_;
+ return compbboxes_[l] <= max_size_;
}
- const mln::util::array<R>& nsitecomp_;
+ /// The component bounding boxes.
+ const mln::util::array<R>& compbboxes_;
+ /// The maximum area.
unsigned max_size_;
};
diff --git a/milena/sandbox/scribo/filter/small_components.hh b/milena/sandbox/scribo/filter/small_components.hh
index 55ee9b1..7439ce5 100644
--- a/milena/sandbox/scribo/filter/small_components.hh
+++ b/milena/sandbox/scribo/filter/small_components.hh
@@ -81,7 +81,7 @@ namespace scribo
/// \param[in] text Text data.
/// \param[in] min_size The minimum cardinality of a component.
///
- /// \return updated text data.
+ /// \return Lines of text without too small components.
template <typename I>
scribo::util::text<I>
small_components(const scribo::util::text<I>& text,
@@ -95,28 +95,39 @@ namespace scribo
{
- /// Filter Functor. Return false for all components which are too
- /// small.
+ /// Filter Functor.
+ /// Return false for all components which are too small.
template <typename R>
struct filter_small_components_functor
: Function_l2b< filter_small_components_functor<R> >
{
- filter_small_components_functor(const mln::util::array<R>& nsitecomp,
+
+ /// Constructor
+ ///
+ /// \param[in] compbboxes Component bounding boxes.
+ /// \param[in] min_size Minimum component size.
+ filter_small_components_functor(const mln::util::array<R>& compbboxes,
unsigned min_size)
- : nsitecomp_(nsitecomp), min_size_(min_size)
+ : compbboxes_(compbboxes), min_size_(min_size)
{
}
- /// Return false if the components area is strictly inferior to
+ /// Check if the component is large enough.
+ ///
+ /// \param l A label.
+ ///
+ /// \return false if the component area is strictly inferion to
/// \p min_size_.
bool operator()(const value::label_16& l) const
{
- return nsitecomp_[l] >= min_size_;
+ return compbboxes_[l] >= min_size_;
}
+ /// The component bounding boxes.
+ const mln::util::array<R>& compbboxes_;
- const mln::util::array<R>& nsitecomp_;
+ /// The minimum area.
unsigned min_size_;
};
@@ -146,11 +157,11 @@ namespace scribo
typedef accu::count<mln_psite(I)> accu_count_t;
typedef mln_result(accu_count_t) accu_count_res_t;
- typedef mln::util::array<accu_count_res_t> nsitecomp_t;
- nsitecomp_t nsitecomp = labeling::compute(accu_count_t(), lbl, nlabels);
+ typedef mln::util::array<accu_count_res_t> compbboxes_t;
+ compbboxes_t compbboxes = labeling::compute(accu_count_t(), lbl, nlabels);
typedef internal::filter_small_components_functor<accu_count_res_t> func_t;
- func_t fl2b(nsitecomp, min_size);
+ func_t fl2b(compbboxes, min_size);
labeling::relabel_inplace(lbl, nlabels, fl2b);
mln_concrete(I) output = duplicate(input);
diff --git a/milena/sandbox/scribo/filter/thick_bboxes.hh b/milena/sandbox/scribo/filter/thick_bboxes.hh
index 006065b..ba097f8 100644
--- a/milena/sandbox/scribo/filter/thick_bboxes.hh
+++ b/milena/sandbox/scribo/filter/thick_bboxes.hh
@@ -44,18 +44,52 @@ namespace scribo
namespace filter
{
+ /// Remove components thicker or equal to \p max_thickness.
+ ///
+ /// \param[in] input_ A binary image.
+ /// \param[in] nbh_ A neighborhood used in labeling algorithms.
+ /// \param[in] label_type The label type used for labeling.
+ /// \param[in] max_thickness The maximum thickness value.
+ ///
+ /// \result A binary image without thick components.
+ template <typename I, typename N, typename V>
+ inline
+ mln_concrete(I)
+ thick_bboxes(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ const V& label_type,
+ unsigned max_thickness);
+
+
+ /// Remove lines of text thicker or equal to \p max_thickness.
+ ///
+ /// \param[in] text Lines of text.
+ /// \param[in] max_thickness The maximum thickness value.
+ ///
+ /// \result Lines of text without too thick lines.
+ template <typename L>
+ inline
+ scribo::util::text<L>
+ thick_bboxes(const scribo::util::text<L>& text,
+ unsigned max_thickness);
+
+
# ifndef MLN_INCLUDE_ONLY
namespace internal
{
-
/// Filter Functor. Return false for all components which are too
/// large.
template <typename R>
struct filter_too_thick_component_functor
: Function_l2b< filter_too_thick_component_functor<R> >
{
+
+ /// Constructor
+ ///
+ /// \param[in] compbboxes component bounding boxes.
+ /// \param[in] max_thickness the maximum thickness allowed.
filter_too_thick_component_functor(const mln::util::array<R>& compbboxes,
unsigned max_thickness)
: compbboxes_(compbboxes), max_thickness_(max_thickness)
@@ -63,8 +97,10 @@ namespace scribo
}
- /// Return false if the components is thickner than
+ /// Return false if the components is thicker than
/// \p max_thickness_.
+ ///
+ /// \param[in] l An image value.
bool operator()(const value::label_16& l) const
{
return compbboxes_[l].nrows() < max_thickness_
@@ -72,7 +108,10 @@ namespace scribo
}
+ /// Component bounding boxes.
const mln::util::array<R>& compbboxes_;
+
+ /// The maximum thickness.
unsigned max_thickness_;
};
@@ -120,7 +159,7 @@ namespace scribo
inline
scribo::util::text<L>
thick_bboxes(const scribo::util::text<L>& text,
- unsigned max_thickness)
+ unsigned max_thickness)
{
trace::entering("scribo::filter::thick_bboxes");
diff --git a/milena/sandbox/scribo/filter/thin_bboxes.hh b/milena/sandbox/scribo/filter/thin_bboxes.hh
index 30d7bb9..14aeec0 100644
--- a/milena/sandbox/scribo/filter/thin_bboxes.hh
+++ b/milena/sandbox/scribo/filter/thin_bboxes.hh
@@ -44,18 +44,52 @@ namespace scribo
namespace filter
{
+ /// Remove components thinner or equal to \p min_thickness.
+ ///
+ /// \param[in] input_ a binary image.
+ /// \param[in] nbh_ a neighborhood used in labeling algorithms.
+ /// \param[in] label_type the label type used for labeling.
+ /// \param[in] min_thickness the minimum thickness value.
+ ///
+ /// \result A binary image without thin components.
+ template <typename I, typename N, typename V>
+ inline
+ mln_concrete(I)
+ thin_bboxes(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ const V& label_type,
+ unsigned min_thickness);
+
+ /// Remove lines of text thinner or equal to \p min_thickness.
+ ///
+ /// \param[in] text lines of text.
+ /// \param[in] min_thickness the minimum thickness value.
+ ///
+ /// \result Lines of text without too thin lines.
+ template <typename L>
+ inline
+ scribo::util::text<L>
+ thin_bboxes(const scribo::util::text<L>& text,
+ unsigned min_thickness);
+
+
# ifndef MLN_INCLUDE_ONLY
namespace internal
{
- /// Filter Functor. Return false for all components which are too
- /// large.
+ /// Filter Functor.
+ /// Return false for all components which are too large.
template <typename R>
struct filter_too_thin_component_functor
: Function_l2b< filter_too_thin_component_functor<R> >
{
+
+ /// Constructor
+ ///
+ /// \param[in] compbboxes component bounding boxes.
+ /// \param[in] min_thickness the minimum thickness allowed.
filter_too_thin_component_functor(const mln::util::array<R>& compbboxes,
unsigned min_thickness)
: compbboxes_(compbboxes), min_thickness_(min_thickness)
@@ -65,6 +99,8 @@ namespace scribo
/// Return false if the components is thinner than
/// \p min_thickness_.
+ ///
+ /// \param[in] l An image value.
bool operator()(const value::label_16& l) const
{
return compbboxes_[l].nrows() > min_thickness_
@@ -72,7 +108,10 @@ namespace scribo
}
+ /// Component bounding boxes.
const mln::util::array<R>& compbboxes_;
+
+ /// The minimum thickness.
unsigned min_thickness_;
};
diff --git a/milena/sandbox/scribo/make/all.hh b/milena/sandbox/scribo/make/all.hh
new file mode 100644
index 0000000..aa62d05
--- /dev/null
+++ b/milena/sandbox/scribo/make/all.hh
@@ -0,0 +1,51 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_MAKE_ALL_HH
+# define SCRIBO_MAKE_ALL_HH
+
+/// \file scribo/make/all.hh
+///
+/// Include all headers located in scribo/make.
+
+namespace scribo
+{
+
+ /// Namespace of routines constructing objects.
+ namespace make
+ {
+
+ } // end of namespace scribo::make
+
+} // end of namespace scribo
+
+# include <scribo/make/influence_zone_graph.hh>
+# include <scribo/make/text.hh>
+# include <scribo/make/debug_filename.hh>
+
+
+#endif // ! SCRIBO_MAKE_ALL_HH
diff --git a/milena/sandbox/scribo/make/text.hh b/milena/sandbox/scribo/make/text.hh
index c4a8a09..b9e4776 100644
--- a/milena/sandbox/scribo/make/text.hh
+++ b/milena/sandbox/scribo/make/text.hh
@@ -48,13 +48,26 @@ namespace scribo
{
+ /// Construct a util::text
+ ///
+ /// \param[in] bboxes Text component bounding boxes.
+ /// \param[in] lbl Associated label image.
+ /// \param[in] nbboxes The number of bounding boxes.
+ ///
+ /// \return A util::text.
template <typename L>
scribo::util::text<L>
text(const mln::util::array<box<mln_site(L)> >& bboxes,
const Image<L>& lbl,
mln_value(L)& nbboxes);
-
+ /// Construct a util::text
+ ///
+ /// \param[in] input_ A binary image.
+ /// \param[in] nbh_ A neighborhood to be used with labeling algorithms.
+ /// \param[in] nbboxes The number of bounding boxes.
+ ///
+ /// \return A util::text.
template <typename I, typename N, typename V>
scribo::util::text<mln_ch_value(I,V)>
text(const Image<I>& input_, const Neighborhood<N>& nbh_,
@@ -106,12 +119,12 @@ namespace scribo
}
//FIXME: we want the following routine to construct a new util::text
- // from another one and a relabeling function. It avoid recomputing
+ // from another one and a relabeling function. It avoids recomputing
// the whole underlying data (mass centers, bboxes...)
// template <typename L>
// scribo::util::text<L>
// text(const scribo::util::text<L>& text,
-// const Function_v2v<F>& f)
+// const Function_v2b<F>& f)
// {
// trace::entering("scribo::make::text");
//
@@ -119,22 +132,22 @@ namespace scribo
//
// mln_value(L) new_nbboxes;
// mln::fun::l2l::relabel<mln_value(L)> fl2l
-// = mln::make::relabelfun(f, nbboxes_, new_nbboxes);
-// lbl_ = labeling::relabel(lbl_, nbboxes_, l2l);
-// nbboxes_ = new_nbboxes;
+// = mln::make::relabelfun(f, text.nbboxes(), new_nbboxes);
+// lbl_ = labeling::relabel(text.label_image(), text.nbboxes(), l2l);
+// text.nbboxes() = new_nbboxes;
//
-// mln::util::array< accu::bbox<mln_site(I)> > tboxes(nbboxes_);
-// mln::util::array< accu::center<mln_site(I)> > tcenters(nbboxes_);
+// mln::util::array< accu::bbox<mln_site(I)> > tboxes(text.nbboxes().next());
+// mln::util::array< accu::center<mln_site(I)> > tcenters(text.nbboxes().next());
// for_all_components(i, text.bboxes())
// {
// abboxes[fl2l(i)].take(text.bbox(i));
// acenters[fl2l(i)].take(text.bbox(i));
// }
// convert::from_to(abboxes, text.bboxes());
-// convert::from_to(acenters, text.mass_centers_);
+// convert::from_to(acenters, text.mass_centers());
//
// trace::exiting("scribo::make::text");
-// return scribo::util::text<L>(;
+// return scribo::util::text<L>();
// }
diff --git a/milena/sandbox/scribo/src/photo_basic.cc b/milena/sandbox/scribo/src/photo_basic.cc
index baba806..871da36 100644
--- a/milena/sandbox/scribo/src/photo_basic.cc
+++ b/milena/sandbox/scribo/src/photo_basic.cc
@@ -28,6 +28,7 @@
#include <iostream>
#include <mln/essential/2d.hh>
+#include <mln/debug/colorize.hh>
#include <scribo/text/extract_bboxes.hh>
#include <scribo/text/grouping/group_with_single_left_link.hh>
@@ -100,6 +101,7 @@ int main(int argc, char* argv[])
literal::red,
scribo::make::debug_filename("test_graph_grouped_text.ppm"));
-
+ io::ppm::save(mln::debug::colorize(value::rgb8(), grouped_textbboxes.label_image(), grouped_textbboxes.nbboxes()),
+ scribo::make::debug_filename("grouped_text_comps.ppm"));
}
diff --git a/milena/sandbox/scribo/src/table_rebuild_rank.cc b/milena/sandbox/scribo/src/table_rebuild_rank.cc
index 1368591..1ed8ddd 100644
--- a/milena/sandbox/scribo/src/table_rebuild_rank.cc
+++ b/milena/sandbox/scribo/src/table_rebuild_rank.cc
@@ -29,6 +29,8 @@
#include <mln/essential/2d.hh>
#include <mln/pw/all.hh>
+#include <mln/level/compute.hh>
+#include <mln/accu/maj_h.hh>
#include <scribo/table/rebuild.hh>
#include <scribo/table/erase.hh>
@@ -71,7 +73,16 @@ int main(int argc, char* argv[])
std::cout << "ncells (including background) = " << ncells << std::endl;
- io::ppm::save(mln::debug::colorize(value::rgb8(), tables, ncells),
+ image2d<value::rgb8> table_color = mln::debug::colorize(value::rgb8(), tables, ncells);
+
+ value::label_8 bg = level::compute(accu::maj_h<value::label_8>(), tables);
+
+ image2d<value::rgb8> sup = level::convert(value::rgb8(), input);
+ data::paste((table_color | pw::value(tables) != pw::cst(bg))
+ | (pw::value(sup) == pw::cst(literal::black)), sup);
+ io::ppm::save(sup, scribo::make::debug_filename("table_color_sup.ppm"));
+
+ io::ppm::save(table_color,
scribo::make::debug_filename("table_cells.ppm"));
io::pgm::save(tables, scribo::make::debug_filename("table_cells.pgm"));
@@ -82,4 +93,5 @@ int main(int argc, char* argv[])
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 88e283e..d3b4361 100644
--- a/milena/sandbox/scribo/table/align_lines_horizontaly.hh
+++ b/milena/sandbox/scribo/table/align_lines_horizontaly.hh
@@ -58,7 +58,7 @@ namespace scribo
///
/// \param[in] input Image from which the line bboxes are
/// extracted from.
- /// \param[in, out] lines_bboxes horizontal lines bounding boxes.
+ /// \param[in, out] line_bboxes horizontal lines bounding boxes.
/// \param[in] max_alignment_diff max space between two lines to
/// consider they are potentialy on the
/// same line.
@@ -68,7 +68,7 @@ namespace scribo
template <typename I>
util::array<int>
align_lines_horizontaly(const Image<I>& input,
- util::array<box<mln_site(I)> >& lines_bboxes,
+ util::array<box<mln_site(I)> >& line_bboxes,
unsigned max_alignment_diff);
@@ -78,7 +78,7 @@ namespace scribo
template <typename I>
util::array<int>
align_lines_horizontaly(const Image<I>& input,
- util::array<box<mln_site(I)> >& lines_bboxes,
+ util::array<box<mln_site(I)> >& line_bboxes,
unsigned max_alignment_diff)
{
trace::entering("scribo::table::align_lines_horizontaly");
@@ -87,7 +87,7 @@ namespace scribo
util::array<int> res = internal::align_lines(geom::nrows(input),
geom::min_row(input),
geom::max_row(input),
- lines_bboxes, 0,
+ line_bboxes, 0,
max_alignment_diff);
trace::exiting("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 c1062bf..9c73980 100644
--- a/milena/sandbox/scribo/table/align_lines_verticaly.hh
+++ b/milena/sandbox/scribo/table/align_lines_verticaly.hh
@@ -59,7 +59,7 @@ namespace scribo
///
/// \param[in] input Image from which the line bboxes are
/// extracted from.
- /// \param[in, out] lines_bboxes vertical lines bounding boxes.
+ /// \param[in, out] line_bboxes vertical lines bounding boxes.
/// \param[in] max_alignment_diff max space between two lines to
/// consider they are potentialy on the
/// same line.
@@ -69,7 +69,7 @@ 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)> >& line_bboxes,
unsigned max_alignment_diff);
@@ -79,7 +79,7 @@ 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)> >& line_bboxes,
unsigned max_alignment_diff)
{
trace::entering("scribo::table::align_lines_verticaly");
@@ -88,7 +88,7 @@ namespace scribo
util::array<int> res = internal::align_lines(geom::ncols(input),
geom::min_col(input),
geom::max_col(input),
- lines_bboxes, 1,
+ line_bboxes, 1,
max_alignment_diff);
trace::exiting("scribo::table::align_lines_verticaly");
diff --git a/milena/sandbox/scribo/table/all.hh b/milena/sandbox/scribo/table/all.hh
new file mode 100644
index 0000000..9062b79
--- /dev/null
+++ b/milena/sandbox/scribo/table/all.hh
@@ -0,0 +1,59 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_TABLE_ALL_HH
+# define SCRIBO_TABLE_ALL_HH
+
+/// \file scribo/table/all.hh
+///
+/// Include all headers located in scribo/table.
+
+namespace scribo
+{
+
+ /// Namespace of routines working on tables.
+ namespace table
+ {
+
+ } // end of namespace scribo::table
+
+} // end of namespace scribo
+
+# include <scribo/table/internal/all.hh>
+# include <scribo/table/repair_vertical_lines.hh>
+# include <scribo/table/rebuild.hh>
+# include <scribo/table/connect_horizontal_lines.hh>
+# include <scribo/table/erase.hh>
+# include <scribo/table/align_lines_horizontaly.hh>
+# include <scribo/table/extract_lines_with_opening.hh>
+# include <scribo/table/align_lines_verticaly.hh>
+# include <scribo/table/extract_lines_with_rank.hh>
+# include <scribo/table/extract.hh>
+# include <scribo/table/connect_vertical_lines.hh>
+# include <scribo/table/repair_horizontal_lines.hh>
+
+#endif // ! SCRIBO_TABLE_ALL_HH
diff --git a/milena/sandbox/scribo/table/connect_horizontal_lines.hh b/milena/sandbox/scribo/table/connect_horizontal_lines.hh
index c1d3bd6..69d52a8 100644
--- a/milena/sandbox/scribo/table/connect_horizontal_lines.hh
+++ b/milena/sandbox/scribo/table/connect_horizontal_lines.hh
@@ -33,6 +33,8 @@
/// \file scribo/table/connect_horizontal_lines.hh
///
/// Connect horizontal lines with the new aligned columns.
+///
+/// \todo do not modify arguments but return a new value.
# include <mln/core/concept/image.hh>
# include <mln/util/array.hh>
@@ -51,7 +53,7 @@ namespace scribo
/// Connect horizontal lines with the new aligned columns.
///
/// \param[in] aligned_cols a list of new aligned cols.
- /// \param[in,out] tableboxes the vertical and horizontal lines
+ /// \param[in,out] tablebboxes the vertical and horizontal lines
/// bounding boxes.
/// \param[in] input The image from where the lines are
/// extracted.
@@ -59,11 +61,11 @@ namespace scribo
/// and horizontal lines.
template <typename I>
void
- connect_vertical_lines(const util::array<int>& aligned_rows,
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tableboxes,
- const Image<I>& input,
- unsigned max_distance);
+ connect_horizontal_lines(const util::array<int>& aligned_cols,
+ util::couple<util::array<box<mln_site(I)> >,
+ util::array<box<mln_site(I)> > >& tablebboxes,
+ const Image<I>& input,
+ unsigned max_distance);
# ifndef MLN_INCLUDE_ONLY
@@ -73,14 +75,14 @@ namespace scribo
void
connect_horizontal_lines(const util::array<int>& aligned_cols,
util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tableboxes,
+ util::array<box<mln_site(I)> > >& tablebboxes,
const Image<I>& input,
unsigned max_distance)
{
trace::entering("scribo::table::connect_horizontal_lines");
mln_precondition(exact(input).is_valid());
- internal::connect_lines(aligned_cols, tableboxes.second(),
+ internal::connect_lines(aligned_cols, tablebboxes.second(),
1, exact(input).ncols(), max_distance);
trace::exiting("scribo::table::connect_horizontal_lines");
diff --git a/milena/sandbox/scribo/table/connect_vertical_lines.hh b/milena/sandbox/scribo/table/connect_vertical_lines.hh
index 2ab4990..06e7cce 100644
--- a/milena/sandbox/scribo/table/connect_vertical_lines.hh
+++ b/milena/sandbox/scribo/table/connect_vertical_lines.hh
@@ -33,6 +33,8 @@
/// \file scribo/table/connect_vertical_lines.hh
///
/// Connect vertical lines with aligned rows.
+///
+/// \todo do not modify arguments but return a new value.
# include <mln/core/concept/image.hh>
# include <mln/util/array.hh>
@@ -51,7 +53,7 @@ namespace scribo
/// Connect vertical lines with the new aligned rows.
///
/// \param[in] aligned_rows a list of new aligned rows.
- /// \param[in,out] tableboxes the vertical and horizontal lines
+ /// \param[in,out] tablebboxes the vertical and horizontal lines
/// bounding boxes.
/// \param[in] input The image from where the lines are
/// extracted.
@@ -61,7 +63,7 @@ namespace scribo
void
connect_vertical_lines(const util::array<int>& aligned_rows,
util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tableboxes,
+ util::array<box<mln_site(I)> > >& tablebboxes,
const Image<I>& input,
unsigned max_distance);
@@ -74,14 +76,14 @@ namespace scribo
void
connect_vertical_lines(const util::array<int>& aligned_rows,
util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tableboxes,
+ util::array<box<mln_site(I)> > >& tablebboxes,
const Image<I>& input,
unsigned max_distance)
{
trace::entering("scribo::table::connect_vertical_lines");
mln_precondition(exact(input).is_valid());
- internal::connect_lines(aligned_rows, tableboxes.first(),
+ internal::connect_lines(aligned_rows, tablebboxes.first(),
0, exact(input).nrows(), max_distance);
trace::exiting("scribo::table::connect_vertical_lines");
diff --git a/milena/sandbox/scribo/table/erase.hh b/milena/sandbox/scribo/table/erase.hh
index 2f5957a..78e3756 100644
--- a/milena/sandbox/scribo/table/erase.hh
+++ b/milena/sandbox/scribo/table/erase.hh
@@ -54,18 +54,18 @@ namespace scribo
/// Erase table line bboxes from an image.
///
- /// \param[in] line_bboxes vertical and horizontal line bounding
+ /// \param[in] tablebboxes vertical and horizontal line bounding
/// boxes.
- /// \param[in] in A binary image from which the table line
+ /// \param[in] input A binary image from which the table line
/// bboxes are extracted.
///
///
/// \return A copy of \p in where the table lines are removed.
template <typename I>
mln_concrete(I)
- erase(const Image<I>& in,
+ erase(const Image<I>& input,
const util::couple<util::array< box<mln_site(I)> >,
- util::array< box<mln_site(I)> > >& line_bboxes);
+ util::array< box<mln_site(I)> > >& tablebboxes);
# ifndef MLN_INCLUDE_ONLY
@@ -73,18 +73,18 @@ namespace scribo
template <typename I>
mln_concrete(I)
- erase(const Image<I>& in,
+ erase(const Image<I>& input,
const util::couple<util::array< box<mln_site(I)> >,
- util::array< box<mln_site(I)> > >& line_bboxes)
+ util::array< box<mln_site(I)> > >& tablebboxes)
{
trace::entering("scribo::internal::erase");
mlc_equal(mln_value(I),bool)::check();
- mln_precondition(exact(in).is_valid());
+ mln_precondition(exact(input).is_valid());
- I output = duplicate(in);
+ I output = duplicate(input);
- erase_bboxes(output, line_bboxes.first());
- erase_bboxes(output, line_bboxes.second());
+ erase_bboxes(output, tablebboxes.first());
+ erase_bboxes(output, tablebboxes.second());
trace::exiting("scribo::internal::erase");
return output;
diff --git a/milena/sandbox/scribo/table/extract_lines_with_opening.hh b/milena/sandbox/scribo/table/extract_lines_with_opening.hh
index a4ddfd1..c3454db 100644
--- a/milena/sandbox/scribo/table/extract_lines_with_opening.hh
+++ b/milena/sandbox/scribo/table/extract_lines_with_opening.hh
@@ -63,22 +63,22 @@ namespace scribo
*
* \param[in] input_ A binary image.
* \param[in] nbh_ The neighborhood used for labeling image components.
- * \param[out] nlines The number of lines found.
- * \param[in] vwin Window used to extract the vertical lines in a morphological
+ * \param[in] label_type Type used for labeling.
+ * \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
+ * \param[in] hwin_ Window used to extract the horizontal lines in a morphological
* opening
*
* \return pair of array of bounding boxes. The first array holds the
* vertical lines bounding boxes and the second one the
* horizontal lines bounding boxes.
*/
- template <typename I, typename N, typename V, typename HW, typename VW>
+ template <typename I, typename N, typename V, typename VW, typename HW>
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_, V& nlines,
- const Window<HW>& vwin, const Window<VW>& hwin);
+ const Neighborhood<N>& nbh_, const V& label_type,
+ const Window<VW>& vwin_, const Window<HW>& hwin_);
# ifndef MLN_INCLUDE_ONLY
@@ -88,7 +88,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_, V& nlines,
+ const Neighborhood<N>& nbh_, const V& label_type,
const Window<VW>& vwin_, const Window<HW>& hwin_)
{
trace::entering("scribo::table::extract_lines_with_opening");
@@ -108,9 +108,11 @@ namespace scribo
typedef util::array<box<mln_site(I)> > boxes_t;
+ V ncomps;
+
// Vertical lines
mln_ch_value(I,bool) vfilter = morpho::erosion(input, vwin);
- boxes_t vboxes = component_bboxes(vfilter, nbh, nlines).first();
+ boxes_t vboxes = component_bboxes(vfilter, nbh, ncomps).first();
for_all_components(i, vboxes)
{
vboxes[i].enlarge(0, vwin.length() / 2);
@@ -119,7 +121,7 @@ namespace scribo
// Horizontal lines.
mln_ch_value(I,bool) hfilter = morpho::erosion(input, hwin);
- boxes_t hboxes = component_bboxes(hfilter, nbh, nlines).first();
+ boxes_t hboxes = component_bboxes(hfilter, nbh, ncomps).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 dbb3d50..c6eb1fa 100644
--- a/milena/sandbox/scribo/table/extract_lines_with_rank.hh
+++ b/milena/sandbox/scribo/table/extract_lines_with_rank.hh
@@ -63,10 +63,10 @@ namespace scribo
*
* \param[in] input_ A binary image.
* \param[in] nbh_ The neighborhood used for labeling image components.
- * \param[out] nlines The number of lines.
- * \param[in] vwin Window used to extract the vertical lines in the rank
+ * \param[in] label_type The label type used for labeling.
+ * \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
+ * \param[in] hwin_ Window used to extract the horizontal lines in the rank
* filter.
* \param[in] vrank_k Rank used for vertical lines filtering.
* \param[in] hrank_k Rank used for horizontal lines filtering.
@@ -75,12 +75,12 @@ namespace scribo
* vertical lines bounding boxes and the second one the
* horizontal lines bounding boxes.
*/
- template <typename I, typename N, typename V, typename HW, typename VW>
+ template <typename I, typename N, typename V, typename VW, typename HW>
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_, V& nlines,
- const Window<HW>& vwin, const Window<VW>& hwin,
+ const Neighborhood<N>& nbh_, const V& label_type,
+ const Window<VW>& vwin_, const Window<HW>& 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_, V& nlines,
+ const Neighborhood<N>& nbh_, const V& label_type,
const Window<VW>& vwin_, const Window<HW>& hwin_,
unsigned vrank_k, unsigned hrank_k)
{
@@ -104,6 +104,7 @@ namespace scribo
const N& nbh = exact(nbh_);
const VW& vwin = exact(vwin_);
const HW& hwin = exact(hwin_);
+ (void) label_type;
mln_precondition(input.is_valid());
mln_precondition(nbh.is_valid());
@@ -112,9 +113,11 @@ namespace scribo
typedef util::array<box<mln_site(I)> > boxes_t;
+ V nbboxes;
+
// Vertical lines
mln_ch_value(I,bool) vfilter = morpho::rank_filter(input, vwin, vrank_k);
- boxes_t vboxes = component_bboxes(vfilter, nbh, nlines).first();
+ boxes_t vboxes = component_bboxes(vfilter, nbh, nbboxes).first();
for_all_components(i, vboxes)
{
vboxes[i].enlarge(0, vwin.length() / 2);
@@ -123,7 +126,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, nlines).first();
+ boxes_t hboxes = component_bboxes(hfilter, nbh, nbboxes).first();
for_all_components(i, hboxes)
{
hboxes[i].enlarge(1, hwin.length() / 2);
diff --git a/milena/sandbox/scribo/table/internal/align_lines.hh b/milena/sandbox/scribo/table/internal/align_lines.hh
index 202b2dd..0902bd4 100644
--- a/milena/sandbox/scribo/table/internal/align_lines.hh
+++ b/milena/sandbox/scribo/table/internal/align_lines.hh
@@ -55,6 +55,13 @@ namespace scribo
/// Align table lines bboxes according to a given dimension.
///
+ /// \param[in] nsites Number of sites in the given dimension \p dim.
+ /// \param[in] min_coord The minimal coordinate in the dimension \p dim.
+ /// \param[in] max_coord The maximal coordinate in the dimension \p dim.
+ /// \param[in] line_bboxes Line bounding boxes.
+ /// \param[in] dim The dimension according which the lines are aligned.
+ /// \param[in] max_alignment_diff Maximum alignment difference.
+ ///
/// \return A list of the resulting aligned cols. Each integer is actually
/// a col number.
/*
@@ -90,8 +97,9 @@ namespace scribo
align_lines(unsigned nsites,
int min_coord,
int max_coord,
- util::array<box<P> >& line_boxes,
- unsigned dim);
+ util::array<box<P> >& line_bboxes,
+ unsigned dim,
+ unsigned max_alignment_diff);
@@ -103,7 +111,7 @@ namespace scribo
align_lines(unsigned nsites,
int min_coord,
int max_coord,
- util::array<box<P> >& line_boxes,
+ util::array<box<P> >& line_bboxes,
unsigned dim,
unsigned max_alignment_diff)
{
@@ -115,11 +123,11 @@ namespace scribo
lines.resize(nsites);
// Map components with actual lines.
- for_all_components(i, line_boxes)
+ for_all_components(i, line_bboxes)
{
- int minline = line_boxes[i].pmin()[dim] - max_alignment_diff;
+ int minline = line_bboxes[i].pmin()[dim] - max_alignment_diff;
minline = (minline < min_coord ? min_coord : minline);
- int maxline = line_boxes[i].pmax()[dim] + max_alignment_diff;
+ int maxline = line_bboxes[i].pmax()[dim] + max_alignment_diff;
maxline = (maxline > max_coord ? max_coord : maxline);
for (int line = minline;
@@ -129,7 +137,7 @@ namespace scribo
// Init box2line
util::array<int> box2line;
- box2line.resize(line_boxes.nelements());
+ box2line.resize(line_bboxes.nelements());
for_all_elements(i, box2line)
box2line[i] = -1;
@@ -152,15 +160,15 @@ namespace scribo
accu::mean<unsigned> mean;
for_all_elements(j, lines[i])
if (box2line[lines[i][j]] == -1)
- mean.take(line_boxes[lines[i][j]].center()[dim]);
+ mean.take(line_bboxes[lines[i][j]].center()[dim]);
if (mean.is_valid())
{
for_all_elements(j, lines[i])
if (box2line[lines[i][j]] == -1)
{
- line_boxes[lines[i][j]].pmin()[dim] = mean.to_result();
- line_boxes[lines[i][j]].pmax()[dim] = mean.to_result();
+ line_bboxes[lines[i][j]].pmin()[dim] = mean.to_result();
+ line_bboxes[lines[i][j]].pmax()[dim] = mean.to_result();
box2line[lines[i][j]] = mean.to_result();
}
newlines.append(mean.to_result());
diff --git a/milena/sandbox/scribo/table/internal/all.hh b/milena/sandbox/scribo/table/internal/all.hh
new file mode 100644
index 0000000..0913dd9
--- /dev/null
+++ b/milena/sandbox/scribo/table/internal/all.hh
@@ -0,0 +1,57 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_TABLE_INTERNAL_ALL_HH
+# define SCRIBO_TABLE_INTERNAL_ALL_HH
+
+/// \file scribo/table/internal/all.hh
+///
+/// Include all headers located in scribo/table/internal.
+
+namespace scribo
+{
+
+ namespace table
+ {
+
+ /// Namespace of internal routines working on tables.
+ namespace internal
+ {
+
+ } // end of namespace scribo::table::internal
+
+ } // end of namespace scribo::table
+
+} // end of namespace scribo
+
+
+# include <scribo/table/internal/align_lines.hh>
+# include <scribo/table/internal/connect_lines.hh>
+# include <scribo/table/internal/repair_lines.hh>
+
+
+#endif // ! SCRIBO_TABLE_INTERNAL_ALL_HH
diff --git a/milena/sandbox/scribo/table/rebuild.hh b/milena/sandbox/scribo/table/rebuild.hh
index 4c632ba..a446c3a 100644
--- a/milena/sandbox/scribo/table/rebuild.hh
+++ b/milena/sandbox/scribo/table/rebuild.hh
@@ -56,13 +56,29 @@ namespace scribo
namespace table
{
+
+ /// Rebuild a table from its line bounding boxes.
+ /*!
+ ** \param[in] input_ A binary image.
+ ** \param[in] linebboxes_ A couple of vertical and horizontal
+ ** line bounding boxes.
+ ** \param[in] max_dist_lines The maximum distance allowed between
+ ** vertical and horizontal lines to connect
+ ** them eachother.
+ ** \param[out] ncells Store the number of cells found in the
+ ** rebuilt tables.
+ **
+ ** \return A couple. The first argument is a label image in which each table
+ ** cell is labeled. The second argument are the aligned and connected
+ ** table line bounding boxes.
+ */
template <typename I, typename 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_,
+ rebuild(const Image<I>& input_,
const util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& lineboxes,
+ util::array<box<mln_site(I)> > >& linebboxes_,
unsigned max_dist_lines,
V& ncells);
@@ -74,62 +90,62 @@ namespace scribo
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_,
+ rebuild(const Image<I>& input_,
const util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& lineboxes,
+ util::array<box<mln_site(I)> > >& linebboxes_,
unsigned max_dist_lines,
V& ncells)
{
trace::entering("scribo::table::rebuild");
- const I& in = exact(in_);
+ const I& input = exact(input_);
mlc_equal(mln_value(I), bool)::check();
- mln_precondition(in.is_valid());
+ mln_precondition(input.is_valid());
util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > > tblboxes = lineboxes;
+ util::array<box<mln_site(I)> > > linebboxes = linebboxes_;
- scribo::debug::save_table_image(in, tblboxes,
+ scribo::debug::save_table_image(input, linebboxes,
literal::red, "table-raw.ppm");
- util::array<int> rows = align_lines_horizontaly(in, tblboxes.second(), 5);
- util::array<int> cols = align_lines_verticaly(in, tblboxes.first(), 5);
+ util::array<int> rows = align_lines_horizontaly(input, linebboxes.second(), 5);
+ util::array<int> cols = align_lines_verticaly(input, linebboxes.first(), 5);
# ifndef SCRIBO_NDEBUG
- scribo::debug::save_table_image(in, tblboxes,
+ scribo::debug::save_table_image(input, linebboxes,
literal::red, "table-aligned.ppm");
# endif
- repair_vertical_lines(in, tblboxes, 30);
- repair_horizontal_lines(in, tblboxes, 30);
+ repair_vertical_lines(input, linebboxes, 30);
+ repair_horizontal_lines(input, linebboxes, 30);
# ifndef SCRIBO_NDEBUG
- scribo::debug::save_table_image(in, tblboxes,
+ scribo::debug::save_table_image(input, linebboxes,
literal::red, "table-repaired.ppm");
# endif
// Connect vertical lines with horizontal lines.
- connect_vertical_lines(rows, tblboxes, in, max_dist_lines);
- connect_horizontal_lines(cols, tblboxes, in, max_dist_lines);
+ connect_vertical_lines(rows, linebboxes, input, max_dist_lines);
+ connect_horizontal_lines(cols, linebboxes, input, max_dist_lines);
# ifndef SCRIBO_NDEBUG
- scribo::debug::save_table_image(in, tblboxes,
+ scribo::debug::save_table_image(input, linebboxes,
literal::red, "table-connected.ppm");
# endif
mln_ch_value(I,bool) res;
- initialize(res, in);
+ initialize(res, input);
data::fill(res, false);
- for_all_elements(i, tblboxes.first())
- mln::draw::box(res, tblboxes.first()[i], true);
- for_all_elements(i, tblboxes.second())
- mln::draw::box(res, tblboxes.second()[i], true);
+ for_all_elements(i, linebboxes.first())
+ mln::draw::box(res, linebboxes.first()[i], true);
+ for_all_elements(i, linebboxes.second())
+ mln::draw::box(res, linebboxes.second()[i], true);
mln_ch_value(I,V) lbl = labeling::background(res, c8(), ncells);
trace::exiting("scribo::table::rebuild");
- return mln::make::couple(lbl, tblboxes);
+ return mln::make::couple(lbl, linebboxes);
}
diff --git a/milena/sandbox/scribo/table/repair_horizontal_lines.hh b/milena/sandbox/scribo/table/repair_horizontal_lines.hh
index e871480..aff4eb4 100644
--- a/milena/sandbox/scribo/table/repair_horizontal_lines.hh
+++ b/milena/sandbox/scribo/table/repair_horizontal_lines.hh
@@ -32,6 +32,8 @@
/// \file scribo/table/repair_horizontal_lines.hh
///
/// Repair horizontal lines which have small discontinuities.
+///
+/// \todo do not modify arguments but return a new value.
# include <mln/core/concept/image.hh>
# include <mln/util/couple.hh>
@@ -52,7 +54,7 @@ namespace scribo
*
* \param[in] input Image from which the table bounding
* boxes are extracted.
- * \param[in,out] tablesboxes Table line bounding boxes.
+ * \param[in,out] tablebboxes Table line bounding boxes.
* \param[in] max_discontinuity Repair discontinuity which are smaller
* than this value.
*/
@@ -60,7 +62,7 @@ namespace scribo
void
repair_horizontal_lines(const Image<I>& input,
util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tableboxes,
+ util::array<box<mln_site(I)> > >& tablebboxes,
unsigned max_discontinuity);
# ifndef MLN_INCLUDE_ONLY
@@ -70,13 +72,13 @@ namespace scribo
void
repair_horizontal_lines(const Image<I>& input,
util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tableboxes,
+ util::array<box<mln_site(I)> > >& tablebboxes,
unsigned max_discontinuity)
{
trace::entering("scribo::table::repair_horizontal_lines");
mln_precondition(exact(input).is_valid());
- internal::repair_lines<1>(input, tableboxes.second(), max_discontinuity);
+ internal::repair_lines<1>(input, tablebboxes.second(), max_discontinuity);
trace::exiting("scribo::table::repair_horizontal_lines");
}
diff --git a/milena/sandbox/scribo/table/repair_vertical_lines.hh b/milena/sandbox/scribo/table/repair_vertical_lines.hh
index 94ae3f1..5fbac2e 100644
--- a/milena/sandbox/scribo/table/repair_vertical_lines.hh
+++ b/milena/sandbox/scribo/table/repair_vertical_lines.hh
@@ -32,6 +32,8 @@
/// \file scribo/table/repair_vertical_lines.hh
///
/// Repair vertical lines which have small discontinuities.
+///
+/// \todo do not modify arguments but return a new value.
# include <mln/core/concept/image.hh>
# include <mln/util/couple.hh>
@@ -58,7 +60,7 @@ namespace scribo
*
* \param[in] input Image from which the table bounding
* boxes are extracted.
- * \param[in,out] tablesboxes Table line bounding boxes.
+ * \param[in,out] tablebboxes Table line bounding boxes.
* \param[in] max_discontinuity Repair discontinuity which are smaller
* than this value.
*/
@@ -66,7 +68,7 @@ namespace scribo
void
repair_vertical_lines(const Image<I>& input,
util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tblboxes,
+ util::array<box<mln_site(I)> > >& tablebboxes,
unsigned max_discontinuity);
# ifndef MLN_INCLUDE_ONLY
@@ -76,13 +78,13 @@ namespace scribo
void
repair_vertical_lines(const Image<I>& input,
util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tblboxes,
+ util::array<box<mln_site(I)> > >& tablebboxes,
unsigned max_discontinuity)
{
trace::entering("scribo::table::repair_vertical_lines");
mln_precondition(exact(input).is_valid());
- internal::repair_lines<0>(input, tblboxes.first(), max_discontinuity);
+ internal::repair_lines<0>(input, tablebboxes.first(), max_discontinuity);
trace::exiting("scribo::table::repair_vertical_lines");
}
diff --git a/milena/sandbox/scribo/text/all.hh b/milena/sandbox/scribo/text/all.hh
new file mode 100644
index 0000000..b25c74f
--- /dev/null
+++ b/milena/sandbox/scribo/text/all.hh
@@ -0,0 +1,51 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_TEXT_ALL_HH
+# define SCRIBO_TEXT_ALL_HH
+
+/// \file scribo/text/all.hh
+///
+/// Include all headers located in scribo/text.
+
+namespace scribo
+{
+
+ /// Namespace of routines working on text components.
+ namespace text
+ {
+
+ } // end of namespace scribo::text
+
+} // end of namespace scribo
+
+# include <scribo/text/extract_lines.hh>
+# include <scribo/text/recognition.hh>
+# include <scribo/text/extract_bboxes.hh>
+# include <scribo/text/grouping/all.hh>
+
+#endif // ! SCRIBO_TEXT_ALL_HH
diff --git a/milena/sandbox/scribo/text/extract_bboxes.hh b/milena/sandbox/scribo/text/extract_bboxes.hh
index 4a936b5..8908677 100644
--- a/milena/sandbox/scribo/text/extract_bboxes.hh
+++ b/milena/sandbox/scribo/text/extract_bboxes.hh
@@ -30,7 +30,7 @@
#ifndef SCRIBO_TEXT_GROUPING_EXTRACT_BBOXES_HH
# define SCRIBO_TEXT_GROUPING_EXTRACT_BBOXES_HH
-/// \file scribo/text/grouping/group_with_single_link.hh
+/// \file scribo/text/extract_bboxes.hh
///
/// Extract text bounding boxes from a binary image.
@@ -55,14 +55,17 @@ namespace scribo
/// Extract text bounding boxes from a binary image.
///
- /// \param[in] input_ A binary image.
+ /// \param[in] input_ A binary imag.
+ /// \param[in] nbh_ The neighborhood used for labeling.
+ /// \param[in,out] nbboxes Will hold the number of bounding boxes at
+ /// the end of the routine.
///
/// \return an array of bounding boxes. The first bounding box is
/// the background's.
template <typename I, typename N, typename V>
scribo::util::text<mln_ch_value(I,V)>
extract_bboxes(const Image<I>& input_,
- const Neighborhood<N>& nbh, V& nbboxes);
+ const Neighborhood<N>& nbh_, V& nbboxes);
# ifndef MLN_INCLUDE_ONLY
@@ -71,14 +74,16 @@ namespace scribo
inline
scribo::util::text<mln_ch_value(I,V)>
extract_bboxes(const Image<I>& input_,
- const Neighborhood<N>& nbh, V& nbboxes)
+ const Neighborhood<N>& nbh_, V& nbboxes)
{
trace::entering("scribo::text::extract_bboxes");
const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
mlc_equal(mln_value(I), bool)::check();
mln_precondition(input.is_valid());
+ mln_precondition(nbh.is_valid());
typedef mln::util::array< box<mln_site(I)> > bboxes_t;
typedef mln::util::couple<bboxes_t, mln_ch_value(I,V)> bboxes_and_lbl_t;
diff --git a/milena/sandbox/scribo/text/extract_lines.hh b/milena/sandbox/scribo/text/extract_lines.hh
index c08a4c4..8326117 100644
--- a/milena/sandbox/scribo/text/extract_lines.hh
+++ b/milena/sandbox/scribo/text/extract_lines.hh
@@ -67,7 +67,15 @@ namespace scribo
using namespace mln;
-
+ /// Extract lines of text in a binary image.
+ /*!
+ ** \param[in] input_ A binary image.
+ ** \param[in] nbh_ A neighborhood used for labeling.
+ ** \param[in,out] nbboxes Will hold the number of bounding boxes
+ ** at the end of the routine.
+ **
+ ** \return The text lines.
+ */
template <typename I, typename N, typename V>
scribo::util::text<mln_ch_value(I,V)>
extract_lines(const Image<I>& input_,
diff --git a/milena/sandbox/scribo/text/grouping/all.hh b/milena/sandbox/scribo/text/grouping/all.hh
new file mode 100644
index 0000000..b0db454
--- /dev/null
+++ b/milena/sandbox/scribo/text/grouping/all.hh
@@ -0,0 +1,64 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_TEXT_GROUPING_ALL_HH
+# define SCRIBO_TEXT_GROUPING_ALL_HH
+
+/// \file scribo/text/grouping/all.hh
+///
+/// Include all headers located in scribo/text/grouping.
+
+namespace scribo
+{
+
+ namespace text
+ {
+
+ /// Namespace of routines grouping text components.
+ namespace grouping
+ {
+
+ } // end of namespace scribo::text::grouping
+
+ } // end of namespace scribo::text
+
+} // end of namespace scribo
+
+
+# include <scribo/text/grouping/internal/all.hh>
+# include <scribo/text/grouping/group_with_several_graphes.hh>
+# include <scribo/text/grouping/group_from_double_link.hh>
+# include <scribo/text/grouping/group_with_several_right_links.hh>
+# include <scribo/text/grouping/group_with_graph.hh>
+# include <scribo/text/grouping/group_with_single_left_link.hh>
+# include <scribo/text/grouping/group_with_several_left_links.hh>
+# include <scribo/text/grouping/group_from_graph.hh>
+# include <scribo/text/grouping/group_from_single_link.hh>
+# include <scribo/text/grouping/group_with_single_right_link.hh>
+
+
+#endif // ! SCRIBO_TEXT_GROUPING_ALL_HH
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 8720c3a..c77b7d2 100644
--- a/milena/sandbox/scribo/text/grouping/group_from_double_link.hh
+++ b/milena/sandbox/scribo/text/grouping/group_from_double_link.hh
@@ -43,12 +43,13 @@
# include <mln/fun/l2l/relabel.hh>
-# include <scribo/text/grouping/internal/find_root.hh>
-
# include <scribo/core/macros.hh>
# include <scribo/util/text.hh>
+# include <scribo/text/grouping/internal/find_root.hh>
+# include <scribo/text/grouping/internal/is_link_valid.hh>
+
namespace scribo
{
@@ -59,7 +60,16 @@ namespace scribo
namespace grouping
{
- /// FIXME: Add much more doc!
+ /// Group text bounding boxes from left and right links and validate
+ /// These links. A link must exist in both ways to be validated.
+ /*!
+ ** \param[in] text The Lines of text.
+ ** \param[in] left_link The left neighbor of each line of text.
+ ** \param[in] right_link The right neighbor of each line of text.
+ **
+ ** \return New lines of text. Some of the lines of \p text may have
+ ** been grouped.
+ */
template <typename I>
scribo::util::text<I>
group_from_double_link(const scribo::util::text<I>& text,
@@ -86,10 +96,11 @@ namespace scribo
internal::init_link_array(parent);
for_all_components(i, text.bboxes())
{
- unsigned nbh = right_link[left_link[i]];
- if (nbh == i)
+ mln::util::couple<bool, unsigned>
+ nbh = internal::is_link_valid(left_link, right_link, i);
+ if (nbh.first())
{
- unsigned par = internal::find_root(parent, left_link[i]);
+ unsigned par = internal::find_root(parent, nbh.second());
if (par < i)
parent[par] = i;
else
diff --git a/milena/sandbox/scribo/text/grouping/group_from_graph.hh b/milena/sandbox/scribo/text/grouping/group_from_graph.hh
index a9cfd93..a0df22f 100644
--- a/milena/sandbox/scribo/text/grouping/group_from_graph.hh
+++ b/milena/sandbox/scribo/text/grouping/group_from_graph.hh
@@ -30,7 +30,8 @@
/// \file scribo/text/grouping/group_from_graph.hh
///
-/// Link text bounding boxes with their neighbors.
+/// Group lines of text according to a graph of links between
+/// the lines of text.
# include <mln/core/concept/graph.hh>
# include <mln/core/concept/image.hh>
@@ -60,7 +61,14 @@ namespace scribo
namespace grouping
{
- /// FIXME: Add much more doc!
+ /// Group lines of text according to a graph of links between
+ /// the lines of text.
+ /*!
+ ** \param[in] text The lines of text.
+ ** \param[in] g_ The graph of links between the lines of text.
+ **
+ ** \return The grouped and non-grouped lines of text.
+ */
template <typename I, typename G>
scribo::util::text<I>
group_from_graph(const scribo::util::text<I>& text,
@@ -77,6 +85,8 @@ namespace scribo
template <typename V>
struct map_vertex_to_component_id_functor
{
+
+ /// Initialize the functor.
template <typename G>
void init(const Graph<G>& g)
{
@@ -84,28 +94,40 @@ namespace scribo
ncomp = 0;
}
+ /// All components have been processed.
void final()
{}
+ /// Starting to treat a new component.
void next_component()
{ ++ncomp; }
+ /// A vertex with id \p id has been found in the current
+ /// component.
void new_component_from_vertex(unsigned id)
{ vertextocomp(id) = ncomp; }
+ /// A new neighbor with id \p id have been found for the
+ /// current vertex.
void added_to_queue(unsigned id)
{ new_component_from_vertex(id); }
+ /// Starting to process a new vertex.
void process_vertex(unsigned)
{}
+ /// Does the vertex with id \p id have been already treated?
bool to_be_treated(unsigned id)
{ return vertextocomp(id) == mln_max(V); }
+ /// Does the neighbor vertex \p id have been already treated?
bool to_be_queued(unsigned id)
{ return to_be_treated(id); }
+ /// The number of components found.
unsigned ncomp;
+
+ /// Map a verted id to its component id.
fun::l2l::relabel<V> vertextocomp;
};
diff --git a/milena/sandbox/scribo/text/grouping/group_from_single_link.hh b/milena/sandbox/scribo/text/grouping/group_from_single_link.hh
index 3dae34f..9428711 100644
--- a/milena/sandbox/scribo/text/grouping/group_from_single_link.hh
+++ b/milena/sandbox/scribo/text/grouping/group_from_single_link.hh
@@ -32,7 +32,7 @@
/// \file scribo/text/grouping/group_from_single_link.hh
///
-/// Link text bounding boxes with their left neighbor.
+/// Link lines of text with their neighbor line if they have one.
# include <mln/core/concept/image.hh>
# include <mln/core/site_set/box.hh>
@@ -56,7 +56,13 @@ namespace scribo
namespace grouping
{
- /// FIXME: Add much more doc!
+ /// Link lines of text with their neighbor line if they have one.
+ /*!
+ ** \param[in] text The lines of text.
+ ** \param[in] link_array The neighbor line of each line.
+ **
+ ** \return The grouped and non-grouped lines of text.
+ */
template <typename I>
scribo::util::text<I>
group_from_single_link(const scribo::util::text<I>& text,
@@ -95,6 +101,7 @@ namespace scribo
I lbl = labeling::relabel(text.label_image(), text.nbboxes(),
convert::to<fun::l2l::relabel<mln_value(I)> >(parent_array));
mln_value(I) new_nbboxes = result.nelements() - 1;
+
trace::exiting("scribo::text::grouping::group_from_single_link");
/// FIXME: construct a new util::text from the old one.
return scribo::make::text(result, lbl, new_nbboxes);
diff --git a/milena/sandbox/scribo/text/grouping/group_with_graph.hh b/milena/sandbox/scribo/text/grouping/group_with_graph.hh
index 3089d56..490d0d3 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_graph.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_graph.hh
@@ -54,8 +54,16 @@ namespace scribo
namespace grouping
{
- /// Group character bounding boxes with a graph.
+ /// Construct the links between each line of text and store
+ /// it as a graph.
/// Look up for neighbors on the right of each box.
+ /*!
+ ** \param[in] text The lines of text.
+ ** \param[in] neighb_max_distance The maximum distance allowed to
+ ** look for a neighbor.
+ **
+ ** \return A graph of relationship.
+ */
template <typename L>
mln::util::graph
group_with_graph(const scribo::util::text<L>& text,
diff --git a/milena/sandbox/scribo/text/grouping/group_with_graph.hh b/milena/sandbox/scribo/text/grouping/internal/all.hh
similarity index 54%
copy from milena/sandbox/scribo/text/grouping/group_with_graph.hh
copy to milena/sandbox/scribo/text/grouping/internal/all.hh
index 3089d56..72f4ca8 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_graph.hh
+++ b/milena/sandbox/scribo/text/grouping/internal/all.hh
@@ -1,5 +1,4 @@
// Copyright (C) 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
@@ -26,24 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
+#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_ALL_HH
+# define SCRIBO_TEXT_GROUPING_INTERNAL_ALL_HH
-#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_GRAPH_HH
-# define SCRIBO_TEXT_GROUPING_GROUP_WITH_GRAPH_HH
-
-/// \file scribo/text/grouping/group_with_graph.hh
+/// \file scribo/text/grouping/internal/all.hh
///
-/// Group character bounding boxes with a graph.
-
-# include <mln/core/concept/image.hh>
-
-# include <mln/math/abs.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/find_graph_link.hh>
-# include <scribo/util/text.hh>
+/// Include all headers located in scribo/text/grouping/internal.
namespace scribo
{
@@ -54,44 +41,11 @@ namespace scribo
namespace grouping
{
- /// Group character bounding boxes with a graph.
- /// Look up for neighbors on the right of each box.
- template <typename L>
- mln::util::graph
- group_with_graph(const scribo::util::text<L>& text,
- unsigned neighb_max_distance);
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename L>
- inline
- mln::util::graph
- group_with_graph(const scribo::util::text<L>& text,
- unsigned neighb_max_distance)
+ /// Namespace of internal routines grouping text components.
+ namespace internal
{
- trace::entering("scribo::text::grouping::group_with_graph");
- mln::util::graph g(text.nbboxes().next());
-
- 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;
-
- // -------
- // | |
- // | X------->
- // | |
- // -------
- internal::find_graph_link(g, text, i, dmax, text.mass_center(i));
- }
-
- trace::exiting("scribo::text::grouping::group_with_graph");
- return g;
- }
-
-# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace scribo::text::grouping::internal
} // end of namespace scribo::text::grouping
@@ -99,4 +53,15 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_GRAPH_HH
+
+# include <scribo/text/grouping/internal/init_link_array.hh>
+# include <scribo/text/grouping/internal/is_link_valid.hh>
+# include <scribo/text/grouping/internal/find_root.hh>
+# include <scribo/text/grouping/internal/find_graph_link.hh>
+# include <scribo/text/grouping/internal/find_right_link.hh>
+# include <scribo/text/grouping/internal/update_graph_link.hh>
+# include <scribo/text/grouping/internal/update_link_array.hh>
+# include <scribo/text/grouping/internal/find_left_link.hh>
+
+
+#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_ALL_HH
diff --git a/milena/sandbox/scribo/text/grouping/internal/find_graph_link.hh b/milena/sandbox/scribo/text/grouping/internal/find_graph_link.hh
index 95edebb..0da1c98 100644
--- a/milena/sandbox/scribo/text/grouping/internal/find_graph_link.hh
+++ b/milena/sandbox/scribo/text/grouping/internal/find_graph_link.hh
@@ -31,7 +31,7 @@
/// \file scribo/text/grouping/internal/find_graph_link.hh
///
-///
+/// Find the right neighbor of a line of text if exists.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/graph.hh>
@@ -46,6 +46,7 @@
//FIXME: not generic.
# include <mln/core/alias/dpoint2d.hh>
+
namespace scribo
{
@@ -58,6 +59,13 @@ namespace scribo
namespace internal
{
+ /// Find a neighbor of a text line in a specific range if it exists.
+ ///
+ /// \param g_ The link graph.
+ /// \param text The lines of text.
+ /// \param current_comp The current line being processed.
+ /// \param dmax The maximum lookup distance.
+ /// \param c Start point of the neighbor lookup.
template <typename G, typename L>
void
find_graph_link(Graph<G>& g_,
diff --git a/milena/sandbox/scribo/text/grouping/internal/find_left_link.hh b/milena/sandbox/scribo/text/grouping/internal/find_left_link.hh
index 4695012..e4fed4f 100644
--- a/milena/sandbox/scribo/text/grouping/internal/find_left_link.hh
+++ b/milena/sandbox/scribo/text/grouping/internal/find_left_link.hh
@@ -31,7 +31,7 @@
/// \file scribo/text/grouping/internal/find_left_link.hh
///
-///
+/// Find the left neighbor of a line of text if exists.
# include <mln/core/concept/image.hh>
@@ -57,6 +57,13 @@ namespace scribo
namespace internal
{
+ /// Find the left neighbor of a line of text if exists.
+ ///
+ /// \param text The lines of text.
+ /// \param left_link The left neighbors.
+ /// \param current_comp A text line id.
+ /// \param dmax The maximum lookup distance.
+ /// \param c The lookup start point.
template <typename L>
void
find_left_link(const scribo::util::text<L>& text,
@@ -79,12 +86,6 @@ namespace scribo
/// First site on the right of the central site
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
diff --git a/milena/sandbox/scribo/text/grouping/internal/find_right_link.hh b/milena/sandbox/scribo/text/grouping/internal/find_right_link.hh
index e83aa46..768861b 100644
--- a/milena/sandbox/scribo/text/grouping/internal/find_right_link.hh
+++ b/milena/sandbox/scribo/text/grouping/internal/find_right_link.hh
@@ -31,7 +31,7 @@
/// \file scribo/text/grouping/internal/find_right_link.hh
///
-///
+/// Find the right neighbor of a line of text if exists.
# include <mln/core/concept/image.hh>
@@ -57,6 +57,13 @@ namespace scribo
namespace internal
{
+ /// Find the right neighbor of a line of text if exists.
+ ///
+ /// \param text The lines of text.
+ /// \param right_link The right neighbors.
+ /// \param current_comp A text line id.
+ /// \param dmax The maximum lookup distance.
+ /// \param c The lookup start point.
template <typename L>
void
find_right_link(const scribo::util::text<L>& text,
@@ -79,12 +86,6 @@ namespace scribo
/// First site on the right of the central site
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
diff --git a/milena/sandbox/scribo/text/grouping/group_with_graph.hh b/milena/sandbox/scribo/text/grouping/internal/is_link_valid.hh
similarity index 53%
copy from milena/sandbox/scribo/text/grouping/group_with_graph.hh
copy to milena/sandbox/scribo/text/grouping/internal/is_link_valid.hh
index 3089d56..30c4f1e 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_graph.hh
+++ b/milena/sandbox/scribo/text/grouping/internal/is_link_valid.hh
@@ -27,23 +27,16 @@
// Public License.
-#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_GRAPH_HH
-# define SCRIBO_TEXT_GROUPING_GROUP_WITH_GRAPH_HH
+#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_IS_LINK_VALID_HH
+# define SCRIBO_TEXT_GROUPING_INTERNAL_IS_LINK_VALID_HH
-/// \file scribo/text/grouping/group_with_graph.hh
+/// \file scribo/text/grouping/internal/is_link_valid.hh
///
-/// Group character bounding boxes with a graph.
+/// Validate a link from two different links.
-# include <mln/core/concept/image.hh>
-
-# include <mln/math/abs.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/find_graph_link.hh>
-# include <scribo/util/text.hh>
+# include <mln/util/couple.hh>
namespace scribo
{
@@ -54,49 +47,41 @@ namespace scribo
namespace grouping
{
- /// Group character bounding boxes with a graph.
- /// Look up for neighbors on the right of each box.
- template <typename L>
- mln::util::graph
- group_with_graph(const scribo::util::text<L>& text,
- unsigned neighb_max_distance);
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename L>
- inline
- mln::util::graph
- group_with_graph(const scribo::util::text<L>& text,
- unsigned neighb_max_distance)
+ namespace internal
{
- trace::entering("scribo::text::grouping::group_with_graph");
- mln::util::graph g(text.nbboxes().next());
+ /// Validate a link from two different links.
+ ///
+ /// \param[in] left_link Left link of components.
+ /// \param[in] right_link Right link of components.
+ /// \param[in] i The component id.
+ ///
+ /// \return True if the link is between the \p i-th component
+ /// and it neighbor is validated.
+ mln::util::couple<bool,unsigned>
+ is_link_valid(const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ unsigned i);
- for_all_ncomponents(i, text.nbboxes())
+# ifndef MLN_INCLUDE_ONLY
+
+ mln::util::couple<bool,unsigned>
+ is_link_valid(const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ unsigned i)
{
- unsigned midcol = (text.bbox(i).pmax().col()
- - text.bbox(i).pmin().col()) / 2;
- int dmax = midcol + neighb_max_distance;
-
- // -------
- // | |
- // | X------->
- // | |
- // -------
- internal::find_graph_link(g, text, i, dmax, text.mass_center(i));
+ return mln::make::couple(right_link[left_link[i]] == i, left_link[i]);
}
- trace::exiting("scribo::text::grouping::group_with_graph");
- return g;
- }
-
# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace scribo::text::grouping::internal
+
} // end of namespace scribo::text::grouping
} // end of namespace scribo::text
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_GRAPH_HH
+#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_IS_LINK_VALID_HH
+
diff --git a/milena/sandbox/scribo/text/recognition.hh b/milena/sandbox/scribo/text/recognition.hh
index c11ed54..1fa3905 100644
--- a/milena/sandbox/scribo/text/recognition.hh
+++ b/milena/sandbox/scribo/text/recognition.hh
@@ -32,6 +32,9 @@
/// \file scribo/text/recognition.hh
///
/// Passes the text bounding boxes to an OCR (Tesseract).
+///
+/// \todo For each text bbox, we create a new image. We may like to avoid that.
+/// \todo Do not store the result in an image?
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
@@ -43,6 +46,7 @@
# include <mln/debug/put_words.hh>
# include <scribo/core/macros.hh>
+# include <scribo/util/text.hh>
# include <tesseract/baseapi.h>
@@ -56,83 +60,74 @@ namespace scribo
using namespace mln;
- /// Passes the text bboxes to Tesseract (OCR) and store the result in
- /// an image of characters.
+ /// Passes the text bboxes to Tesseract (OCR).
///
- /// \param[in] input_ image from where the text bboxes are extracted.
- /// \param[in] nbh_ The neighborhood used to label \p input_.
- /// \param[in] nbboxes The value type used in the labeled image.
- /// \param[in] textbboxes array of text bounding boxes.
+ /// \param[in] input_ Image from where the text is extracted.
+ /// \param[in] text The lines of text.
/// \param[in] language the language which should be recognized by Tesseract.
/// (fra, en, ...)
///
/// \return An image of characters.
- ///
- /// FIXME: For each text bbox, we create a new image. We may like to avoid that.
- /// FIXME: Do not store the result in an image?
- template <typename I, typename N, typename V>
+ template <typename I, typename L>
mln_ch_value(I,char)
text_recognition(const Image<I>& input_,
- const Neighborhood<N>& nbh_, const V& label_type,
- const scribo::util::text_bboxes<mln_ch_value(I,V)>& textbboxes,
+ const scribo::util::text<L>& text,
const char *language);
# ifndef MLN_INCLUDE_ONLY
- template <typename I, typename N, typename V>
+ template <typename I, typename L>
mln_ch_value(I,char)
text_recognition(const Image<I>& input_,
- const Neighborhood<N>& nbh_, const V& label_type,
- const scribo::util::text_bboxes<mln_ch_value(I,V)>& textbboxes,
+ const scribo::util::text<L>& text,
const char *language)
{
trace::entering("scribo::text::recognition");
mlc_equal(mln_value(I), bool)::check();
const I& input = exact(input_);
- const N& nbh = exact(nbh_);
mln_precondition(input.is_valid());
- mln_precondition(nbh.is_valid());
-
- V nbboxes;
- mln_ch_value(I,V) lbl = labeling::blobs(input, nbh, nbboxes);
+ mln_precondition(text.is_valid());
- /// Use text bboxes with Tesseract
+ // Initialize Tesseract.
TessBaseAPI::InitWithLanguage(NULL, NULL, language, NULL, false, 0, NULL);
+
mln_ch_value(I,char) txt(input.domain());
data::fill(txt, ' ');
- for_all_components(i, textbboxes)
+ /// Use text bboxes with Tesseract
+ for_all_components(i, text.bboxes())
{
- if (textbboxes[i].is_valid())
- {
- mln_ch_value(I,bool) b(textbboxes.bboxes()[i], 0);
- data::fill(b, false);
- data::fill((b | (pw::value(lbl) == pw::cst(i))).rw(), true);
-
- char* s = TessBaseAPI::TesseractRect(
- (unsigned char*) b.buffer(),
- sizeof (bool), // Pixel size.
- b.ncols() * sizeof (bool), // Row_offset
- 0, // Left
- 0, // Top
- b.ncols(), // n cols
- b.nrows()); // n rows
-
-
-
- mln_site(I) p = textbboxes.bboxes[i].center();
- p.col() -= (textbboxes.bboxes()[i].pmax().col()
- - textbboxes.bboxes()[i].pmin().col()) / 2;
- if (s != 0)
- debug::put_word(txt, p, s);
- free(s);
- }
+ mln_ch_value(I,bool) b(text.bbox(i), 0);
+ data::fill(b, false);
+ data::fill((b | (pw::value(text.label_image()) == pw::cst(i))).rw(),
+ true);
+
+ // Recognize characters.
+ char* s = TessBaseAPI::TesseractRect(
+ (unsigned char*) b.buffer(),
+ sizeof (bool), // Pixel size.
+ b.ncols() * sizeof (bool), // Row_offset
+ 0, // Left
+ 0, // Top
+ b.ncols(), // n cols
+ b.nrows()); // n rows
+
+
+
+ mln_site(I) p = text.bbox(i).center();
+ p.col() -= (text.bbox(i).pmax().col()
+ - text.bbox(i).pmin().col()) / 2;
+ if (s != 0)
+ debug::put_word(txt, p, s);
+
+ // The string has been allocated by Tesseract. We must free it.
+ free(s);
}
trace::exiting("scribo::text::recognition");
- return text;
+ return txt;
}
diff --git a/milena/sandbox/scribo/util/all.hh b/milena/sandbox/scribo/util/all.hh
new file mode 100644
index 0000000..1e97565
--- /dev/null
+++ b/milena/sandbox/scribo/util/all.hh
@@ -0,0 +1,48 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef SCRIBO_UTIL_ALL_HH
+# define SCRIBO_UTIL_ALL_HH
+
+/// \file scribo/util/all.hh
+///
+/// Include all headers located in scribo/util.
+
+namespace scribo
+{
+
+ /// Namespace of useful classes and routines.
+ namespace util
+ {
+
+ } // end of namespace scribo::util
+
+} // end of namespace scribo
+
+# include <scribo/util/text.hh>
+
+#endif // ! SCRIBO_UTIL_ALL_HH
diff --git a/milena/sandbox/scribo/util/text.hh b/milena/sandbox/scribo/util/text.hh
index 531d735..ceb5765 100644
--- a/milena/sandbox/scribo/util/text.hh
+++ b/milena/sandbox/scribo/util/text.hh
@@ -55,34 +55,65 @@ namespace scribo
class text
{
public:
+ /// The site type in the label image.
typedef mln_site(L) site;
+ /// The bounding box list type.
typedef mln::util::array<box<site> > boxes_t;
+ /// The mass center list type.
typedef mln::util::array<mln_site(L)::vec> mass_centers_t;
+ /// Constructors
+ /// @{
+
+ /// Default.
text();
+
+ /// \param[in] bboxes text line bounding boxes.
+ /// \param[in] lbl label image associated to the bounding boxes.
+ /// \param[in] nbboxes The number of bounding boxes.
+ /// \param[in] mass_centers Mass centers of the components.
text(const mln::util::array<box<mln_site(L)> >& bboxes,
const Image<L>& lbl,
const mln_value(L)& nbboxes,
const mln::util::array<mln_site(L)::vec>& mass_centers);
+
+ /// \param[in] bboxes text line bounding boxes.
+ /// \param[in] lbl label image associated to the bounding boxes.
+ /// \param[in] nbboxes The number of bounding boxes.
text(const mln::util::array<box<mln_site(L)> >& bboxes,
- const Image<L>& lbl,
- const mln_value(L)& nbboxes);
+ const Image<L>& lbl,
+ const mln_value(L)& nbboxes);
+ /// @}
+ /// Return the underlying label image.
const L& label_image() const;
+
+ /// Update the label image.
+ /// Note: Updating the label image update the bounding boxes
+ /// and the mass centers as well.
void set_label_image(const Image<L>& lbl);
+ /// Return the number of bounding boxes.
const mln_value(L)& nbboxes() const;
+ /// Return the number of bounding boxes.
mln_value(L)& nbboxes();
+ /// Return the bounding boxes.
const boxes_t& bboxes() const;
+ /// Return the bounding boxes.
boxes_t& bboxes();
+ /// Return the i-th bounding box.
const box<mln_site(L)>& bbox(unsigned i) const;
+ /// Return the i-th bounding box.
box<mln_site(L)>& bbox(unsigned i);
+ /// Return the mass centers.
const mln::util::array<mln_site(L)::vec>& mass_centers() const;
+ /// Return the i-th mass centers.
mln_site(L) mass_center(unsigned i) const;
+ /// Is this text objet consistant/valid?
bool is_valid() const;
private:
--
1.5.6.5
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-03-30 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Add a plot format save() routine.
* mln/io/plot/save.hh: New routine save() for saving arrays and
1d images into plot formatted file.
---
save.hh | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 110 insertions(+)
Index: trunk/milena/mln/io/plot/save.hh
===================================================================
--- trunk/milena/mln/io/plot/save.hh (revision 0)
+++ trunk/milena/mln/io/plot/save.hh (revision 3590)
@@ -0,0 +1,110 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_IO_PLOT_SAVE_HH
+# define MLN_IO_PLOT_SAVE_HH
+
+///
+/// \file mln/io/plot/save.hh
+///
+/// Define a routine which saves in a plot format.
+
+# include <mln/core/image/image1d.hh>
+# include <mln/metal/equal.hh>
+# include <mln/util/array.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/value/rgb8.hh>
+
+
+namespace mln
+{
+
+ namespace io
+ {
+
+ namespace plot
+ {
+
+ /*! Save a Milena 1D image in a plot file.
+ *
+ * \param[out] ima A reference to the image to save.
+ * \param[in] filename The output file.
+ */
+ template <typename I>
+ void save(image1d<I>& ima,
+ const std::string& filename);
+
+ /*! Save a Milena array in a plot file.
+ *
+ * \param[out] ima A reference to the array to save.
+ * \param[in] filename The output file.
+ */
+ template <typename I>
+ void save(util::array<I>& arr,
+ const std::string& filename);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ inline
+ void save(image1d<I>& ima, const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save");
+
+ std::ofstream file_out(filename.c_str());
+ for (unsigned i = 0; i < ima.ninds(); ++i)
+ file_out << i << ", " << ima.at_(i) << std::endl;
+
+ trace::exiting("mln::io::plot::save");
+ }
+
+ template <typename I>
+ inline
+ void save(util::array<I>& arr, const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save");
+
+ std::ofstream file_out(filename.c_str());
+ for (unsigned i = 0; i < arr.nelements(); ++i)
+ file_out << i << ", " << arr[i] << std::endl;
+
+ trace::exiting("mln::io::plot::save");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::io::plot
+
+ } // end of namespace mln::io
+
+} // end of namespace mln
+
+
+#endif // ! MLN_IO_PLOT_SAVE_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Write a solution for a common mistake.
* bugs/piter_slice.cc: Copy to...
* bugs/piter_slice.solved.cc: ...this new file.
Fix bug.
piter_slice.solved.cc | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
Index: bugs/piter_slice.solved.cc
--- bugs/piter_slice.solved.cc (revision 3588)
+++ bugs/piter_slice.solved.cc (working copy)
@@ -19,12 +19,17 @@
using namespace mln;
using value::int_u12;
- image3d<int_u12> ima(150, 256, 256);
+ typedef image2d<int_u12> I;
+
+ image3d<int_u12> ima(15, 25, 25);
image2d<util::array<int_u12> > ima_arr(ima.nrows(), ima.ncols());
- mln_piter_(image2d<int_u12>) p(slice(ima, 0).domain());
+
+ box2d b = slice(ima, 0).domain();
+ mln_piter_(I) p(b); // b is not a temporary object, so that's ok
+
for (int i = 0; i < ima.nslices(); ++i)
{
- image2d<int_u12> tmp_slice = duplicate(slice(ima, i));
+ I tmp_slice = duplicate(slice(ima, i));
for_all(p)
{
ima_arr(p).append(tmp_slice(p));
Property changes on: bugs/piter_slice.solved.cc
___________________________________________________________________
Added: svn:mergeinfo
1
0
30 Mar '09
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-30 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Add a test file for a bug involving slice() and piter.
* bugs/piter_slice.cc: New test file.
---
piter_slice.cc | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
Index: trunk/milena/sandbox/bugs/piter_slice.cc
===================================================================
--- trunk/milena/sandbox/bugs/piter_slice.cc (revision 0)
+++ trunk/milena/sandbox/bugs/piter_slice.cc (revision 3588)
@@ -0,0 +1,33 @@
+/*
+** Creating a piter onb a slice causes bugs. The iterator takes
+** erroneous values.
+*/
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/slice_image.hh>
+#include <mln/core/routine/duplicate.hh>
+
+#include <mln/value/int_u12.hh>
+
+#include <mln/util/array.hh>
+
+
+
+int main(int, char*argv[])
+{
+ using namespace mln;
+ using value::int_u12;
+
+ image3d<int_u12> ima(150, 256, 256);
+ image2d<util::array<int_u12> > ima_arr(ima.nrows(), ima.ncols());
+ mln_piter_(image2d<int_u12>) p(slice(ima, 0).domain());
+ for (int i = 0; i < ima.nslices(); ++i)
+ {
+ image2d<int_u12> tmp_slice = duplicate(slice(ima, i));
+ for_all(p)
+ {
+ ima_arr(p).append(tmp_slice(p));
+ }
+ }
+}
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Change histogram printing.
* mln/debug/histo.hh: Remove overload for std::vector.
Use values instead of indices.
* mln/histo/array.hh (operator=),
(cpy ctor): New.
* mln/accu/stat/variance.hh: New.
accu/stat/variance.hh | 201 +++++++++++++++++++++++++++++++-------------------
debug/histo.hh | 28 +++---
histo/array.hh | 22 +++++
3 files changed, 162 insertions(+), 89 deletions(-)
Index: mln/debug/histo.hh
--- mln/debug/histo.hh (revision 3586)
+++ mln/debug/histo.hh (working copy)
@@ -31,7 +31,9 @@
/// \file mln/debug/histo.hh
///
-/// save a histogram to a plot data file.
+/// Save a histogram to a plot data file.
+///
+/// \todo Move to io::histo::save.
# include <iostream>
# include <fstream>
@@ -41,6 +43,7 @@
# include <mln/core/image/image2d.hh>
# include <mln/draw/line.hh>
+
namespace mln
{
@@ -48,32 +51,27 @@
{
+ template <typename T>
void
- histo(const histo::array<unsigned>& h, const std::string& filename);
+ histo(const histo::array<T>& h, const std::string& filename);
- void
- histo(const std::vector<unsigned>& h, const std::string& filename);
-# ifndef MLN_INCLUDE_ONLY
- void
- histo(const histo::array<unsigned>& h, const std::string& filename)
- {
- histo(h.vect(), filename);
- }
+# ifndef MLN_INCLUDE_ONLY
+ template <typename T>
void
- histo(const std::vector<unsigned>& h, const std::string& filename)
+ histo(const histo::array<T>& h, const std::string& filename)
{
std::ofstream file(filename.c_str());
if (! file)
{
std::cerr << "error: cannot open file '" << filename << "'!";
- abort();
+ std::abort();
}
-
- for (unsigned i = 0; i < h.size(); ++i)
- file << i << ' ' << h[i] << std::endl;
+ mln_viter(value::set<T>) v(h.vset());
+ for_all(v)
+ file << v << ' ' << h(v) << std::endl;
}
Index: mln/histo/array.hh
--- mln/histo/array.hh (revision 3586)
+++ mln/histo/array.hh (working copy)
@@ -54,6 +54,9 @@
array();
+ array(const array& other);
+ array& operator=(const array& other);
+
void clear();
unsigned operator()(const T& v) const;
@@ -91,6 +94,25 @@
template <typename T>
inline
+ array<T>::array(const array& other)
+ : s_(other.s_),
+ h_(other.h_)
+ {
+ }
+
+ template <typename T>
+ inline
+ array<T>&
+ array<T>::operator=(const array& other)
+ {
+ if (&other == this)
+ return *this;
+ h_ = other.h_;
+ return *this;
+ }
+
+ template <typename T>
+ inline
void
array<T>::clear()
{
Index: mln/accu/stat/variance.hh
--- mln/accu/stat/variance.hh (revision 3570)
+++ mln/accu/stat/variance.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 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
@@ -26,18 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_ACCU_STAT_DEVIATION_HH
-# define MLN_ACCU_STAT_DEVIATION_HH
+#ifndef MLN_ACCU_STAT_VARIANCE_HH
+# define MLN_ACCU_STAT_VARIANCE_HH
-/// \file mln/accu/stat/deviation.hh
+/// \file mln/accu/stat/variance.hh
///
-/// Define an accumulator that computes a standard deviation.
+/// Define an accumulator that computes the variance of a set of values.
+# include <cmath>
# include <mln/accu/internal/base.hh>
-# include <mln/accu/count.hh>
-# include <mln/accu/sum.hh>
-# include <mln/math/sqr.hh>
-# include <mln/math/sqrt.hh>
namespace mln
@@ -49,34 +45,51 @@
namespace stat
{
- /// Generic standard deviation accumulator class.
+ /// Variance accumulator class.
/*!
- * Parameter \c T is the type of values that we sum. Parameter \c
- * S is the type to store the standard deviation; the default type of
- * \c S is the summation type (property) of \c T. Parameter \c M
- * is the type of the mean value; the default type of \c M is \c
- * S.
+ * Parameter \c T is the type of values that we sum. Parameter
+ * \c S is the type to store the value sum and the sum of value
+ * * value; the default type of \c S is the summation type
+ * (property) of \c T. Parameter \c R is the type of the mean
+ * and variance values; the default type of \c R is \c S.
*/
template <typename T,
typename S = mln_sum(T),
- typename M = S>
- struct deviation : public mln::accu::internal::base< M , deviation<T,S,M> >
+ typename R = S>
+ struct variance : public mln::accu::internal::base< R , variance<T,S,R> >
{
typedef T argument;
- typedef M result;
+ typedef R result;
- deviation(const T mean);
+ variance();
/// Manipulators.
/// \{
void init();
+ void take_as_init(const argument& t);
void take(const argument& t);
- void take(const deviation<T,S,M>& other);
+ void take(const variance<T,S,R>& other);
+
+ void take(unsigned n_times, const argument& t); // Extra.
/// \}
- /// Get the value of the accumulator.
- M to_result() const;
- operator M () const;
+ /// Get the accumulator result (the variance value).
+ R to_result() const;
+
+ /// Get the variance value.
+ R var() const;
+
+ /// Get the standard deviation value.
+ R standard_deviation() const;
+
+ /// Get the mean value.
+ R mean() const;
+
+ /// Get the sum value.
+ S sum() const;
+
+ /// Get the number of items.
+ unsigned n_items() const;
/// Check whether this accu is able to return a result.
/// Always true here.
@@ -84,96 +97,136 @@
protected:
- accu::count<T> count_;
- accu::sum<T,S> sum_;
- T mean_;
+ unsigned n_;
+ S sum_, sum2_;
};
- template <typename I, typename S, typename M>
- struct deviation< util::pix<I>, S,M >;
+ template <typename I, typename S, typename R>
+ struct variance< util::pix<I>, S,R >;
- namespace meta
- {
- /// Meta accumulator for deviation.
- struct deviation : public Meta_Accumulator< deviation >
- {
- template < typename T,
- typename S = mln_sum(T),
- typename M = S >
- struct with
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename S, typename R>
+ inline
+ variance<T,S,R>::variance()
{
- typedef accu::stat::deviation<T,S,M> ret;
- };
- };
+ init();
+ }
- } // end of namespace mln::accu::meta
+ template <typename T, typename S, typename R>
+ inline
+ void
+ variance<T,S,R>::init()
+ {
+ n_ = 0;
+ sum_ = sum2_ = 0;
+ }
+ template <typename T, typename S, typename R>
+ inline
+ void
+ variance<T,S,R>::take(const argument& t)
+ {
+ ++n_;
+ sum_ += t;
+ sum2_ += t * t;
+ }
-# ifndef MLN_INCLUDE_ONLY
+ template <typename T, typename S, typename R>
+ inline
+ void
+ variance<T,S,R>::take(unsigned n_times, const argument& t)
+ {
+ if (n_times == 0u)
+ return;
+ n_ += n_times;
+ sum_ += n_times * t;
+ sum2_ += n_times * t * t;
+ }
- template <typename T, typename S, typename M>
+ template <typename T, typename S, typename R>
inline
- deviation<T,S,M>::deviation(const T mean)
+ void
+ variance<T,S,R>::take_as_init(const argument& t)
{
- init();
- mean_ = mean;
+ n_ = 1;
+ sum_ = t;
+ sum2_ = t * t;
}
- template <typename T, typename S, typename M>
+ template <typename T, typename S, typename R>
inline
void
- deviation<T,S,M>::init()
+ variance<T,S,R>::take(const variance<T,S,R>& other)
{
- count_.init();
- sum_.init();
+ n_ += other.n_;
+ sum_ += other.sum_;
+ sum2_ += other.sum2_;
}
- template <typename T, typename S, typename M>
+ template <typename T, typename S, typename R>
inline
- void deviation<T,S,M>::take(const argument& t)
+ R
+ variance<T,S,R>::to_result() const
{
- count_.take(t);
- sum_.take(math::sqr(t - mean_));
+ if (n_ == 0u)
+ return 0; // Safety.
+ S m_ = sum_ / n_;
+ return sum2_ / n_ - m_ * m_;
}
- template <typename T, typename S, typename M>
+ template <typename T, typename S, typename R>
inline
- void
- deviation<T,S,M>::take(const deviation<T,S,M>& other)
+ R
+ variance<T,S,R>::mean() const
+ {
+ if (n_ == 0u)
+ return 0; // Safety.
+ return sum_ / n_;
+ }
+
+ template <typename T, typename S, typename R>
+ inline
+ S
+ variance<T,S,R>::sum() const
{
- // FIXME
- count_.take(other.count_);
- sum_.take(other.sum_);
+ return sum_;
}
- template <typename T, typename S, typename M>
+ template <typename T, typename S, typename R>
inline
- M
- deviation<T,S,M>::to_result() const
+ unsigned
+ variance<T,S,R>::n_items() const
{
- unsigned n = count_.to_result();
- if (n == 0u)
- return M(); // Safety.
- return static_cast<M>(math::sqrt(sum_.to_result() / n));
+ return n_;
}
- template <typename T, typename S, typename M>
+ template <typename T, typename S, typename R>
inline
- deviation<T,S,M>::operator M() const
+ R
+ variance<T,S,R>::var() const
{
return to_result();
}
- template <typename T, typename S, typename M>
+ template <typename T, typename S, typename R>
+ inline
+ R
+ variance<T,S,R>::standard_deviation() const
+ {
+ return std::sqrt(to_result());
+ }
+
+ template <typename T, typename S, typename R>
inline
bool
- deviation<T,S,M>::is_valid() const
+ variance<T,S,R>::is_valid() const
{
- return count_.to_result() != 0;
+ return n_ != 0;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -185,4 +238,4 @@
} // end of namespace mln
-#endif // ! MLN_ACCU_STAT_DEVIATION_HH
+#endif // ! MLN_ACCU_STAT_VARIANCE_HH
Property changes on: mln/accu/stat/variance.hh
___________________________________________________________________
Added: svn:mergeinfo
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 exec files.
* exec/filetype.hh: New.
* exec/histo_save.cc: New.
* theo/exec/closing_height.cc: New.
exec/histo_save.cc | 46 +++++++++++++++++++++++++++++++++
theo/exec/closing_height.cc | 60 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 106 insertions(+)
Property changes on: exec/filetype.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: exec/histo_save.cc
--- exec/histo_save.cc (revision 0)
+++ exec/histo_save.cc (revision 0)
@@ -0,0 +1,46 @@
+#include "filetype.hh"
+
+#include <mln/histo/compute.hh>
+#include <mln/debug/histo.hh>
+
+#include <mln/core/image/image_if.hh>
+#include <mln/pw/all.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.pgm [mask.pbm] output.txt" << std::endl
+ << " Compute an histogram." << std::endl
+ << " Input images are 2D." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 3 && argc != 4)
+ usage(argv);
+
+ trace::entering("main");
+
+ image2d<int_u8> input;
+ io::pgm::load(input, argv[1]);
+
+ histo::array<int_u8> h;
+ if (argc == 3)
+ h = histo::compute(input);
+ else
+ {
+ image2d<bool> mask;
+ io::pbm::load(mask, argv[2]);
+ h = histo::compute(input | pw::value(mask));
+ }
+ debug::histo(h, argv[argc - 1]);
+
+ trace::exiting("main");
+}
Index: theo/exec/closing_height.cc
--- theo/exec/closing_height.cc (revision 0)
+++ theo/exec/closing_height.cc (revision 0)
@@ -0,0 +1,60 @@
+#include "filetype.hh"
+#include <mln/morpho/closing/height.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.xxx lambda output.xxx" << std::endl
+ << " Height closing." << std::endl
+ << " xxx in { pgm, dump }" << 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");
+
+ std::string filename = argv[1];
+ unsigned lambda = atoi(argv[2]);
+
+ switch (get_filetype(argv[1]))
+ {
+ case filetype::pgm:
+ {
+ image2d<int_u8> ima, clo;
+ io::pgm::load(ima, argv[1]);
+ clo = morpho::closing::height(ima, c4(), lambda);
+ io::pgm::save(clo, argv[3]);
+ }
+ break;
+
+ case filetype::dump:
+ {
+ image3d<int_u8> ima, clo;
+ io::dump::load(ima, argv[1]);
+ clo = morpho::closing::height(ima, c6(), lambda);
+ io::dump::save(clo, argv[3]);
+ }
+ break;
+
+ case filetype::unknown:
+ std::cerr << "unknown filename extension!" << std::endl;
+ usage(argv);
+ break;
+
+ default:
+ std::cerr << "file type not handled!" << std::endl;
+ usage(argv);
+ }
+
+ trace::exiting("main");
+}
1
0