Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
* 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
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-27 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Update IGR related code.
* fabien/igr/Makefile: Update.
* fabien/igr/matlab.cc: Update.
* fabien/igr/time_max.cc: Create tmax image.
---
TODO | 5
igr/Makefile | 46 +++-----
igr/matlab.cc | 296 ++++++++++++++++++++++++++++++++++----------------------
igr/time_max.cc | 113 +++++++++++++++++++++
4 files changed, 318 insertions(+), 142 deletions(-)
Index: trunk/milena/sandbox/fabien/igr/matlab.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/matlab.cc (revision 3584)
+++ trunk/milena/sandbox/fabien/igr/matlab.cc (revision 3585)
@@ -36,6 +36,8 @@
mln_precondition(first >=0 && first < arr_ima.nelements());
mln_precondition(last >=0 && last < arr_ima.nelements());
+ initialize(result, arr_ima[first]);
+
accu::image::init(result);
for (int i = first; i < last; ++i)
accu::image::take(result, arr_ima[i]);
@@ -58,10 +60,10 @@
for (int i = 0; i < input.nslices(); ++i)
arr_ima.append(duplicate(cast_image<float>(slice(input, i))));
- int acqui = 3; // durée acqui et temps interimages; en secondes
- int fseuil = 4; // ratio entre signaux trop faibles, éliminés, et bruit de fond mesuré sur l image
- int ini = 9; // nombre images ligne de base
- int ini2 = 20; // a la fin de la montée vasculaire, à la dixieme image post injection: lissage des images par trois
+ const int acqui = 3; // durée acqui et temps interimages; en secondes
+ const int fseuil = 4; // ratio entre signaux trop faibles, éliminés, et bruit de fond mesuré sur l image
+ const int ini = 9; // nombre images ligne de base
+ const int ini2 = 20; // a la fin de la montée vasculaire, à la dixieme image post injection: lissage des images par trois
// Calcul signal initialmoyen : 8 images de 2 à 9 moyennées=ligne de base
image2d<float> imageini = mean_slices(arr_ima, 1, 8);
@@ -86,10 +88,19 @@
data::fill(prodsignal1, 0.0);
data::paste(datasli | pw::value(roi_noise) == pw::cst(true), prodsignal1);
- // moyenne
+ /////////////
+ // //
+ // Moyenne //
+ // //
+ /////////////
accu::mean<float> accu_mean;
float moysignal1 = level::compute(accu_mean, prodsignal1 | pw::value(roi_noise) == pw::cst(true));
- // ecart type
+
+ ////////////////
+ // //
+ // Ecart type //
+ // //
+ ////////////////
int som1 = 0;
int kk = 0;
mln_piter_(image2d<float>) p(datasli.domain());
@@ -99,11 +110,16 @@
float ectys = std::sqrt(som1 / (nbrpix1 - 1));
float seuil = fseuil * ectys;
- // Calcul du masque
+ //////////////////////
+ // //
+ // Calcul du masque //
+ // //
+ //////////////////////
image2d<bool> masque;
initialize(masque, datasli);
data::fill(masque, false);
data::fill((masque | pw::value(datasli) > pw::cst(seuil)).rw(), true);
+
// si on a choisi une région avec roi
int nargin = 0;
image2d<bool> roi; // FIXME: init this ROI, should be a domain
@@ -123,6 +139,12 @@
// On cherche les maxi (intensité ima_c et temps ima_t) des courbes signal(temps)
// On masque toute la série d'images
+ /////////////
+ // //
+ // Lissage //
+ // //
+ /////////////
+
// Essai de lissage à parir de fin de montée vaculaire ini2 pour ameliorer
// les seuillages a 10 50 90 NON EVALUE RIGOUREUSEMENT
util::array<image2d<double> > arr_smooth;
@@ -131,17 +153,33 @@
arr_smooth.append(arr_ima[k] * 0.5 + arr_ima[k - 1] * 0.25 + arr_ima[k + 1] * 0.25);
arr_smooth.append(arr_ima[dim3 - 1] * 1.0);
+ ///////////////////////////////////
+ // //
+ // Calcul image max et temps max //
+ // //
+ ///////////////////////////////////
+ image2d<float> ima_c;
+ initialize(ima_c, arr_smooth[0]);
+ data::fill(ima_c, 0.0);
+ image2d<unsigned> ima_t;
+ initialize(ima_t, ima_c);
for_all(p)
if (masque(p) == false)
{
for (int k = 0; k < arr_smooth.nelements(); ++k)
arr_smooth[k](p) = 0.0;
ima_c(p) = 0.0;
- ima_t(p) = 0.0;
+ ima_t(p) = 0;
++kk;
}
- // FIXME: [c,T]=max(image,[ ],3);
+ for_all(p)
+ for (unsigned k = 0; k < dim3; ++k)
+ if (ima_c(p) < arr_smooth[k](p))
+ {
+ ima_c(p) = arr_smooth[k](p);
+ ima_t(p) = k;
+ }
// Ou 'ima_c' est la valeur du max et 'ima_t' son index, le long de la dimension 3
// kk est le nombre de points masques
@@ -149,151 +187,179 @@
std::cout << "kk = " << kk << std::endl;
image2d<accu::sum<float> > accu_sum;
- accu::image::init(result);
- for (int i = first; i < last; ++i)
- accu::image::take(result, arr_ima[i]);
- ima_auc accu::image::to_result(result);
+ accu::image::init(accu_sum);
+ for (int k = 0; k < dim3; ++k)
+ accu::image::take(accu_sum, arr_smooth[k]);
+ image2d<float> ima_auc = accu::image::to_result(accu_sum);
// Conversion du temps du pic en secondes à partir fin période de base
- tmax = acqui * (ima_t - ini);
+ image2d<int> tmax = acqui * (ima_t - ini);
// calcul des temps 10 et 90 et de la pente correspondante
- for (int i = 0; i < dim1; ++i)
- for (int j = 0; j < dim2; ++j)
+ image2d<float> ima_c10;
+ initialize(ima_c10, arr_smooth[0]);
+ data::fill(ima_c10, 0.0);
+ image2d<unsigned> ima_idx10;
+ initialize(ima_idx10, ima_c10);
+ bool set_10 = false;
+
+ image2d<float> ima_c90;
+ initialize(ima_c90, arr_smooth[0]);
+ data::fill(ima_c90, 0.0);
+ image2d<unsigned> ima_idx90;
+ initialize(ima_idx90, ima_c90);
+ bool set_90 = false;
+
+ image2d<float> ima_c50;
+ initialize(ima_c50, arr_smooth[0]);
+ data::fill(ima_c50, 0.0);
+ image2d<unsigned> ima_idx50;
+ initialize(ima_idx50, ima_c50);
+ bool set_50 = false;
+
+ image2d<bool> masque2;
+ initialize(masque2, arr_smooth[0]);
+
+ // FIXME: This could be done with a bkw_piter.
+ for_all(p)
{
- [C10(i,j),idx_10(i,j)]=max(image(i,j,:)>=0.1*c(i,j));
- [C90(i,j),idx_90(i,j)]=max(image(i,j,:)>=0.9*c(i,j));
- [C50(i,j),idx_50(i,j)]=max(image(i,j,:)>=0.5*c(i,j));
- if (idx_90(i,j)-idx_10(i,j)==0)
- masque2(i,j)=0;
- else
- masque2(i,j)=1;
+ for (unsigned k = 0; k < dim3; ++k)
+ {
+ if (!set_10 && arr_smooth[k](p) >= 0.1 * ima_c(p))
+ {
+ ima_c10(p) = arr_smooth[k](p);
+ ima_idx10(p) = k;
+ set_10 = true;
+ }
+ if (!set_90 && arr_smooth[k](p) >= 0.9 * ima_c(p))
+ {
+ ima_c90(p) = arr_smooth[k](p);
+ ima_idx90(p) = k;
+ set_90 = true;
+ }
+ if (!set_50 && arr_smooth[k](p) >= 0.5 * ima_c(p))
+ {
+ ima_c50(p) = arr_smooth[k](p);
+ ima_idx50(p) = k;
+ set_50 = true;
+ }
+ }
+ masque2(p) = (ima_idx90(p) != ima_idx10(p));
}
- // calcul MTT
+ ////////////////
+ // //
+ // Calcul MTT //
+ // //
+ ////////////////
// QUAND le signal redescent significativement après le maximum
// elimination des voxels où le signal est encore 90// du maximum en fin
// d'acquisition
+ image2d<bool> masque3;
+ initialize(masque3, masque2);
int kk2 = 0;
- for (int i = 0; i < dim1; ++i)
- for (int j = 0; j < dim2; ++j)
- if (image(i,j,dim3)>=0.9*c(i,j))
+ for_all(p)
+ if (arr_smooth[dim3 - 1](p) >= 0.9 * ima_c(p))
{
- masque3(i,j)=0;
- kk2=kk2+1;
+ masque3(p) = false;
+ ++kk2;
}
else
- masque3(i,j)=1;
+ masque3(p) = true;
// pour les voxels non masqués on inverse t et on cherche le max 50// a partir de la fin
- for (int i = 0; i < dim1; ++i)
- for (int j = 0; j < dim2; ++j)
+ util::array<image2d<float> > arr_inv;
for (int k = 0; k < dim3; ++k)
- imageinv(i,j,k)=masque3(i,j)*image(i,j,dim3+1-k);
+ {
+ arr_inv.append(arr_ima[dim3 - 1 - k]);
+ data::fill((arr_inv[k] | pw::value(masque3) == false).rw(), 0.0);
+ }
- for (int i = 0; i < dim1; ++i)
- for (int j = 0; j < dim2; ++j)
- if (masque3(i,j)==0)
+ image2d<float> ima_c51;
+ initialize(ima_c51, arr_smooth[0]);
+ data::fill(ima_c51, 0.0);
+ image2d<unsigned> ima_idx51;
+ initialize(ima_idx51, ima_c51);
+ bool set_51 = false;
+ for_all(p)
+ {
+ if (masque3(p))
{
- idx_51(i,j)=0;
- C51(i,j)=0;
+ for (unsigned k = 0; k < dim3; ++k)
+ if (!set_50 && arr_smooth[k](p) >= 0.8 * ima_c(p))
+ {
+ ima_c51(p) = arr_inv[k](p);
+ ima_idx51(p) = k;
+ set_51 = true;
+ }
}
else
- [C51(i,j),idx_51(i,j)]=max(imageinv(i,j,:)>=0.8*c(i,j));
+ {
+ ima_c51(p) = 0;
+ ima_idx51(p) = 0;
+ }
+ }
std::cout << "kk2 = " << kk2 << std::endl;
// Calcul MTT defini comme largeur a mi hauteur de la courbe signal(temps)
// soit t50 montant et t50 descendant
- for (int i = 0; i < dim1; ++i)
- for (int j = 0; j < dim2; ++j)
- if (masque(i,j)*masque2(i,j)*masque3(i,j)==0)
- MTT(i,j)=0;
- else
- MTT(i,j)=acqui*(dim3-idx_51(i,j)-idx_50(i,j));
+ image2d<int> ima_mtt;
+ initialize(ima_mtt, masque);
+ data::fill(ima_mtt, 0);
+ for_all(p)
+ if (masque(p) && masque2(p) && masque3(p))
+ ima_mtt(p) = acqui * (dim3 - ima_idx51(p) - ima_idx50(p));
// calcul de la pente 10/90 (avec delta signal=80// du maximum c(i,j) et
// delta temps =t90 -t10
- for (int i = 0; i < dim1; ++i)
- for (int j = 0; j < dim2; ++j)
- if (masque(i,j)*masque2(i,j)==0)
- pente(i,j)=0;
- else
- pente(i,j)=(0.8*c(i,j))/(acqui*(idx_90(i,j)-idx_10(i,j)));
+ image2d<float> ima_pente;
+ initialize(ima_pente, masque);
+ data::fill(ima_pente, 0);
+ for_all(p)
+ if (masque(p) && masque2(p))
+ ima_pente(p) = (0.8 * ima_c(p)) / (acqui * (ima_idx90(p) - ima_idx10(p)));
- // calcul pente normalisée rehaussement normalisé et AUC normalisée
- for (int i = 0; i < dim1; ++i)
- for (int j = 0; j < dim2; ++j)
- if (masque(i,j)==0)
- {
- pentenorm(i,j)=0;
- reh(i,j)=0;
- AUCnorm(i,j)=0;
- }
- else
+ ////////////////////////////////////////////////
+ // //
+ // Normalisation de la pente, du rehaussement //
+ // et de l'AUC //
+ // //
+ ////////////////////////////////////////////////
+ image2d<float> ima_pentenorm;
+ initialize(ima_pentenorm, masque);
+ data::fill(ima_pentenorm, 0);
+
+ image2d<float> ima_reh;
+ initialize(ima_reh, masque);
+ data::fill(ima_reh, 0);
+
+ image2d<float> ima_aucnorm;
+ initialize(ima_aucnorm, masque);
+ data::fill(ima_aucnorm, 0);
+
+ for_all(p)
+ if (masque(p))
{
- pentenorm(i,j)=pente(i,j)/imageini(i,j);
- reh(i,j)=c(i,j)/imageini(i,j);
- AUCnorm(i,j)=AUC(i,j)/imageini(i,j);
- }
-
- /*figure (3)
- imagesc(AUCnorm);
- title('image aire normalisée sous la courbe');
- // l'aire sous la courbe est négative là où il y a eu du bougé (bord tube)
-
-
- figure (4)
- imagesc(pentenorm);
- title('pente normalisée10-90');
-
- figure(5)
- imagesc(reh);
- title('image rehaussement relatif');
- caxis([0 5]);
- // au dela de 5 il faut réviser la dose d'agent de contraste car surdosage
-
- figure(6)
- imagesc(MTT);
- title('image MTT');
-
- figure(9)
- imagesc(idx_51);
- title('idx_51');
-
- figure(10)
- imagesc(C51);
-
- figure(7)
- imagesc(tmax);
- title('image Tmaximum');
-
- figure(8)
- subplot(2,2,1);
- imagesc(pentenorm);
- title('pente normalisée10-90');
- subplot(2,2,2)
- imagesc(reh);
- title('image rehaussement relatif');
- caxis([0 3]);
- subplot(2,2,3)
- imagesc(tmax);
- title('image Tmaximum');*/
+ ima_pentenorm(p) = ima_pente(p) / imageini(p);
+ ima_reh(p) = ima_c(p) / imageini(p);
+ ima_aucnorm(p) = ima_auc(p) / imageini(p);
+ }
// COURBE S(t)sur pixel choisi graphiquement
// Permet de voir la courbe de rehaussement d'un voxel pointé
// SI LE VOXEL EST AU BORD DU TUBE TEMOIN: UN DETECTEUR DE MOUVEMENTS
// coordonx=1:size(image,3);
- x = size(image, 1) / 2;
- y = size(image, 2) / 2;
- while (x < size(image, 1) && y < size(image, 2))
+ float x = masque.nrows() / 2;
+ float y = masque.ncols() / 2;
+ /*while (x < masque.nrows() && y < masque.ncols())
{
// la saisie du point de coordonnées x,y se fait sur la figure ouverte en
// dernier
// pour sortir: cliquer dans le gris...
// pour affichage interactif coordonnées pixel, mais en fait pas utile
- h=figure(8)
+ h=figure(8);
pixval;
// saisie coordonnées du pixel pour lequel on veut afficher la courbe de
// décroissance et le fit
@@ -305,12 +371,12 @@
// test sortie du programme
if ((coordx > size(image, 1)) | (coordy > size(image, 2)))
break;
- fprintf(1,'\n// d\t// d\t// f\t// f\n',coordx,coordy,reh(coordx,coordy),image(coordx,coordy,1));
+ fprintf(1,"\n// d\t// d\t// f\t// f\n",coordx,coordy,reh(coordx,coordy),image(coordx,coordy,1));
titi = (abs(image(coordx, coordy, :)));
tata = squeeze(titi);
- subplot(2,2,4)
+ subplot(2,2,4);
plot(tata);
- }
+ }*/
return 0;
}
Index: trunk/milena/sandbox/fabien/igr/time_max.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/time_max.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/time_max.cc (revision 3585)
@@ -0,0 +1,113 @@
+#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_u8.hh>
+#include <mln/value/int_u12.hh>
+
+#include <mln/io/dicom/load.hh>
+#include <mln/io/magick/save.hh>
+
+#include <mln/accu/count.hh>
+#include <mln/accu/mean.hh>
+#include <mln/accu/sum.hh>
+#include <mln/accu/image/all.hh>
+
+#include <mln/arith/minus.hh>
+#include <mln/arith/all.hh>
+
+#include <mln/data/fill.hh>
+#include <mln/data/paste.hh>
+
+#include <mln/level/compute.hh>
+#include <mln/level/stretch.hh>
+
+#include <mln/math/abs.hh>
+#include <mln/pw/all.hh>
+#include <mln/trait/concrete.hh>
+#include <mln/util/array.hh>
+
+#include <cmath>
+
+using namespace mln;
+using value::int_u8;
+
+
+inline
+image2d<float> mean_slices(util::array<image2d<float> >& arr_ima, int first, int last)
+{
+ image2d<accu::mean<float> > result;
+
+ mln_precondition(first >=0 && first < arr_ima.nelements());
+ mln_precondition(last >=0 && last < arr_ima.nelements());
+
+ initialize(result, arr_ima[first]);
+
+ accu::image::init(result);
+ for (int i = first; i < last; ++i)
+ accu::image::take(result, arr_ima[i]);
+
+ return accu::image::to_result(result);
+}
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << " input" << std::endl;
+ return 1;
+ }
+
+ image3d<value::int_u12> input;
+ io::dicom::load(input, argv[1]);
+ util::array<image2d<float> > arr_ima;
+ for (unsigned int i = 0; i < input.nslices(); ++i)
+ arr_ima.append(duplicate(cast_image<float>(slice(input, i))));
+
+ // Calcul signal initialmoyen : 8 images de 2 à 9 moyennées=ligne de base
+ image2d<float> imageini = mean_slices(arr_ima, 1, 8);
+
+ unsigned dim3 = arr_ima.nelements();
+
+ /////////////
+ // //
+ // Lissage //
+ // //
+ /////////////
+ util::array<image2d<double> > arr_smooth;
+ arr_smooth.append(arr_ima[0] * 1.0);
+ for (unsigned k = 1; k < dim3 - 1; ++k)
+ arr_smooth.append(arr_ima[k] * 0.5 + arr_ima[k - 1] * 0.25 + arr_ima[k + 1] * 0.25);
+ arr_smooth.append(arr_ima[dim3 - 1] * 1.0);
+
+ ///////////////////////////////////
+ // //
+ // Calcul image max et temps max //
+ // //
+ ///////////////////////////////////
+ image2d<float> ima_c;
+ initialize(ima_c, arr_smooth[0]);
+ data::fill(ima_c, 0.0);
+ image2d<unsigned> ima_t;
+ initialize(ima_t, ima_c);
+ data::fill(ima_c, 0);
+ mln_piter_(image2d<float>) p(ima_c.domain());
+ for_all(p)
+ for (unsigned k = 0; k < dim3; ++k)
+ if (ima_c(p) < arr_ima[k](p))
+ {
+ ima_c(p) = arr_ima[k](p);
+ ima_t(p) = k;
+ }
+
+ image2d<int_u8> result_c = level::stretch(int_u8(), ima_c);
+ image2d<int_u8> result_t = level::stretch(int_u8(), ima_t);
+ io::magick::save(result_c, "result_max.png");
+ io::magick::save(result_t, "result_time.png");
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/Makefile
===================================================================
--- trunk/milena/sandbox/fabien/igr/Makefile (revision 3584)
+++ trunk/milena/sandbox/fabien/igr/Makefile (revision 3585)
@@ -1,38 +1,30 @@
CXX = llvm-g++
-DCM_SRC=/Users/HiSoKa/Downloads/gdcm-2.0.10
-DCM_BIN=/Users/HiSoKa/Downloads/gdcmbin
-DICOM_INC = -I${DCM_SRC}/Source/Common/ \
- -I${DCM_BIN}/Source/Common/ \
- -I${DCM_SRC}/Source/DataDictionary/ \
- -I${DCM_SRC}/Source/MediaStorageAndFileFormat/ \
- -I${DCM_SRC}/Source/DataStructureAndEncodingDefinition/
-DICOM_LIBS = -L${DCM_BIN}/bin \
- -lgdcmCommon -lgdcmDICT -lgdcmDSED -lgdcmIOD -lgdcmMSFF -lgdcmexpat -lgdcmjpeg12 -lgdcmjpeg16 -lgdcmjpeg8 -lgdcmopenjpeg -lgdcmuuid -lgdcmzlib \
+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
-CXXFLAGS = -DNDEBUG -O1
+DICOM = ${DICOM_INC} ${DICOM_LIBS}
-all: 2d 3d wsd2d wsd3d grad
+MAGICK = `Magick++-config --cppflags --ldflags --libs`
-2d: seg_vol_irm.hh seg2d.cc
- ${CXX} -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} seg2d.cc -o seg2d
+seg2d: seg_vol_irm.hh seg2d.cc
+ ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} seg2d.cc -o seg2d
-3d: seg_vol_irm.hh seg3d.cc
- ${CXX} -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} seg3d.cc -o seg3d
+seg3d: seg_vol_irm.hh seg3d.cc
+ ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} seg3d.cc -o seg3d
wsd2d: watershed.hh watershed2d.cc
- ${CXX} -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} $^ -o wsd2d
+ ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o wsd2d
wsd3d: watershed.hh watershed3d.cc
- ${CXX} -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} $^ -o wsd3d
-
-wsd3dg: watershed.hh watershed3d.cc
- ${CXX} -I../../../ ${DICOM_INC} ${DICOM_LIBS} -g $^ -o wsd3dg
+ ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o wsd3d
nbasins: nbasins_finder.cc
- ${CXX} -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} $^ -o nbasins_finder
+ ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o nbasins_finder
grad: grad.cc
- ${CXX} -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} $^ -o grad
+ ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o grad
clo_vol: clo_vol.cc
${CXX} -I../../../ ${CXXFLAGS} $^ -o clo_vol
@@ -41,16 +33,20 @@
${CXX} -I../../../ ${CXXFLAGS} $^ -o wst
graph: graph.cc
- ${CXX} -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} $^ -o graph
+ ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o graph
med: med.cc
- ${CXX} -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} $^ -o med
+ ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o med
thres: thres.cc
${CXX} -I../../../ ${CXXFLAGS} $^ -o thres
matlab: matlab.cc
- ${CXX} -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} -lm $^ -o matlab
+ ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} -lm $^ -o matlab
+
+time_max: time_max.cc
+ ${CXX} -I../../../ ${DICOM} ${MAGICK} ${CXXFLAGS} -lm $^ -o time_max
clean:
rm -rf *.dump *.p?m *.plot *.log *.csv *.dSYM
+ rm seg2d seg3d wsd2d wsd3d nbasins_finder grad clo_vol wst graph med thres matlab time_max
Index: trunk/milena/sandbox/fabien/TODO
===================================================================
--- trunk/milena/sandbox/fabien/TODO (revision 3584)
+++ trunk/milena/sandbox/fabien/TODO (revision 3585)
@@ -36,10 +36,11 @@
[X] 3D
[X] Print nb bg regions // nb fg objets
[ ] Profile for performance
-[ ] ImageMagick support
+[X] ImageMagick support
[ ] Integrate external libraries (GDCM, IM)
[ ] Send result images to lrde account
-[ ] Translate Matlab code
+[X] Translate Matlab code
[X] Subsample binary images
[X] Fast projected histogram
[ ] Triple histogram
+[ ] Create plot for each kind of point with each method
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add ICDAR-related code.
* theo/icdar/dibco/wst-based.sh: New.
* theo/icdar/hsc/boxes.cc: New.
* theo/icdar/hsc/main.cc: New.
dibco/wst-based.sh | 8 +
hsc/boxes.cc | 102 ++++++++++++++
hsc/main.cc | 385 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 495 insertions(+)
Index: theo/icdar/dibco/wst-based.sh
--- theo/icdar/dibco/wst-based.sh (revision 0)
+++ theo/icdar/dibco/wst-based.sh (revision 0)
@@ -0,0 +1,8 @@
+#! /bin/zsh
+
+./+bin/elementary_gradient $1 1 tmp_grad.pgm
+./+bin/closing_volume tmp_grad.pgm 500 tmp_clo.pgm
+./+bin/watershed_flooding tmp_clo.pgm tmp_wst.pgm
+./+bin/watershed_superpose $1 tmp_wst.pgm ${1%pgm}ppm
+
+rm tmp_grad.pgm tmp_clo.pgm tmp_wst.pgm
Property changes on: theo/icdar/dibco/wst-based.sh
___________________________________________________________________
Added: svn:executable
+ *
Index: theo/icdar/hsc/boxes.cc
--- theo/icdar/hsc/boxes.cc (revision 0)
+++ theo/icdar/hsc/boxes.cc (revision 0)
@@ -0,0 +1,102 @@
+// 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.
+
+#include <iostream>
+
+#include <mln/essential/2d.hh>
+#include <mln/debug/colorize.hh>
+#include <mln/debug/println.hh>
+
+#include <scribo/text/extract_bboxes.hh>
+#include <scribo/text/grouping/group_with_single_left_link.hh>
+#include <scribo/text/grouping/group_with_single_right_link.hh>
+#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/text/grouping/group_from_double_link.hh>
+#include <scribo/filter/small_components.hh>
+
+#include <scribo/debug/save_textbboxes_image.hh>
+#include <scribo/make/debug_filename.hh>
+
+#include <mln/logical/not.hh>
+#include <mln/io/dump/save.hh>
+
+
+int usage(const char *name)
+{
+ std::cout << "Usage: " << name << " input.pbm output.dump" << std::endl;
+ return 1;
+}
+
+
+int main(int argc, char* argv[])
+{
+ using namespace scribo;
+ using namespace mln;
+
+ if (argc != 3)
+ return usage(argv[0]);
+
+ scribo::make::internal::debug_filename_prefix = "extract_text_double_link";
+
+ image2d<bool> input;
+ io::pbm::load(input, argv[1]);
+
+ logical::not_inplace(input);
+
+ value::label_16 nbboxes;
+ scribo::util::text<image2d<value::label_16> >
+ text = text::extract_bboxes(input, c8(), nbboxes);
+
+ text = filter::small_components(text,4);
+
+ mln::util::array<unsigned>
+ left_link = text::grouping::group_with_single_left_link(text, 100),
+ right_link = text::grouping::group_with_single_right_link(text, 100);
+
+ std::cout << "BEFORE - nbboxes = " << nbboxes << std::endl;
+
+
+ scribo::debug::save_linked_textbboxes_image(input,
+ text, left_link, right_link,
+ literal::red, literal::cyan, literal::yellow,
+ literal::green,
+ scribo::make::debug_filename("links.ppm"));
+
+ // Validation.
+ scribo::util::text<image2d<value::label_16> > grouped_text
+ = text::grouping::group_from_double_link(text, left_link, right_link);
+
+ std::cout << "AFTER double grouping - nbboxes = " << grouped_text.bboxes().nelements() << std::endl;
+
+ io::dump::save(grouped_text.label_image(), argv[2]);
+
+ scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("boxes.ppm"));
+
+}
+
Index: theo/icdar/hsc/main.cc
--- theo/icdar/hsc/main.cc (revision 0)
+++ theo/icdar/hsc/main.cc (revision 0)
@@ -0,0 +1,385 @@
+#include <set>
+#include <vector>
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/pw/all.hh>
+#include <mln/data/fill.hh>
+#include <mln/level/saturate.hh>
+#include <mln/level/convert.hh>
+#include <mln/arith/revert.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/literal/colors.hh>
+#include <mln/debug/colorize.hh>
+
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pbm/save.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/io/ppm/save.hh>
+
+#include <mln/world/binary_2d/subsample.hh>
+
+#define MLN_FLOAT double
+#include <sandbox/theo/exec/gaussian_directional_2d.hh>
+
+#include <mln/morpho/closing/structural.hh>
+#include <mln/morpho/watershed/flooding.hh>
+#include <mln/win/rectangle2d.hh>
+
+#include <mln/accu/stat/variance.hh>
+
+
+
+namespace mln
+{
+
+
+ template <typename L>
+ inline
+ L find_root_(std::vector<L>& parent, L l)
+ {
+ if (parent[l] == l)
+ return l;
+ return parent[l] = find_root_(parent, parent[l]);
+ }
+
+
+
+ template <typename L>
+ image2d<L>
+ merge(const image2d<value::int_u8>& ima,
+ const image2d<L>& ws,
+ L n,
+ unsigned n_min_stats)
+ {
+ typedef accu::stat::variance<float> A;
+ std::vector<A>
+ vvar(n + 1),
+ hvar(n + 1);
+
+ mln_piter(box2d) p(ima.domain());
+ for_all(p)
+ if (ima(p) != 255 && ws(p) != 0)
+ vvar[ws(p)].take(255 - ima(p), p.row());
+
+
+ image2d<bool>
+ radj(n + 1, n + 1),
+ ladj(n + 1, n + 1);
+ data::fill(radj, false);
+ data::fill(ladj, false);
+
+ for_all(p) if (ws(p) == 0)
+ {
+ if (ws(p + left) == 0 || ws(p + right) == 0)
+ // ws is horizontal => forget it
+ continue;
+ L l1 = ws(p + left),
+ l2 = ws(p + right);
+ if (l1 == 0 || l2 == 0 || l2 == l1)
+ continue;
+ radj.at_(l1, l2) = true;
+ ladj.at_(l2, l1) = true;
+ }
+
+ std::vector<L>
+ best_right(n + 1, 0),
+ best_left(n + 1, 0);
+ L best_l2;
+ float best_score;
+
+ for (L l1 = 1; l1 <= n; ++l1)
+ {
+ if (! vvar[l1].is_valid() || vvar[l1].n_items() < n_min_stats)
+ // Non significative stats.
+ continue;
+
+
+ // Look right.
+
+# ifdef LOG
+ std::cout << l1 << ": ";
+# endif
+
+ best_l2 = 0;
+ best_score;
+
+ for (L l2 = 1; l2 <= n; ++l2)
+ {
+ if (! radj.at_(l1, l2)) // l1 -> l2
+ continue;
+
+ if (! vvar[l2].is_valid() || vvar[l2].n_items() < n_min_stats)
+ // Non significative stats.
+ continue;
+
+# ifdef LOG
+ std::cout << l2 << ' ';
+# endif
+
+ float vm, vM, sm, sM;
+ if (vvar[l1].mean() < vvar[l2].mean())
+ {
+ vm = vvar[l1].mean();
+ sm = vvar[l1].standard_deviation();
+ vM = vvar[l2].mean();
+ sM = vvar[l2].standard_deviation();
+ }
+ else
+ {
+ vm = vvar[l2].mean();
+ sm = vvar[l2].standard_deviation();
+ vM = vvar[l1].mean();
+ sM = vvar[l1].standard_deviation();
+ }
+
+ float score = (vm - sm) - (vM - sM);
+# ifdef LOG
+ std::cout << '(' << score << "), ";
+# endif
+ if (best_l2 == 0 || score > best_score)
+ {
+ best_score = score;
+ best_l2 = l2;
+ }
+ }
+
+ if (best_l2 != 0)
+ {
+ best_right[l1] = best_l2;
+# ifdef LOG
+ std::cout << " ... " << l1 << " -> " << best_l2 << std::endl;
+# endif
+ }
+
+ // Look left.
+
+# ifdef LOG
+ std::cout << l1 << ": ";
+# endif
+
+ best_l2 = 0;
+ best_score;
+
+ for (L l2 = 1; l2 <= n; ++l2)
+ {
+ if (! ladj.at_(l1, l2)) // l2 <- l1
+ continue;
+
+ if (! vvar[l2].is_valid() || vvar[l2].n_items() < n_min_stats)
+ // Non significative stats.
+ continue;
+
+# ifdef LOG
+ std::cout << l2 << ' ';
+# endif
+
+ float vm, vM, sm, sM;
+ if (vvar[l1].mean() < vvar[l2].mean())
+ {
+ vm = vvar[l1].mean();
+ sm = vvar[l1].standard_deviation();
+ vM = vvar[l2].mean();
+ sM = vvar[l2].standard_deviation();
+ }
+ else
+ {
+ vm = vvar[l2].mean();
+ sm = vvar[l2].standard_deviation();
+ vM = vvar[l1].mean();
+ sM = vvar[l1].standard_deviation();
+ }
+
+ float score = (vm - sm) - (vM - sM);
+# ifdef LOG
+ std::cout << '(' << score << "), ";
+# endif
+
+ if (best_l2 == 0 || score > best_score)
+ {
+ best_score = score;
+ best_l2 = l2;
+ }
+ }
+
+ if (best_l2 != 0)
+ {
+ best_left[l1] = best_l2;
+# ifdef LOG
+ std::cout << " ... " << best_l2 << " <- " << l1 << std::endl;
+# endif
+ }
+
+ }
+
+
+ std::vector<L> parent(n + 1);
+ for (L l = 0; l <= n; ++l)
+ parent[l] = l;
+
+ for (L l1 = 1; l1 <= n; ++l1)
+ {
+ L l2 = best_right[l1];
+ if (l2 == 0)
+ continue;
+ if (best_left[l2] == l1)
+ {
+ // cross-validation
+ L l1r = find_root_(parent, l1),
+ l2r = find_root_(parent, l2);
+ if (l2r == l1r)
+ continue; // already merged
+ if (l1r < l2r)
+ parent[l1r] = l2r;
+ else
+ parent[l2r] = l1r;
+ }
+ }
+
+
+ for (L l = 1; l <= n; ++l)
+ parent[l] = find_root_(parent, l);
+
+
+ image2d<L> out(ima.domain());
+ for_all(p)
+ out(p) = parent[ws(p)];
+
+ // io::pgm::save(out, "tmp_out.pgm");
+
+ return out;
+
+ } // end of 'merge'
+
+
+
+} // ! mln
+
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.pbm output.pgm [output.ppm]" << std::endl
+ << " ICDAR'2009: HSC." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::rgb8;
+
+ if (argc != 3 && argc != 4)
+ usage(argv);
+
+
+ // Parameters.
+
+ const unsigned
+ subsampling_factor = 4,
+ height = 5,
+ width = 25,
+ n_min_stats = 1000;
+ const float
+ h_sigma = 31,
+ v_sigma = 1.3;
+
+ // end of Parameters.
+
+
+ trace::entering("main");
+
+ image2d<bool> input;
+ io::pbm::load(input, argv[1]);
+
+ // Sub-sampling.
+ image2d<int_u8>
+ small = world::binary_2d::subsample(input, subsampling_factor),
+ fuzzy, clo,
+ ws,
+ spc;
+
+
+# ifdef LOG
+ io::pgm::save(small, "tmp_small.pgm");
+# endif
+
+
+ // Fuzzifying.
+ {
+ image2d<MLN_FLOAT> temp(small.domain()), out;
+ data::fill(temp, small);
+
+ out = linear::gaussian_directional_2d(temp, 1, h_sigma, 0);
+ out = linear::gaussian_directional_2d(out, 0, v_sigma, 0);
+
+ fuzzy = level::saturate(int_u8(), out);
+
+# ifdef LOG
+ io::pgm::save(fuzzy, "tmp_fuzzy.pgm");
+# endif
+ }
+
+
+ clo = morpho::closing::structural(fuzzy, win::rectangle2d(height, width));
+
+ int_u8 n_basins;
+ ws = morpho::watershed::flooding(clo, c4(), n_basins);
+
+
+ spc = merge(small, ws, n_basins, n_min_stats); // Merging!
+
+
+# ifdef LOG
+
+ {
+ io::ppm::save(debug::colorize(rgb8(), spc, n_basins),
+ "tmp_spc.ppm");
+
+ io::pgm::save(ws, "tmp_ws.pgm");
+
+ image2d<rgb8> cool = level::convert(rgb8(), small);
+ data::fill((cool | (pw::value(ws) == pw::cst(0))).rw(),
+ literal::red);
+ io::ppm::save(cool, "tmp_ws.ppm");
+ }
+# endif
+
+
+ // Outputing.
+ {
+ image2d<int_u8> output(input.domain());
+
+ image2d<rgb8>
+ cool = debug::colorize(rgb8(), spc, n_basins),
+ lab(input.domain());
+
+ mln_piter_(box2d) p(input.domain());
+ for_all(p)
+ if (input(p))
+ {
+ output(p) = 0;
+ lab(p) = literal::black;
+ }
+ else
+ {
+ output(p) = spc.at_(p.row() / subsampling_factor, p.col() / subsampling_factor);
+ lab(p) = cool.at_(p.row() / subsampling_factor, p.col() / subsampling_factor);
+ }
+
+ io::pgm::save(output, argv[2]);
+ if (argc == 4)
+ io::ppm::save(lab, argv[3]);
+ }
+
+
+ trace::exiting("main");
+}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-03-26 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Update IO section of ref guide.
* doc/ref_guide/ref_guide.tex: Update IO section.
---
ref_guide.tex | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
Index: trunk/milena/doc/ref_guide/ref_guide.tex
===================================================================
--- trunk/milena/doc/ref_guide/ref_guide.tex (revision 3582)
+++ trunk/milena/doc/ref_guide/ref_guide.tex (revision 3583)
@@ -42,6 +42,7 @@
\usepackage{color}
\usepackage{hyperref}
\usepackage{pgf}
+\usepackage{hyperref}
\usepackage{doxyfuns}
\usepackage{milena}
@@ -1680,7 +1681,7 @@
\end{itemize}
\doxysection{ioim}{ImageMagick}
- http://www.imagemagick.org/
+ \href{http://www.imagemagick.org/}{http://www.imagemagick.org/}
You have to install ImageMagick with Magick++ support. You will be able to
load every file recognized as an image by ImageMagick.
@@ -1692,13 +1693,15 @@
To do so, just add the following line to your compilation:
+ \begin{verbatim}
`Magick++-config --cppflags --cxxflags --ldflags --libs`
+ \end{verbatim}
- Magick++-config will automatically fill the dependencies depending of your
+ \begin{verbatim}Magick++-config\end{verbatim} will automatically fill the dependencies depending of your
installation.
\doxysection{iodcm}{GDCM}
- http://apps.sourceforge.net/mediawiki/gdcm/
+ \href{http://apps.sourceforge.net/mediawiki/gdcm/}{http://apps.sourceforge.net/mediawiki/gdcm/}
GDCM is a library for manipulating DICOM files. DICOM files are used in
medical imaging.
1
0