3591: 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. --- 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@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@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
participants (1)
-
Guillaume Lazzara