Olena-patches
Threads by month
- ----- 2025 -----
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
March 2011
- 7 participants
- 277 discussions

14 Mar '11
* scribo/fun/v2v/highlight.hh,
* scribo/io/img/internal/debug_img_visitor.hh,
* scribo/io/img/internal/draw_edges.hh,
* scribo/io/img/internal/full_img_visitor.hh,
* scribo/io/img/internal/non_text_img_visitor.hh,
* scribo/io/img/internal/text_img_visitor.hh,
* scribo/io/img/save.hh: New.
---
scribo/ChangeLog | 12 +
.../serializable.hh => fun/v2v/highlight.hh} | 57 +++--
scribo/scribo/io/img/internal/debug_img_visitor.hh | 263 ++++++++++++++++++++
.../internal/draw_edges.hh} | 62 +++---
scribo/scribo/io/img/internal/full_img_visitor.hh | 194 ++++++++++++++
.../scribo/io/img/internal/non_text_img_visitor.hh | 162 ++++++++++++
scribo/scribo/io/img/internal/text_img_visitor.hh | 164 ++++++++++++
scribo/scribo/io/img/save.hh | 242 ++++++++++++++++++
8 files changed, 1104 insertions(+), 52 deletions(-)
copy scribo/scribo/{core/concept/serializable.hh => fun/v2v/highlight.hh} (66%)
create mode 100644 scribo/scribo/io/img/internal/debug_img_visitor.hh
copy scribo/scribo/io/{xml/internal/print_box_coords.hh => img/internal/draw_edges.hh} (56%)
create mode 100644 scribo/scribo/io/img/internal/full_img_visitor.hh
create mode 100644 scribo/scribo/io/img/internal/non_text_img_visitor.hh
create mode 100644 scribo/scribo/io/img/internal/text_img_visitor.hh
create mode 100644 scribo/scribo/io/img/save.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 5cca1e2..3e77d78 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,17 @@
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Introduce result image output.
+
+ * scribo/fun/v2v/highlight.hh,
+ * scribo/io/img/internal/debug_img_visitor.hh,
+ * scribo/io/img/internal/draw_edges.hh,
+ * scribo/io/img/internal/full_img_visitor.hh,
+ * scribo/io/img/internal/non_text_img_visitor.hh,
+ * scribo/io/img/internal/text_img_visitor.hh,
+ * scribo/io/img/save.hh: New.
+
+2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Save image edge coordinates in XML output.
* scribo/io/xml/internal/extended_page_xml_visitor.hh: Here.
diff --git a/scribo/scribo/core/concept/serializable.hh b/scribo/scribo/fun/v2v/highlight.hh
similarity index 66%
copy from scribo/scribo/core/concept/serializable.hh
copy to scribo/scribo/fun/v2v/highlight.hh
index 6e661a6..835be59 100644
--- a/scribo/scribo/core/concept/serializable.hh
+++ b/scribo/scribo/fun/v2v/highlight.hh
@@ -23,42 +23,55 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
-# define SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
+#ifndef SCRIBO_FUN_V2V_HIGHLIGHT_HH
+# define SCRIBO_FUN_V2V_HIGHLIGHT_HH
-/// \file
-///
-/// Concept for serializer visitors.
+/// \brief Function increasing values to highlight areas.
-# include <mln/core/concept/object.hh>
-# include <scribo/core/concept/serialize_visitor.hh>
+# include <mln/core/concept/function.hh>
namespace scribo
{
- /// \brief Link functor concept.
- template <typename E>
- class Serializable : public mln::Object<E>
+ namespace fun
{
- public:
- template <typename E2>
- void accept(const SerializeVisitor<E2>& visitor) const;
- };
+
+ namespace v2v
+ {
+
+ template <typename R>
+ struct highlight
+ : mln::Function_v2v<highlight<R> >
+ {
+ typedef R result;
+
+ highlight();
+ result operator()(const result& v) const;
+ };
# ifndef MLN_INCLUDE_ONLY
- template <typename E>
- template <typename E2>
- void
- Serializable<E>::accept(const SerializeVisitor<E2>& visitor) const
- {
- exact(visitor).visit(exact(*this));
- }
+
+ template <typename R>
+ highlight<R>::highlight()
+ {
+ }
+
+
+ template <typename R>
+ typename highlight<R>::result
+ highlight<R>::operator()(const result& v) const
+ {
+ return v + v / 2;
+ }
# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace scribo::fun::v2v
+
+ } // end of namespace scribo::fun
} // end of namespace scribo
-#endif // SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
+#endif // ! SCRIBO_FUN_V2V_HIGHLIGHT_HH
diff --git a/scribo/scribo/io/img/internal/debug_img_visitor.hh b/scribo/scribo/io/img/internal/debug_img_visitor.hh
new file mode 100644
index 0000000..f1c689d
--- /dev/null
+++ b/scribo/scribo/io/img/internal/debug_img_visitor.hh
@@ -0,0 +1,263 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_DEBUG_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_DEBUG_IMG_VISITOR_HH
+
+/// \file
+///
+/// Save document image analysis to a small image.
+
+# include <fstream>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+# include <mln/subsampling/antialiased.hh>
+# include <mln/morpho/elementary/gradient_external.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/line_info.hh>
+
+# include <scribo/io/img/internal/draw_edges.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+
+ class debug_img_visitor : public doc_serializer<debug_img_visitor>
+ {
+ public:
+ // Constructor
+ debug_img_visitor(mln::image2d<value::rgb8>& out,
+ unsigned output_ratio);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ void visit(const component_info& info) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+ unsigned output_ratio;
+
+ mutable image2d<scribo::def::lbl_type> elt_edge;
+
+
+ private: // Methods
+ box2d compute_bbox(const box2d& b) const;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ box2d
+ debug_img_visitor::compute_bbox(const box2d& b) const
+ {
+ point2d
+ pmin = b.pmin() / output_ratio,
+ pmax = b.pmax() / output_ratio;
+
+ return box2d(pmin, pmax);
+ }
+
+
+ inline
+ debug_img_visitor::debug_img_visitor(mln::image2d<value::rgb8>& out,
+ unsigned output_ratio)
+ : output(out), output_ratio(output_ratio)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ debug_img_visitor::visit(const document<L>& doc) const
+ {
+ // Text
+ if (doc.has_text())
+ doc.paragraphs().accept(*this);
+
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ {
+ // Prepare element edges
+
+ // FIXME: UGLY! Too slow!
+ scribo::def::lbl_type nlabels;
+ component_set<L> elts = primitive::extract::components(
+ data::convert(bool(), mln::subsampling::antialiased(doc.elements().labeled_image(),
+ output_ratio)),
+ c8(),
+ nlabels);
+
+ // Preserving elements tags
+ if (doc.elements().nelements() != elts.nelements())
+ {
+ std::cerr << "Warnig: could not preserve element type in "
+ << "img debug output." << std::endl;
+ std::cerr << "The number of non text element has changed while "
+ << "subsampling images : "
+ << doc.elements().nelements() << " vs "
+ << elts.nelements() << std::endl;
+ }
+ else
+ for_all_comps(c, doc.elements())
+ elts(c).update_type(doc.elements()(c).type());
+
+ elt_edge = morpho::elementary::gradient_external(elts.labeled_image(), c8());
+
+// const component_set<L>& elts = doc.elements();
+ for_all_comps(e, elts)
+ if (elts(e).is_valid())
+ elts(e).accept(*this);
+ }
+
+
+ // line seraparators
+ if (doc.has_vline_seps())
+ for_all_comps(c, doc.vline_seps_comps())
+ doc.vline_seps_comps()(c).accept(*this);
+ if (doc.has_hline_seps())
+ for_all_comps(c, doc.hline_seps_comps())
+ doc.hline_seps_comps()(c).accept(*this);
+
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ debug_img_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::LineSeparator:
+ {
+ mln::draw::box(output, compute_bbox(info.bbox()),
+ literal::cyan);
+ }
+ break;
+
+
+ default:
+ case component::Image:
+ {
+ // The bbox does not need to be reajusted to the
+ // subsampled domain since it has been recomputed while
+ // computing the edge image.
+ //
+ // However, the bbox must be enlarged since only the
+ // _external_ edge is computed.
+ box2d b = info.bbox();
+ b.enlarge(1);
+ b.crop_wrt(output.domain());
+ data::fill(((output | b).rw()
+ | (pw::value(elt_edge)
+ == pw::cst((scribo::def::lbl_type)info.id().to_equiv()))).rw(),
+ literal::orange);
+ }
+ break;
+ }
+ }
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ debug_img_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+ lines(l).accept(*this);
+ }
+
+ box2d b = compute_bbox(parset(p).bbox());
+ b.enlarge(1);
+ b.crop_wrt(output.domain());
+ mln::draw::box(output, b, literal::blue);
+ }
+ }
+
+
+ template <typename L>
+ void
+ debug_img_visitor::visit(const line_info<L>& line) const
+ {
+ point2d
+ pmin = line.bbox().pmin(),
+ pmax = line.bbox().pmax();
+ pmax.row() = line.baseline();
+ pmin.row() = line.baseline();
+
+ pmin = pmin / output_ratio;
+ pmax = pmax / output_ratio;
+
+ mln::draw::line(output, pmin, pmax, literal::red);
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_DEBUG_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/xml/internal/print_box_coords.hh b/scribo/scribo/io/img/internal/draw_edges.hh
similarity index 56%
copy from scribo/scribo/io/xml/internal/print_box_coords.hh
copy to scribo/scribo/io/img/internal/draw_edges.hh
index ad84709..664a352 100644
--- a/scribo/scribo/io/xml/internal/print_box_coords.hh
+++ b/scribo/scribo/io/img/internal/draw_edges.hh
@@ -23,15 +23,26 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
-# define SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#ifndef SCRIBO_IO_IMG_INTERNAL_DRAW_EDGES_HH
+# define SCRIBO_IO_IMG_INTERNAL_DRAW_EDGES_HH
/// \file
///
-/// \brief Prints box2d coordinates to XML data.
+/// \brief Draw object edges.
# include <fstream>
-# include <mln/core/alias/box2d.hh>
+# include <mln/core/image/image2d.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+# include <mln/pw/all.hh>
+# include <mln/data/fill.hh>
+# include <mln/data/convert.hh>
+# include <mln/literal/colors.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/morpho/elementary/gradient_external.hh>
+
+# include <scribo/core/component_info.hh>
+# include <scribo/core/def/lbl_type.hh>
+
namespace scribo
{
@@ -39,7 +50,7 @@ namespace scribo
namespace io
{
- namespace xml
+ namespace img
{
namespace internal
@@ -47,11 +58,12 @@ namespace scribo
using namespace mln;
- /*! \brief Prints box2d coordinates to XML data.
+ /*! \brief Draw component edges.
*/
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space);
+ draw_edges(const component_info& info,
+ image2d<value::rgb8>& output, const value::rgb8& value,
+ const image2d<scribo::def::lbl_type>& edges);
# ifndef MLN_INCLUDE_ONLY
@@ -59,37 +71,27 @@ namespace scribo
inline
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space)
+ draw_edges(const component_info& info,
+ image2d<value::rgb8>& output, const value::rgb8& value,
+ const image2d<scribo::def::lbl_type>& edges)
{
- std::string sc = space;
- std::string sp = sc + " ";
- ostr << sc << "<coords>" << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sc << "</coords>" << std::endl;
-
+ box2d b = info.bbox();
+ b.enlarge(1);
+ data::fill(((output | b).rw()
+ | (pw::value(edges)
+ == pw::cst((scribo::def::lbl_type)info.id().to_equiv()))).rw(),
+ value);
}
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace scribo::io::xml::internal
+ } // end of namespace scribo::io::img::internal
- } // end of namespace scribo::io::xml
+ } // end of namespace scribo::io::img
} // end of namespace scribo::io
} // end of namespace scribo
-#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#endif // ! SCRIBO_IO_IMG_INTERNAL_DRAW_EDGES_HH
diff --git a/scribo/scribo/io/img/internal/full_img_visitor.hh b/scribo/scribo/io/img/internal/full_img_visitor.hh
new file mode 100644
index 0000000..30987db
--- /dev/null
+++ b/scribo/scribo/io/img/internal/full_img_visitor.hh
@@ -0,0 +1,194 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_FULL_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_FULL_IMG_VISITOR_HH
+
+/// \file
+///
+/// Save document image analysis to an image.
+
+# include <fstream>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/line_info.hh>
+
+# include <scribo/io/img/internal/draw_edges.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+
+ class full_img_visitor : public doc_serializer<full_img_visitor>
+ {
+ public:
+ // Constructor
+ full_img_visitor(mln::image2d<value::rgb8>& out);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ void visit(const component_info& info) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+
+ mutable image2d<scribo::def::lbl_type> elt_edge;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ full_img_visitor::full_img_visitor(mln::image2d<value::rgb8>& out)
+ : output(out)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ full_img_visitor::visit(const document<L>& doc) const
+ {
+ // Text
+ if (doc.has_text())
+ doc.paragraphs().accept(*this);
+
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ {
+ // Prepare element edges
+ elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c8());
+
+ const component_set<L>& elts = doc.elements();
+ for_all_comps(e, elts)
+ if (elts(e).is_valid())
+ elts(e).accept(*this);
+ }
+
+
+ // line seraparators
+ if (doc.has_vline_seps())
+ for_all_comps(c, doc.vline_seps_comps())
+ doc.vline_seps_comps()(c).accept(*this);
+ if (doc.has_hline_seps())
+ for_all_comps(c, doc.hline_seps_comps())
+ doc.hline_seps_comps()(c).accept(*this);
+
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ full_img_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::LineSeparator:
+ {
+ mln::draw::box(output, info.bbox(), literal::cyan);
+ }
+ break;
+
+
+ default:
+ case component::Image:
+ {
+ draw_edges(info, output, literal::orange, elt_edge);
+ }
+ break;
+ }
+ }
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ full_img_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+ lines(l).accept(*this);
+ }
+
+ mln::draw::box(output, parset(p).bbox(), literal::blue);
+ }
+ }
+
+
+ template <typename L>
+ void
+ full_img_visitor::visit(const line_info<L>& line) const
+ {
+ mln::draw::box(output, line.bbox(), literal::red);
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_FULL_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/img/internal/non_text_img_visitor.hh b/scribo/scribo/io/img/internal/non_text_img_visitor.hh
new file mode 100644
index 0000000..24b027e
--- /dev/null
+++ b/scribo/scribo/io/img/internal/non_text_img_visitor.hh
@@ -0,0 +1,162 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH
+
+/// \file
+///
+/// \brief Save non-text information as an image.
+
+# include <fstream>
+
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/io/img/internal/draw_edges.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+ /*! \brief Save non-text information as an image.
+ */
+ class non_text_img_visitor : public doc_serializer<non_text_img_visitor>
+ {
+ public:
+ // Constructor
+ non_text_img_visitor(mln::image2d<value::rgb8>& out);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ template <typename L>
+ void visit(const component_set<L>& comp_set) const;
+
+ void visit(const component_info& info) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+
+ mutable image2d<scribo::def::lbl_type> elt_edge;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ non_text_img_visitor::non_text_img_visitor(mln::image2d<value::rgb8>& out)
+ : output(out)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ non_text_img_visitor::visit(const document<L>& doc) const
+ {
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ {
+ // Prepare element edges
+ elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c8());
+
+ doc.elements().accept(*this);
+ }
+
+ // line seraparators
+ if (doc.has_hline_seps())
+ doc.hline_seps_comps().accept(*this);
+ if (doc.has_vline_seps())
+ doc.vline_seps_comps().accept(*this);
+ }
+
+
+ /// Component Set
+ //
+ template <typename L>
+ void
+ non_text_img_visitor::visit(const component_set<L>& comp_set) const
+ {
+ for_all_comps(c, comp_set)
+ if (comp_set(c).is_valid())
+ comp_set(c).accept(*this);
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ non_text_img_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::LineSeparator:
+ {
+ mln::draw::box(output, info.bbox(), literal::cyan);
+ }
+ break;
+
+
+ default:
+ case component::Image:
+ {
+ draw_edges(info, output, literal::orange, elt_edge);
+ }
+ break;
+ }
+ }
+
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/img/internal/text_img_visitor.hh b/scribo/scribo/io/img/internal/text_img_visitor.hh
new file mode 100644
index 0000000..7629bf7
--- /dev/null
+++ b/scribo/scribo/io/img/internal/text_img_visitor.hh
@@ -0,0 +1,164 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_TEXT_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_TEXT_IMG_VISITOR_HH
+
+/// \file
+///
+/// Image output with text related information.
+
+# include <fstream>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+# include <mln/literal/colors.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/line_info.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+
+ class text_img_visitor : public doc_serializer<text_img_visitor>
+ {
+ public:
+ // Constructor
+ text_img_visitor(mln::image2d<value::rgb8>&);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ template <typename L>
+ void visit(const component_set<L>& comp_set) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ inline
+ text_img_visitor::text_img_visitor(mln::image2d<value::rgb8>& out)
+ : output(out)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ text_img_visitor::visit(const document<L>& doc) const
+ {
+ mln_precondition(doc.is_open());
+
+ // Prepare output image.
+ output = duplicate(doc.image());
+
+
+ // Text
+ if (doc.has_text())
+ doc.paragraphs().accept(*this);
+ }
+
+ /// Component Set
+ //
+ template <typename L>
+ void
+ text_img_visitor::visit(const component_set<L>& comp_set) const
+ {
+ for_all_comps(c, comp_set)
+ if (comp_set(c).is_valid())
+ comp_set(c).accept(*this);
+ }
+
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ text_img_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+ lines(l).accept(*this);
+ }
+
+ mln::draw::box(output, parset(p).bbox(), literal::blue);
+ }
+ }
+
+
+ template <typename L>
+ void
+ text_img_visitor::visit(const line_info<L>& line) const
+ {
+ mln::draw::box(output, line.bbox(), literal::red);
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_TEXT_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/img/save.hh b/scribo/scribo/io/img/save.hh
new file mode 100644
index 0000000..56300d6
--- /dev/null
+++ b/scribo/scribo/io/img/save.hh
@@ -0,0 +1,242 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_SAVE_HH
+# define SCRIBO_IO_IMG_SAVE_HH
+
+/// \file
+///
+/// \brief Save document information as an image.
+
+# include <libgen.h>
+# include <fstream>
+# include <sstream>
+
+# include <map>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/io/magick/save.hh>
+# include <mln/subsampling/antialiased.hh>
+# include <mln/data/transform_inplace.hh>
+
+# include <scribo/core/document.hh>
+
+# include <scribo/io/img/internal/text_img_visitor.hh>
+# include <scribo/io/img/internal/non_text_img_visitor.hh>
+# include <scribo/io/img/internal/full_img_visitor.hh>
+# include <scribo/io/img/internal/debug_img_visitor.hh>
+
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ /*! \brief Supported image formats
+
+ Text : Display text regions.
+
+ NonText : Display non-text regions.
+
+ Full : Text and non-text regions.
+ */
+ enum Format
+ {
+ Text,
+ NonText,
+ Full,
+ DebugWoImage,
+ DebugWithImage,
+ };
+
+
+ /*! \brief Save document information as an image
+
+ */
+ template <typename L>
+ void
+ save(const document<L>& doc, const std::string& output_name,
+ Format format);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ struct highlight_mask
+ : Function_v2v<highlight_mask>
+ {
+ typedef value::rgb8 result;
+
+ highlight_mask(float ratio)
+ : ratio(ratio)
+ {
+ }
+
+ result operator()(const result& v) const
+ {
+ result out = v;
+ out.red() = std::min(out.red() * ratio, 255.f);
+ out.green() = std::min(out.green() * ratio, 255.f);
+ out.blue() = std::min(out.blue() * ratio, 255.f);
+ return out;
+ }
+
+ float ratio;
+ };
+
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_text(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8> output = duplicate(doc.image());
+ scribo::io::img::internal::text_img_visitor f(output);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_non_text(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8> output = duplicate(doc.image());
+ scribo::io::img::internal::non_text_img_visitor f(output);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_full(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8> output = duplicate(doc.image());
+ scribo::io::img::internal::full_img_visitor f(output);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_debug_without_image(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8>
+ output(box2d(doc.image().domain().pmin() / 4,
+ doc.image().domain().pmax() / 4));
+ data::fill(output, literal::black);
+ scribo::io::img::internal::debug_img_visitor f(output, 4);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_debug_with_image(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8>
+ output = mln::subsampling::antialiased(doc.image(), 4);
+ internal::highlight_mask highlight(0.5f);
+ data::transform_inplace(output, highlight);
+ scribo::io::img::internal::debug_img_visitor f(output, 4);
+ doc.accept(f);
+ return output;
+ }
+
+ } // end of namespace scribo::io::img::internal
+
+
+
+ // FACADE
+
+ template <typename L>
+ void
+ save(const document<L>& doc,
+ const std::string& output_name,
+ Format format)
+ {
+ trace::entering("scribo::io::img::save");
+
+ mln_precondition(doc.is_open());
+
+ mln::image2d<value::rgb8> output;
+
+ // Choose saving method.
+ switch (format)
+ {
+ case Text:
+ output = internal::save_text(doc);
+ break;
+
+ case NonText:
+ output = internal::save_non_text(doc);
+ break;
+
+ case Full:
+ output = internal::save_full(doc);
+ break;
+
+ case DebugWoImage:
+ output = internal::save_debug_without_image(doc);
+ break;
+
+ case DebugWithImage:
+ output = internal::save_debug_with_image(doc);
+ break;
+
+ default:
+ trace::warning("scribo::io::img::save - "
+ "Invalid image format! Skip saving...");
+ trace::exiting("scribo::io::img::save");
+ return;
+ }
+
+ mln::io::magick::save(output, output_name.c_str());
+
+ trace::exiting("scribo::io::img::save");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_IO_IMG_SAVE_HH
--
1.5.6.5
1
0

14 Mar '11
* scribo/fun/v2v/highlight.hh,
* scribo/io/img/internal/debug_img_visitor.hh,
* scribo/io/img/internal/draw_edges.hh,
* scribo/io/img/internal/full_img_visitor.hh,
* scribo/io/img/internal/non_text_img_visitor.hh,
* scribo/io/img/internal/text_img_visitor.hh,
* scribo/io/img/save.hh: New.
---
scribo/ChangeLog | 12 +
.../serializable.hh => fun/v2v/highlight.hh} | 57 +++--
scribo/scribo/io/img/internal/debug_img_visitor.hh | 263 ++++++++++++++++++++
.../internal/draw_edges.hh} | 62 +++---
scribo/scribo/io/img/internal/full_img_visitor.hh | 194 ++++++++++++++
.../scribo/io/img/internal/non_text_img_visitor.hh | 162 ++++++++++++
scribo/scribo/io/img/internal/text_img_visitor.hh | 164 ++++++++++++
scribo/scribo/io/img/save.hh | 242 ++++++++++++++++++
8 files changed, 1104 insertions(+), 52 deletions(-)
copy scribo/scribo/{core/concept/serializable.hh => fun/v2v/highlight.hh} (66%)
create mode 100644 scribo/scribo/io/img/internal/debug_img_visitor.hh
copy scribo/scribo/io/{xml/internal/print_box_coords.hh => img/internal/draw_edges.hh} (56%)
create mode 100644 scribo/scribo/io/img/internal/full_img_visitor.hh
create mode 100644 scribo/scribo/io/img/internal/non_text_img_visitor.hh
create mode 100644 scribo/scribo/io/img/internal/text_img_visitor.hh
create mode 100644 scribo/scribo/io/img/save.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 5b96508..43041fe 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,17 @@
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Introduce result image output.
+
+ * scribo/fun/v2v/highlight.hh,
+ * scribo/io/img/internal/debug_img_visitor.hh,
+ * scribo/io/img/internal/draw_edges.hh,
+ * scribo/io/img/internal/full_img_visitor.hh,
+ * scribo/io/img/internal/non_text_img_visitor.hh,
+ * scribo/io/img/internal/text_img_visitor.hh,
+ * scribo/io/img/save.hh: New.
+
+2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Save image edge coordinates in XML output.
* scribo/io/xml/internal/extended_page_xml_visitor.hh: Here.
diff --git a/scribo/scribo/core/concept/serializable.hh b/scribo/scribo/fun/v2v/highlight.hh
similarity index 66%
copy from scribo/scribo/core/concept/serializable.hh
copy to scribo/scribo/fun/v2v/highlight.hh
index 6e661a6..835be59 100644
--- a/scribo/scribo/core/concept/serializable.hh
+++ b/scribo/scribo/fun/v2v/highlight.hh
@@ -23,42 +23,55 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
-# define SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
+#ifndef SCRIBO_FUN_V2V_HIGHLIGHT_HH
+# define SCRIBO_FUN_V2V_HIGHLIGHT_HH
-/// \file
-///
-/// Concept for serializer visitors.
+/// \brief Function increasing values to highlight areas.
-# include <mln/core/concept/object.hh>
-# include <scribo/core/concept/serialize_visitor.hh>
+# include <mln/core/concept/function.hh>
namespace scribo
{
- /// \brief Link functor concept.
- template <typename E>
- class Serializable : public mln::Object<E>
+ namespace fun
{
- public:
- template <typename E2>
- void accept(const SerializeVisitor<E2>& visitor) const;
- };
+
+ namespace v2v
+ {
+
+ template <typename R>
+ struct highlight
+ : mln::Function_v2v<highlight<R> >
+ {
+ typedef R result;
+
+ highlight();
+ result operator()(const result& v) const;
+ };
# ifndef MLN_INCLUDE_ONLY
- template <typename E>
- template <typename E2>
- void
- Serializable<E>::accept(const SerializeVisitor<E2>& visitor) const
- {
- exact(visitor).visit(exact(*this));
- }
+
+ template <typename R>
+ highlight<R>::highlight()
+ {
+ }
+
+
+ template <typename R>
+ typename highlight<R>::result
+ highlight<R>::operator()(const result& v) const
+ {
+ return v + v / 2;
+ }
# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace scribo::fun::v2v
+
+ } // end of namespace scribo::fun
} // end of namespace scribo
-#endif // SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
+#endif // ! SCRIBO_FUN_V2V_HIGHLIGHT_HH
diff --git a/scribo/scribo/io/img/internal/debug_img_visitor.hh b/scribo/scribo/io/img/internal/debug_img_visitor.hh
new file mode 100644
index 0000000..f1c689d
--- /dev/null
+++ b/scribo/scribo/io/img/internal/debug_img_visitor.hh
@@ -0,0 +1,263 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_DEBUG_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_DEBUG_IMG_VISITOR_HH
+
+/// \file
+///
+/// Save document image analysis to a small image.
+
+# include <fstream>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+# include <mln/subsampling/antialiased.hh>
+# include <mln/morpho/elementary/gradient_external.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/line_info.hh>
+
+# include <scribo/io/img/internal/draw_edges.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+
+ class debug_img_visitor : public doc_serializer<debug_img_visitor>
+ {
+ public:
+ // Constructor
+ debug_img_visitor(mln::image2d<value::rgb8>& out,
+ unsigned output_ratio);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ void visit(const component_info& info) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+ unsigned output_ratio;
+
+ mutable image2d<scribo::def::lbl_type> elt_edge;
+
+
+ private: // Methods
+ box2d compute_bbox(const box2d& b) const;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ box2d
+ debug_img_visitor::compute_bbox(const box2d& b) const
+ {
+ point2d
+ pmin = b.pmin() / output_ratio,
+ pmax = b.pmax() / output_ratio;
+
+ return box2d(pmin, pmax);
+ }
+
+
+ inline
+ debug_img_visitor::debug_img_visitor(mln::image2d<value::rgb8>& out,
+ unsigned output_ratio)
+ : output(out), output_ratio(output_ratio)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ debug_img_visitor::visit(const document<L>& doc) const
+ {
+ // Text
+ if (doc.has_text())
+ doc.paragraphs().accept(*this);
+
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ {
+ // Prepare element edges
+
+ // FIXME: UGLY! Too slow!
+ scribo::def::lbl_type nlabels;
+ component_set<L> elts = primitive::extract::components(
+ data::convert(bool(), mln::subsampling::antialiased(doc.elements().labeled_image(),
+ output_ratio)),
+ c8(),
+ nlabels);
+
+ // Preserving elements tags
+ if (doc.elements().nelements() != elts.nelements())
+ {
+ std::cerr << "Warnig: could not preserve element type in "
+ << "img debug output." << std::endl;
+ std::cerr << "The number of non text element has changed while "
+ << "subsampling images : "
+ << doc.elements().nelements() << " vs "
+ << elts.nelements() << std::endl;
+ }
+ else
+ for_all_comps(c, doc.elements())
+ elts(c).update_type(doc.elements()(c).type());
+
+ elt_edge = morpho::elementary::gradient_external(elts.labeled_image(), c8());
+
+// const component_set<L>& elts = doc.elements();
+ for_all_comps(e, elts)
+ if (elts(e).is_valid())
+ elts(e).accept(*this);
+ }
+
+
+ // line seraparators
+ if (doc.has_vline_seps())
+ for_all_comps(c, doc.vline_seps_comps())
+ doc.vline_seps_comps()(c).accept(*this);
+ if (doc.has_hline_seps())
+ for_all_comps(c, doc.hline_seps_comps())
+ doc.hline_seps_comps()(c).accept(*this);
+
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ debug_img_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::LineSeparator:
+ {
+ mln::draw::box(output, compute_bbox(info.bbox()),
+ literal::cyan);
+ }
+ break;
+
+
+ default:
+ case component::Image:
+ {
+ // The bbox does not need to be reajusted to the
+ // subsampled domain since it has been recomputed while
+ // computing the edge image.
+ //
+ // However, the bbox must be enlarged since only the
+ // _external_ edge is computed.
+ box2d b = info.bbox();
+ b.enlarge(1);
+ b.crop_wrt(output.domain());
+ data::fill(((output | b).rw()
+ | (pw::value(elt_edge)
+ == pw::cst((scribo::def::lbl_type)info.id().to_equiv()))).rw(),
+ literal::orange);
+ }
+ break;
+ }
+ }
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ debug_img_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+ lines(l).accept(*this);
+ }
+
+ box2d b = compute_bbox(parset(p).bbox());
+ b.enlarge(1);
+ b.crop_wrt(output.domain());
+ mln::draw::box(output, b, literal::blue);
+ }
+ }
+
+
+ template <typename L>
+ void
+ debug_img_visitor::visit(const line_info<L>& line) const
+ {
+ point2d
+ pmin = line.bbox().pmin(),
+ pmax = line.bbox().pmax();
+ pmax.row() = line.baseline();
+ pmin.row() = line.baseline();
+
+ pmin = pmin / output_ratio;
+ pmax = pmax / output_ratio;
+
+ mln::draw::line(output, pmin, pmax, literal::red);
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_DEBUG_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/xml/internal/print_box_coords.hh b/scribo/scribo/io/img/internal/draw_edges.hh
similarity index 56%
copy from scribo/scribo/io/xml/internal/print_box_coords.hh
copy to scribo/scribo/io/img/internal/draw_edges.hh
index ad84709..664a352 100644
--- a/scribo/scribo/io/xml/internal/print_box_coords.hh
+++ b/scribo/scribo/io/img/internal/draw_edges.hh
@@ -23,15 +23,26 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
-# define SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#ifndef SCRIBO_IO_IMG_INTERNAL_DRAW_EDGES_HH
+# define SCRIBO_IO_IMG_INTERNAL_DRAW_EDGES_HH
/// \file
///
-/// \brief Prints box2d coordinates to XML data.
+/// \brief Draw object edges.
# include <fstream>
-# include <mln/core/alias/box2d.hh>
+# include <mln/core/image/image2d.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+# include <mln/pw/all.hh>
+# include <mln/data/fill.hh>
+# include <mln/data/convert.hh>
+# include <mln/literal/colors.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/morpho/elementary/gradient_external.hh>
+
+# include <scribo/core/component_info.hh>
+# include <scribo/core/def/lbl_type.hh>
+
namespace scribo
{
@@ -39,7 +50,7 @@ namespace scribo
namespace io
{
- namespace xml
+ namespace img
{
namespace internal
@@ -47,11 +58,12 @@ namespace scribo
using namespace mln;
- /*! \brief Prints box2d coordinates to XML data.
+ /*! \brief Draw component edges.
*/
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space);
+ draw_edges(const component_info& info,
+ image2d<value::rgb8>& output, const value::rgb8& value,
+ const image2d<scribo::def::lbl_type>& edges);
# ifndef MLN_INCLUDE_ONLY
@@ -59,37 +71,27 @@ namespace scribo
inline
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space)
+ draw_edges(const component_info& info,
+ image2d<value::rgb8>& output, const value::rgb8& value,
+ const image2d<scribo::def::lbl_type>& edges)
{
- std::string sc = space;
- std::string sp = sc + " ";
- ostr << sc << "<coords>" << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sc << "</coords>" << std::endl;
-
+ box2d b = info.bbox();
+ b.enlarge(1);
+ data::fill(((output | b).rw()
+ | (pw::value(edges)
+ == pw::cst((scribo::def::lbl_type)info.id().to_equiv()))).rw(),
+ value);
}
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace scribo::io::xml::internal
+ } // end of namespace scribo::io::img::internal
- } // end of namespace scribo::io::xml
+ } // end of namespace scribo::io::img
} // end of namespace scribo::io
} // end of namespace scribo
-#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#endif // ! SCRIBO_IO_IMG_INTERNAL_DRAW_EDGES_HH
diff --git a/scribo/scribo/io/img/internal/full_img_visitor.hh b/scribo/scribo/io/img/internal/full_img_visitor.hh
new file mode 100644
index 0000000..30987db
--- /dev/null
+++ b/scribo/scribo/io/img/internal/full_img_visitor.hh
@@ -0,0 +1,194 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_FULL_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_FULL_IMG_VISITOR_HH
+
+/// \file
+///
+/// Save document image analysis to an image.
+
+# include <fstream>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/line_info.hh>
+
+# include <scribo/io/img/internal/draw_edges.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+
+ class full_img_visitor : public doc_serializer<full_img_visitor>
+ {
+ public:
+ // Constructor
+ full_img_visitor(mln::image2d<value::rgb8>& out);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ void visit(const component_info& info) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+
+ mutable image2d<scribo::def::lbl_type> elt_edge;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ full_img_visitor::full_img_visitor(mln::image2d<value::rgb8>& out)
+ : output(out)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ full_img_visitor::visit(const document<L>& doc) const
+ {
+ // Text
+ if (doc.has_text())
+ doc.paragraphs().accept(*this);
+
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ {
+ // Prepare element edges
+ elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c8());
+
+ const component_set<L>& elts = doc.elements();
+ for_all_comps(e, elts)
+ if (elts(e).is_valid())
+ elts(e).accept(*this);
+ }
+
+
+ // line seraparators
+ if (doc.has_vline_seps())
+ for_all_comps(c, doc.vline_seps_comps())
+ doc.vline_seps_comps()(c).accept(*this);
+ if (doc.has_hline_seps())
+ for_all_comps(c, doc.hline_seps_comps())
+ doc.hline_seps_comps()(c).accept(*this);
+
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ full_img_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::LineSeparator:
+ {
+ mln::draw::box(output, info.bbox(), literal::cyan);
+ }
+ break;
+
+
+ default:
+ case component::Image:
+ {
+ draw_edges(info, output, literal::orange, elt_edge);
+ }
+ break;
+ }
+ }
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ full_img_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+ lines(l).accept(*this);
+ }
+
+ mln::draw::box(output, parset(p).bbox(), literal::blue);
+ }
+ }
+
+
+ template <typename L>
+ void
+ full_img_visitor::visit(const line_info<L>& line) const
+ {
+ mln::draw::box(output, line.bbox(), literal::red);
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_FULL_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/img/internal/non_text_img_visitor.hh b/scribo/scribo/io/img/internal/non_text_img_visitor.hh
new file mode 100644
index 0000000..24b027e
--- /dev/null
+++ b/scribo/scribo/io/img/internal/non_text_img_visitor.hh
@@ -0,0 +1,162 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH
+
+/// \file
+///
+/// \brief Save non-text information as an image.
+
+# include <fstream>
+
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/io/img/internal/draw_edges.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+ /*! \brief Save non-text information as an image.
+ */
+ class non_text_img_visitor : public doc_serializer<non_text_img_visitor>
+ {
+ public:
+ // Constructor
+ non_text_img_visitor(mln::image2d<value::rgb8>& out);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ template <typename L>
+ void visit(const component_set<L>& comp_set) const;
+
+ void visit(const component_info& info) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+
+ mutable image2d<scribo::def::lbl_type> elt_edge;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ non_text_img_visitor::non_text_img_visitor(mln::image2d<value::rgb8>& out)
+ : output(out)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ non_text_img_visitor::visit(const document<L>& doc) const
+ {
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ {
+ // Prepare element edges
+ elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c8());
+
+ doc.elements().accept(*this);
+ }
+
+ // line seraparators
+ if (doc.has_hline_seps())
+ doc.hline_seps_comps().accept(*this);
+ if (doc.has_vline_seps())
+ doc.vline_seps_comps().accept(*this);
+ }
+
+
+ /// Component Set
+ //
+ template <typename L>
+ void
+ non_text_img_visitor::visit(const component_set<L>& comp_set) const
+ {
+ for_all_comps(c, comp_set)
+ if (comp_set(c).is_valid())
+ comp_set(c).accept(*this);
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ non_text_img_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::LineSeparator:
+ {
+ mln::draw::box(output, info.bbox(), literal::cyan);
+ }
+ break;
+
+
+ default:
+ case component::Image:
+ {
+ draw_edges(info, output, literal::orange, elt_edge);
+ }
+ break;
+ }
+ }
+
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/img/internal/text_img_visitor.hh b/scribo/scribo/io/img/internal/text_img_visitor.hh
new file mode 100644
index 0000000..7629bf7
--- /dev/null
+++ b/scribo/scribo/io/img/internal/text_img_visitor.hh
@@ -0,0 +1,164 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_TEXT_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_TEXT_IMG_VISITOR_HH
+
+/// \file
+///
+/// Image output with text related information.
+
+# include <fstream>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+# include <mln/literal/colors.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/line_info.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+
+ class text_img_visitor : public doc_serializer<text_img_visitor>
+ {
+ public:
+ // Constructor
+ text_img_visitor(mln::image2d<value::rgb8>&);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ template <typename L>
+ void visit(const component_set<L>& comp_set) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ inline
+ text_img_visitor::text_img_visitor(mln::image2d<value::rgb8>& out)
+ : output(out)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ text_img_visitor::visit(const document<L>& doc) const
+ {
+ mln_precondition(doc.is_open());
+
+ // Prepare output image.
+ output = duplicate(doc.image());
+
+
+ // Text
+ if (doc.has_text())
+ doc.paragraphs().accept(*this);
+ }
+
+ /// Component Set
+ //
+ template <typename L>
+ void
+ text_img_visitor::visit(const component_set<L>& comp_set) const
+ {
+ for_all_comps(c, comp_set)
+ if (comp_set(c).is_valid())
+ comp_set(c).accept(*this);
+ }
+
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ text_img_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+ lines(l).accept(*this);
+ }
+
+ mln::draw::box(output, parset(p).bbox(), literal::blue);
+ }
+ }
+
+
+ template <typename L>
+ void
+ text_img_visitor::visit(const line_info<L>& line) const
+ {
+ mln::draw::box(output, line.bbox(), literal::red);
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_TEXT_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/img/save.hh b/scribo/scribo/io/img/save.hh
new file mode 100644
index 0000000..56300d6
--- /dev/null
+++ b/scribo/scribo/io/img/save.hh
@@ -0,0 +1,242 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_SAVE_HH
+# define SCRIBO_IO_IMG_SAVE_HH
+
+/// \file
+///
+/// \brief Save document information as an image.
+
+# include <libgen.h>
+# include <fstream>
+# include <sstream>
+
+# include <map>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/io/magick/save.hh>
+# include <mln/subsampling/antialiased.hh>
+# include <mln/data/transform_inplace.hh>
+
+# include <scribo/core/document.hh>
+
+# include <scribo/io/img/internal/text_img_visitor.hh>
+# include <scribo/io/img/internal/non_text_img_visitor.hh>
+# include <scribo/io/img/internal/full_img_visitor.hh>
+# include <scribo/io/img/internal/debug_img_visitor.hh>
+
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ /*! \brief Supported image formats
+
+ Text : Display text regions.
+
+ NonText : Display non-text regions.
+
+ Full : Text and non-text regions.
+ */
+ enum Format
+ {
+ Text,
+ NonText,
+ Full,
+ DebugWoImage,
+ DebugWithImage,
+ };
+
+
+ /*! \brief Save document information as an image
+
+ */
+ template <typename L>
+ void
+ save(const document<L>& doc, const std::string& output_name,
+ Format format);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ struct highlight_mask
+ : Function_v2v<highlight_mask>
+ {
+ typedef value::rgb8 result;
+
+ highlight_mask(float ratio)
+ : ratio(ratio)
+ {
+ }
+
+ result operator()(const result& v) const
+ {
+ result out = v;
+ out.red() = std::min(out.red() * ratio, 255.f);
+ out.green() = std::min(out.green() * ratio, 255.f);
+ out.blue() = std::min(out.blue() * ratio, 255.f);
+ return out;
+ }
+
+ float ratio;
+ };
+
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_text(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8> output = duplicate(doc.image());
+ scribo::io::img::internal::text_img_visitor f(output);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_non_text(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8> output = duplicate(doc.image());
+ scribo::io::img::internal::non_text_img_visitor f(output);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_full(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8> output = duplicate(doc.image());
+ scribo::io::img::internal::full_img_visitor f(output);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_debug_without_image(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8>
+ output(box2d(doc.image().domain().pmin() / 4,
+ doc.image().domain().pmax() / 4));
+ data::fill(output, literal::black);
+ scribo::io::img::internal::debug_img_visitor f(output, 4);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_debug_with_image(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8>
+ output = mln::subsampling::antialiased(doc.image(), 4);
+ internal::highlight_mask highlight(0.5f);
+ data::transform_inplace(output, highlight);
+ scribo::io::img::internal::debug_img_visitor f(output, 4);
+ doc.accept(f);
+ return output;
+ }
+
+ } // end of namespace scribo::io::img::internal
+
+
+
+ // FACADE
+
+ template <typename L>
+ void
+ save(const document<L>& doc,
+ const std::string& output_name,
+ Format format)
+ {
+ trace::entering("scribo::io::img::save");
+
+ mln_precondition(doc.is_open());
+
+ mln::image2d<value::rgb8> output;
+
+ // Choose saving method.
+ switch (format)
+ {
+ case Text:
+ output = internal::save_text(doc);
+ break;
+
+ case NonText:
+ output = internal::save_non_text(doc);
+ break;
+
+ case Full:
+ output = internal::save_full(doc);
+ break;
+
+ case DebugWoImage:
+ output = internal::save_debug_without_image(doc);
+ break;
+
+ case DebugWithImage:
+ output = internal::save_debug_with_image(doc);
+ break;
+
+ default:
+ trace::warning("scribo::io::img::save - "
+ "Invalid image format! Skip saving...");
+ trace::exiting("scribo::io::img::save");
+ return;
+ }
+
+ mln::io::magick::save(output, output_name.c_str());
+
+ trace::exiting("scribo::io::img::save");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_IO_IMG_SAVE_HH
--
1.5.6.5
1
0

14 Mar '11
* scribo/fun/v2v/highlight.hh,
* scribo/io/img/internal/debug_img_visitor.hh,
* scribo/io/img/internal/draw_edges.hh,
* scribo/io/img/internal/full_img_visitor.hh,
* scribo/io/img/internal/non_text_img_visitor.hh,
* scribo/io/img/internal/text_img_visitor.hh,
* scribo/io/img/save.hh: New.
---
scribo/ChangeLog | 12 +
.../serializable.hh => fun/v2v/highlight.hh} | 57 +++--
scribo/scribo/io/img/internal/debug_img_visitor.hh | 263 ++++++++++++++++++++
.../internal/draw_edges.hh} | 62 +++---
scribo/scribo/io/img/internal/full_img_visitor.hh | 194 ++++++++++++++
.../scribo/io/img/internal/non_text_img_visitor.hh | 162 ++++++++++++
scribo/scribo/io/img/internal/text_img_visitor.hh | 164 ++++++++++++
scribo/scribo/io/img/save.hh | 242 ++++++++++++++++++
8 files changed, 1104 insertions(+), 52 deletions(-)
copy scribo/scribo/{core/concept/serializable.hh => fun/v2v/highlight.hh} (66%)
create mode 100644 scribo/scribo/io/img/internal/debug_img_visitor.hh
copy scribo/scribo/io/{xml/internal/print_box_coords.hh => img/internal/draw_edges.hh} (56%)
create mode 100644 scribo/scribo/io/img/internal/full_img_visitor.hh
create mode 100644 scribo/scribo/io/img/internal/non_text_img_visitor.hh
create mode 100644 scribo/scribo/io/img/internal/text_img_visitor.hh
create mode 100644 scribo/scribo/io/img/save.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 5b96508..43041fe 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,17 @@
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Introduce result image output.
+
+ * scribo/fun/v2v/highlight.hh,
+ * scribo/io/img/internal/debug_img_visitor.hh,
+ * scribo/io/img/internal/draw_edges.hh,
+ * scribo/io/img/internal/full_img_visitor.hh,
+ * scribo/io/img/internal/non_text_img_visitor.hh,
+ * scribo/io/img/internal/text_img_visitor.hh,
+ * scribo/io/img/save.hh: New.
+
+2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Save image edge coordinates in XML output.
* scribo/io/xml/internal/extended_page_xml_visitor.hh: Here.
diff --git a/scribo/scribo/core/concept/serializable.hh b/scribo/scribo/fun/v2v/highlight.hh
similarity index 66%
copy from scribo/scribo/core/concept/serializable.hh
copy to scribo/scribo/fun/v2v/highlight.hh
index 6e661a6..835be59 100644
--- a/scribo/scribo/core/concept/serializable.hh
+++ b/scribo/scribo/fun/v2v/highlight.hh
@@ -23,42 +23,55 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
-# define SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
+#ifndef SCRIBO_FUN_V2V_HIGHLIGHT_HH
+# define SCRIBO_FUN_V2V_HIGHLIGHT_HH
-/// \file
-///
-/// Concept for serializer visitors.
+/// \brief Function increasing values to highlight areas.
-# include <mln/core/concept/object.hh>
-# include <scribo/core/concept/serialize_visitor.hh>
+# include <mln/core/concept/function.hh>
namespace scribo
{
- /// \brief Link functor concept.
- template <typename E>
- class Serializable : public mln::Object<E>
+ namespace fun
{
- public:
- template <typename E2>
- void accept(const SerializeVisitor<E2>& visitor) const;
- };
+
+ namespace v2v
+ {
+
+ template <typename R>
+ struct highlight
+ : mln::Function_v2v<highlight<R> >
+ {
+ typedef R result;
+
+ highlight();
+ result operator()(const result& v) const;
+ };
# ifndef MLN_INCLUDE_ONLY
- template <typename E>
- template <typename E2>
- void
- Serializable<E>::accept(const SerializeVisitor<E2>& visitor) const
- {
- exact(visitor).visit(exact(*this));
- }
+
+ template <typename R>
+ highlight<R>::highlight()
+ {
+ }
+
+
+ template <typename R>
+ typename highlight<R>::result
+ highlight<R>::operator()(const result& v) const
+ {
+ return v + v / 2;
+ }
# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace scribo::fun::v2v
+
+ } // end of namespace scribo::fun
} // end of namespace scribo
-#endif // SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
+#endif // ! SCRIBO_FUN_V2V_HIGHLIGHT_HH
diff --git a/scribo/scribo/io/img/internal/debug_img_visitor.hh b/scribo/scribo/io/img/internal/debug_img_visitor.hh
new file mode 100644
index 0000000..f1c689d
--- /dev/null
+++ b/scribo/scribo/io/img/internal/debug_img_visitor.hh
@@ -0,0 +1,263 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_DEBUG_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_DEBUG_IMG_VISITOR_HH
+
+/// \file
+///
+/// Save document image analysis to a small image.
+
+# include <fstream>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+# include <mln/subsampling/antialiased.hh>
+# include <mln/morpho/elementary/gradient_external.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/line_info.hh>
+
+# include <scribo/io/img/internal/draw_edges.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+
+ class debug_img_visitor : public doc_serializer<debug_img_visitor>
+ {
+ public:
+ // Constructor
+ debug_img_visitor(mln::image2d<value::rgb8>& out,
+ unsigned output_ratio);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ void visit(const component_info& info) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+ unsigned output_ratio;
+
+ mutable image2d<scribo::def::lbl_type> elt_edge;
+
+
+ private: // Methods
+ box2d compute_bbox(const box2d& b) const;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ box2d
+ debug_img_visitor::compute_bbox(const box2d& b) const
+ {
+ point2d
+ pmin = b.pmin() / output_ratio,
+ pmax = b.pmax() / output_ratio;
+
+ return box2d(pmin, pmax);
+ }
+
+
+ inline
+ debug_img_visitor::debug_img_visitor(mln::image2d<value::rgb8>& out,
+ unsigned output_ratio)
+ : output(out), output_ratio(output_ratio)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ debug_img_visitor::visit(const document<L>& doc) const
+ {
+ // Text
+ if (doc.has_text())
+ doc.paragraphs().accept(*this);
+
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ {
+ // Prepare element edges
+
+ // FIXME: UGLY! Too slow!
+ scribo::def::lbl_type nlabels;
+ component_set<L> elts = primitive::extract::components(
+ data::convert(bool(), mln::subsampling::antialiased(doc.elements().labeled_image(),
+ output_ratio)),
+ c8(),
+ nlabels);
+
+ // Preserving elements tags
+ if (doc.elements().nelements() != elts.nelements())
+ {
+ std::cerr << "Warnig: could not preserve element type in "
+ << "img debug output." << std::endl;
+ std::cerr << "The number of non text element has changed while "
+ << "subsampling images : "
+ << doc.elements().nelements() << " vs "
+ << elts.nelements() << std::endl;
+ }
+ else
+ for_all_comps(c, doc.elements())
+ elts(c).update_type(doc.elements()(c).type());
+
+ elt_edge = morpho::elementary::gradient_external(elts.labeled_image(), c8());
+
+// const component_set<L>& elts = doc.elements();
+ for_all_comps(e, elts)
+ if (elts(e).is_valid())
+ elts(e).accept(*this);
+ }
+
+
+ // line seraparators
+ if (doc.has_vline_seps())
+ for_all_comps(c, doc.vline_seps_comps())
+ doc.vline_seps_comps()(c).accept(*this);
+ if (doc.has_hline_seps())
+ for_all_comps(c, doc.hline_seps_comps())
+ doc.hline_seps_comps()(c).accept(*this);
+
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ debug_img_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::LineSeparator:
+ {
+ mln::draw::box(output, compute_bbox(info.bbox()),
+ literal::cyan);
+ }
+ break;
+
+
+ default:
+ case component::Image:
+ {
+ // The bbox does not need to be reajusted to the
+ // subsampled domain since it has been recomputed while
+ // computing the edge image.
+ //
+ // However, the bbox must be enlarged since only the
+ // _external_ edge is computed.
+ box2d b = info.bbox();
+ b.enlarge(1);
+ b.crop_wrt(output.domain());
+ data::fill(((output | b).rw()
+ | (pw::value(elt_edge)
+ == pw::cst((scribo::def::lbl_type)info.id().to_equiv()))).rw(),
+ literal::orange);
+ }
+ break;
+ }
+ }
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ debug_img_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+ lines(l).accept(*this);
+ }
+
+ box2d b = compute_bbox(parset(p).bbox());
+ b.enlarge(1);
+ b.crop_wrt(output.domain());
+ mln::draw::box(output, b, literal::blue);
+ }
+ }
+
+
+ template <typename L>
+ void
+ debug_img_visitor::visit(const line_info<L>& line) const
+ {
+ point2d
+ pmin = line.bbox().pmin(),
+ pmax = line.bbox().pmax();
+ pmax.row() = line.baseline();
+ pmin.row() = line.baseline();
+
+ pmin = pmin / output_ratio;
+ pmax = pmax / output_ratio;
+
+ mln::draw::line(output, pmin, pmax, literal::red);
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_DEBUG_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/xml/internal/print_box_coords.hh b/scribo/scribo/io/img/internal/draw_edges.hh
similarity index 56%
copy from scribo/scribo/io/xml/internal/print_box_coords.hh
copy to scribo/scribo/io/img/internal/draw_edges.hh
index ad84709..664a352 100644
--- a/scribo/scribo/io/xml/internal/print_box_coords.hh
+++ b/scribo/scribo/io/img/internal/draw_edges.hh
@@ -23,15 +23,26 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
-# define SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#ifndef SCRIBO_IO_IMG_INTERNAL_DRAW_EDGES_HH
+# define SCRIBO_IO_IMG_INTERNAL_DRAW_EDGES_HH
/// \file
///
-/// \brief Prints box2d coordinates to XML data.
+/// \brief Draw object edges.
# include <fstream>
-# include <mln/core/alias/box2d.hh>
+# include <mln/core/image/image2d.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+# include <mln/pw/all.hh>
+# include <mln/data/fill.hh>
+# include <mln/data/convert.hh>
+# include <mln/literal/colors.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/morpho/elementary/gradient_external.hh>
+
+# include <scribo/core/component_info.hh>
+# include <scribo/core/def/lbl_type.hh>
+
namespace scribo
{
@@ -39,7 +50,7 @@ namespace scribo
namespace io
{
- namespace xml
+ namespace img
{
namespace internal
@@ -47,11 +58,12 @@ namespace scribo
using namespace mln;
- /*! \brief Prints box2d coordinates to XML data.
+ /*! \brief Draw component edges.
*/
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space);
+ draw_edges(const component_info& info,
+ image2d<value::rgb8>& output, const value::rgb8& value,
+ const image2d<scribo::def::lbl_type>& edges);
# ifndef MLN_INCLUDE_ONLY
@@ -59,37 +71,27 @@ namespace scribo
inline
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space)
+ draw_edges(const component_info& info,
+ image2d<value::rgb8>& output, const value::rgb8& value,
+ const image2d<scribo::def::lbl_type>& edges)
{
- std::string sc = space;
- std::string sp = sc + " ";
- ostr << sc << "<coords>" << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sc << "</coords>" << std::endl;
-
+ box2d b = info.bbox();
+ b.enlarge(1);
+ data::fill(((output | b).rw()
+ | (pw::value(edges)
+ == pw::cst((scribo::def::lbl_type)info.id().to_equiv()))).rw(),
+ value);
}
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace scribo::io::xml::internal
+ } // end of namespace scribo::io::img::internal
- } // end of namespace scribo::io::xml
+ } // end of namespace scribo::io::img
} // end of namespace scribo::io
} // end of namespace scribo
-#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#endif // ! SCRIBO_IO_IMG_INTERNAL_DRAW_EDGES_HH
diff --git a/scribo/scribo/io/img/internal/full_img_visitor.hh b/scribo/scribo/io/img/internal/full_img_visitor.hh
new file mode 100644
index 0000000..30987db
--- /dev/null
+++ b/scribo/scribo/io/img/internal/full_img_visitor.hh
@@ -0,0 +1,194 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_FULL_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_FULL_IMG_VISITOR_HH
+
+/// \file
+///
+/// Save document image analysis to an image.
+
+# include <fstream>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/line_info.hh>
+
+# include <scribo/io/img/internal/draw_edges.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+
+ class full_img_visitor : public doc_serializer<full_img_visitor>
+ {
+ public:
+ // Constructor
+ full_img_visitor(mln::image2d<value::rgb8>& out);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ void visit(const component_info& info) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+
+ mutable image2d<scribo::def::lbl_type> elt_edge;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ full_img_visitor::full_img_visitor(mln::image2d<value::rgb8>& out)
+ : output(out)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ full_img_visitor::visit(const document<L>& doc) const
+ {
+ // Text
+ if (doc.has_text())
+ doc.paragraphs().accept(*this);
+
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ {
+ // Prepare element edges
+ elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c8());
+
+ const component_set<L>& elts = doc.elements();
+ for_all_comps(e, elts)
+ if (elts(e).is_valid())
+ elts(e).accept(*this);
+ }
+
+
+ // line seraparators
+ if (doc.has_vline_seps())
+ for_all_comps(c, doc.vline_seps_comps())
+ doc.vline_seps_comps()(c).accept(*this);
+ if (doc.has_hline_seps())
+ for_all_comps(c, doc.hline_seps_comps())
+ doc.hline_seps_comps()(c).accept(*this);
+
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ full_img_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::LineSeparator:
+ {
+ mln::draw::box(output, info.bbox(), literal::cyan);
+ }
+ break;
+
+
+ default:
+ case component::Image:
+ {
+ draw_edges(info, output, literal::orange, elt_edge);
+ }
+ break;
+ }
+ }
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ full_img_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+ lines(l).accept(*this);
+ }
+
+ mln::draw::box(output, parset(p).bbox(), literal::blue);
+ }
+ }
+
+
+ template <typename L>
+ void
+ full_img_visitor::visit(const line_info<L>& line) const
+ {
+ mln::draw::box(output, line.bbox(), literal::red);
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_FULL_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/img/internal/non_text_img_visitor.hh b/scribo/scribo/io/img/internal/non_text_img_visitor.hh
new file mode 100644
index 0000000..24b027e
--- /dev/null
+++ b/scribo/scribo/io/img/internal/non_text_img_visitor.hh
@@ -0,0 +1,162 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH
+
+/// \file
+///
+/// \brief Save non-text information as an image.
+
+# include <fstream>
+
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/io/img/internal/draw_edges.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+ /*! \brief Save non-text information as an image.
+ */
+ class non_text_img_visitor : public doc_serializer<non_text_img_visitor>
+ {
+ public:
+ // Constructor
+ non_text_img_visitor(mln::image2d<value::rgb8>& out);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ template <typename L>
+ void visit(const component_set<L>& comp_set) const;
+
+ void visit(const component_info& info) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+
+ mutable image2d<scribo::def::lbl_type> elt_edge;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ non_text_img_visitor::non_text_img_visitor(mln::image2d<value::rgb8>& out)
+ : output(out)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ non_text_img_visitor::visit(const document<L>& doc) const
+ {
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ {
+ // Prepare element edges
+ elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c8());
+
+ doc.elements().accept(*this);
+ }
+
+ // line seraparators
+ if (doc.has_hline_seps())
+ doc.hline_seps_comps().accept(*this);
+ if (doc.has_vline_seps())
+ doc.vline_seps_comps().accept(*this);
+ }
+
+
+ /// Component Set
+ //
+ template <typename L>
+ void
+ non_text_img_visitor::visit(const component_set<L>& comp_set) const
+ {
+ for_all_comps(c, comp_set)
+ if (comp_set(c).is_valid())
+ comp_set(c).accept(*this);
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ non_text_img_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::LineSeparator:
+ {
+ mln::draw::box(output, info.bbox(), literal::cyan);
+ }
+ break;
+
+
+ default:
+ case component::Image:
+ {
+ draw_edges(info, output, literal::orange, elt_edge);
+ }
+ break;
+ }
+ }
+
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/img/internal/text_img_visitor.hh b/scribo/scribo/io/img/internal/text_img_visitor.hh
new file mode 100644
index 0000000..7629bf7
--- /dev/null
+++ b/scribo/scribo/io/img/internal/text_img_visitor.hh
@@ -0,0 +1,164 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_INTERNAL_TEXT_IMG_VISITOR_HH
+# define SCRIBO_IO_IMG_INTERNAL_TEXT_IMG_VISITOR_HH
+
+/// \file
+///
+/// Image output with text related information.
+
+# include <fstream>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/draw/box.hh>
+# include <mln/literal/colors.hh>
+
+# include <scribo/core/internal/doc_serializer.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/line_info.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ namespace internal
+ {
+
+
+ class text_img_visitor : public doc_serializer<text_img_visitor>
+ {
+ public:
+ // Constructor
+ text_img_visitor(mln::image2d<value::rgb8>&);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ template <typename L>
+ void visit(const component_set<L>& comp_set) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+
+ private: // Attributes
+ mln::image2d<value::rgb8>& output;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ inline
+ text_img_visitor::text_img_visitor(mln::image2d<value::rgb8>& out)
+ : output(out)
+ {
+ mln_assertion(output.is_valid());
+ }
+
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ text_img_visitor::visit(const document<L>& doc) const
+ {
+ mln_precondition(doc.is_open());
+
+ // Prepare output image.
+ output = duplicate(doc.image());
+
+
+ // Text
+ if (doc.has_text())
+ doc.paragraphs().accept(*this);
+ }
+
+ /// Component Set
+ //
+ template <typename L>
+ void
+ text_img_visitor::visit(const component_set<L>& comp_set) const
+ {
+ for_all_comps(c, comp_set)
+ if (comp_set(c).is_valid())
+ comp_set(c).accept(*this);
+ }
+
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ text_img_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+ lines(l).accept(*this);
+ }
+
+ mln::draw::box(output, parset(p).bbox(), literal::blue);
+ }
+ }
+
+
+ template <typename L>
+ void
+ text_img_visitor::visit(const line_info<L>& line) const
+ {
+ mln::draw::box(output, line.bbox(), literal::red);
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img::internal
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_IMG_INTERNAL_TEXT_IMG_VISITOR_HH
diff --git a/scribo/scribo/io/img/save.hh b/scribo/scribo/io/img/save.hh
new file mode 100644
index 0000000..56300d6
--- /dev/null
+++ b/scribo/scribo/io/img/save.hh
@@ -0,0 +1,242 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_IMG_SAVE_HH
+# define SCRIBO_IO_IMG_SAVE_HH
+
+/// \file
+///
+/// \brief Save document information as an image.
+
+# include <libgen.h>
+# include <fstream>
+# include <sstream>
+
+# include <map>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/io/magick/save.hh>
+# include <mln/subsampling/antialiased.hh>
+# include <mln/data/transform_inplace.hh>
+
+# include <scribo/core/document.hh>
+
+# include <scribo/io/img/internal/text_img_visitor.hh>
+# include <scribo/io/img/internal/non_text_img_visitor.hh>
+# include <scribo/io/img/internal/full_img_visitor.hh>
+# include <scribo/io/img/internal/debug_img_visitor.hh>
+
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace img
+ {
+
+ /*! \brief Supported image formats
+
+ Text : Display text regions.
+
+ NonText : Display non-text regions.
+
+ Full : Text and non-text regions.
+ */
+ enum Format
+ {
+ Text,
+ NonText,
+ Full,
+ DebugWoImage,
+ DebugWithImage,
+ };
+
+
+ /*! \brief Save document information as an image
+
+ */
+ template <typename L>
+ void
+ save(const document<L>& doc, const std::string& output_name,
+ Format format);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ struct highlight_mask
+ : Function_v2v<highlight_mask>
+ {
+ typedef value::rgb8 result;
+
+ highlight_mask(float ratio)
+ : ratio(ratio)
+ {
+ }
+
+ result operator()(const result& v) const
+ {
+ result out = v;
+ out.red() = std::min(out.red() * ratio, 255.f);
+ out.green() = std::min(out.green() * ratio, 255.f);
+ out.blue() = std::min(out.blue() * ratio, 255.f);
+ return out;
+ }
+
+ float ratio;
+ };
+
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_text(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8> output = duplicate(doc.image());
+ scribo::io::img::internal::text_img_visitor f(output);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_non_text(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8> output = duplicate(doc.image());
+ scribo::io::img::internal::non_text_img_visitor f(output);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_full(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8> output = duplicate(doc.image());
+ scribo::io::img::internal::full_img_visitor f(output);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_debug_without_image(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8>
+ output(box2d(doc.image().domain().pmin() / 4,
+ doc.image().domain().pmax() / 4));
+ data::fill(output, literal::black);
+ scribo::io::img::internal::debug_img_visitor f(output, 4);
+ doc.accept(f);
+ return output;
+ }
+
+ template <typename L>
+ mln::image2d<value::rgb8>
+ save_debug_with_image(const document<L>& doc)
+ {
+ mln_precondition(doc.is_valid());
+ mln::image2d<value::rgb8>
+ output = mln::subsampling::antialiased(doc.image(), 4);
+ internal::highlight_mask highlight(0.5f);
+ data::transform_inplace(output, highlight);
+ scribo::io::img::internal::debug_img_visitor f(output, 4);
+ doc.accept(f);
+ return output;
+ }
+
+ } // end of namespace scribo::io::img::internal
+
+
+
+ // FACADE
+
+ template <typename L>
+ void
+ save(const document<L>& doc,
+ const std::string& output_name,
+ Format format)
+ {
+ trace::entering("scribo::io::img::save");
+
+ mln_precondition(doc.is_open());
+
+ mln::image2d<value::rgb8> output;
+
+ // Choose saving method.
+ switch (format)
+ {
+ case Text:
+ output = internal::save_text(doc);
+ break;
+
+ case NonText:
+ output = internal::save_non_text(doc);
+ break;
+
+ case Full:
+ output = internal::save_full(doc);
+ break;
+
+ case DebugWoImage:
+ output = internal::save_debug_without_image(doc);
+ break;
+
+ case DebugWithImage:
+ output = internal::save_debug_with_image(doc);
+ break;
+
+ default:
+ trace::warning("scribo::io::img::save - "
+ "Invalid image format! Skip saving...");
+ trace::exiting("scribo::io::img::save");
+ return;
+ }
+
+ mln::io::magick::save(output, output_name.c_str());
+
+ trace::exiting("scribo::io::img::save");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::img
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_IO_IMG_SAVE_HH
--
1.5.6.5
1
0

last-svn-commit-807-g4c0ed4e Save image edge coordinates in XML output.
by Guillaume Lazzara 14 Mar '11
by Guillaume Lazzara 14 Mar '11
14 Mar '11
* scribo/io/xml/internal/extended_page_xml_visitor.hh: Here.
* scribo/io/xml/internal/print_image_coords.hh: New.
---
scribo/ChangeLog | 8 ++++
.../io/xml/internal/extended_page_xml_visitor.hh | 22 ++++++++-
.../{print_box_coords.hh => print_image_coords.hh} | 45 ++++++++++----------
3 files changed, 49 insertions(+), 26 deletions(-)
copy scribo/scribo/io/xml/internal/{print_box_coords.hh => print_image_coords.hh} (66%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index d63fa40..5cca1e2 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,13 @@
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Save image edge coordinates in XML output.
+
+ * scribo/io/xml/internal/extended_page_xml_visitor.hh: Here.
+
+ * scribo/io/xml/internal/print_image_coords.hh: New.
+
+2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* scribo/filter/object_links_aligned.hh: New.
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
index e8c7689..44d8342 100644
--- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
@@ -31,7 +31,13 @@
/// Extended XML PAGE format serializer Visitor.
# include <fstream>
-# include <scribo/core/internal/doc_xml_serializer.hh>
+
+# include <mln/morpho/elementary/gradient_external.hh>
+# include <mln/pw/all.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+
+# include <scribo/core/def/lbl_type.hh>
+
# include <scribo/core/internal/doc_serializer.hh>
# include <scribo/core/document.hh>
# include <scribo/core/component_set.hh>
@@ -42,6 +48,7 @@
# include <scribo/core/line_info.hh>
# include <scribo/io/xml/internal/print_box_coords.hh>
+# include <scribo/io/xml/internal/print_image_coords.hh>
# include <scribo/io/xml/internal/print_page_preambule.hh>
@@ -81,6 +88,7 @@ namespace scribo
private: // Attributes
std::ofstream& output;
+ mutable image2d<scribo::def::lbl_type> elt_edge;
};
@@ -112,7 +120,12 @@ namespace scribo
// Page elements (Pictures, ...)
if (doc.has_elements())
+ {
+ // Prepare element edges
+ elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c4());
+
doc.elements().accept(*this);
+ }
// line seraparators
if (doc.has_vline_seps())
@@ -184,7 +197,10 @@ namespace scribo
<< " img_emb_text=\"No\" "
<< " img_bgcolour=\"White\">" << std::endl;
- internal::print_box_coords(output, info.bbox(), " ");
+ internal::print_image_coords(output,
+ ((elt_edge | info.bbox())
+ | (pw::value(elt_edge) == pw::cst((scribo::def::lbl_type)info.id().to_equiv()))).domain(),
+ " ");
output << " </image_region>" << std::endl;
break;
@@ -252,7 +268,7 @@ namespace scribo
output << " <line text=\"" << line.html_text() << "\" ";
}
else
- output << " <line " << std::endl;
+ output << " <line ";
output << "id=\"" << line.id()
<< "\" txt_orientation=\"" << line.orientation()
diff --git a/scribo/scribo/io/xml/internal/print_box_coords.hh b/scribo/scribo/io/xml/internal/print_image_coords.hh
similarity index 66%
copy from scribo/scribo/io/xml/internal/print_box_coords.hh
copy to scribo/scribo/io/xml/internal/print_image_coords.hh
index ad84709..ebfe402 100644
--- a/scribo/scribo/io/xml/internal/print_box_coords.hh
+++ b/scribo/scribo/io/xml/internal/print_image_coords.hh
@@ -23,15 +23,15 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
-# define SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
+# define SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
/// \file
///
/// \brief Prints box2d coordinates to XML data.
# include <fstream>
-# include <mln/core/alias/box2d.hh>
+# include <mln/core/concept/site_set.hh>
namespace scribo
{
@@ -49,36 +49,35 @@ namespace scribo
/*! \brief Prints box2d coordinates to XML data.
*/
+ template <typename S>
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space);
+ print_image_coords(std::ofstream& ostr, const mln::Site_Set<S>& b,
+ const char *space);
# ifndef MLN_INCLUDE_ONLY
- inline
+ template <typename S>
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space)
+ print_image_coords(std::ofstream& ostr, const mln::Site_Set<S>& b_,
+ const char *space)
{
std::string sc = space;
std::string sp = sc + " ";
- ostr << sc << "<coords>" << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sc << "</coords>" << std::endl;
+ const S& b = exact(b_);
+ mln_precondition(b.is_valid());
+
+ ostr << sc << "<coords>" << std::endl;
+
+ mln_piter(S) p(b);
+ for_all(p)
+ ostr << sp << "<point x=\"" << p.col()
+ << "\" y=\"" << p.row() << "\"/>"
+ << std::endl;
+
+ ostr << sc << "</coords>" << std::endl;
}
@@ -92,4 +91,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
--
1.5.6.5
1
0

last-svn-commit-806-g1e9c3e5 Save image edge coordinates in XML output.
by Guillaume Lazzara 14 Mar '11
by Guillaume Lazzara 14 Mar '11
14 Mar '11
* scribo/io/xml/internal/extended_page_xml_visitor.hh: Here.
* scribo/io/xml/internal/print_image_coords.hh: New.
---
scribo/ChangeLog | 8 ++++
.../io/xml/internal/extended_page_xml_visitor.hh | 22 ++++++++-
.../{print_box_coords.hh => print_image_coords.hh} | 45 ++++++++++----------
3 files changed, 49 insertions(+), 26 deletions(-)
copy scribo/scribo/io/xml/internal/{print_box_coords.hh => print_image_coords.hh} (66%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 1644058..5b96508 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,13 @@
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Save image edge coordinates in XML output.
+
+ * scribo/io/xml/internal/extended_page_xml_visitor.hh: Here.
+
+ * scribo/io/xml/internal/print_image_coords.hh: New.
+
+2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* scribo/filter/object_links_aligned.hh: New.
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
index e8c7689..44d8342 100644
--- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
@@ -31,7 +31,13 @@
/// Extended XML PAGE format serializer Visitor.
# include <fstream>
-# include <scribo/core/internal/doc_xml_serializer.hh>
+
+# include <mln/morpho/elementary/gradient_external.hh>
+# include <mln/pw/all.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+
+# include <scribo/core/def/lbl_type.hh>
+
# include <scribo/core/internal/doc_serializer.hh>
# include <scribo/core/document.hh>
# include <scribo/core/component_set.hh>
@@ -42,6 +48,7 @@
# include <scribo/core/line_info.hh>
# include <scribo/io/xml/internal/print_box_coords.hh>
+# include <scribo/io/xml/internal/print_image_coords.hh>
# include <scribo/io/xml/internal/print_page_preambule.hh>
@@ -81,6 +88,7 @@ namespace scribo
private: // Attributes
std::ofstream& output;
+ mutable image2d<scribo::def::lbl_type> elt_edge;
};
@@ -112,7 +120,12 @@ namespace scribo
// Page elements (Pictures, ...)
if (doc.has_elements())
+ {
+ // Prepare element edges
+ elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c4());
+
doc.elements().accept(*this);
+ }
// line seraparators
if (doc.has_vline_seps())
@@ -184,7 +197,10 @@ namespace scribo
<< " img_emb_text=\"No\" "
<< " img_bgcolour=\"White\">" << std::endl;
- internal::print_box_coords(output, info.bbox(), " ");
+ internal::print_image_coords(output,
+ ((elt_edge | info.bbox())
+ | (pw::value(elt_edge) == pw::cst((scribo::def::lbl_type)info.id().to_equiv()))).domain(),
+ " ");
output << " </image_region>" << std::endl;
break;
@@ -252,7 +268,7 @@ namespace scribo
output << " <line text=\"" << line.html_text() << "\" ";
}
else
- output << " <line " << std::endl;
+ output << " <line ";
output << "id=\"" << line.id()
<< "\" txt_orientation=\"" << line.orientation()
diff --git a/scribo/scribo/io/xml/internal/print_box_coords.hh b/scribo/scribo/io/xml/internal/print_image_coords.hh
similarity index 66%
copy from scribo/scribo/io/xml/internal/print_box_coords.hh
copy to scribo/scribo/io/xml/internal/print_image_coords.hh
index ad84709..ebfe402 100644
--- a/scribo/scribo/io/xml/internal/print_box_coords.hh
+++ b/scribo/scribo/io/xml/internal/print_image_coords.hh
@@ -23,15 +23,15 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
-# define SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
+# define SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
/// \file
///
/// \brief Prints box2d coordinates to XML data.
# include <fstream>
-# include <mln/core/alias/box2d.hh>
+# include <mln/core/concept/site_set.hh>
namespace scribo
{
@@ -49,36 +49,35 @@ namespace scribo
/*! \brief Prints box2d coordinates to XML data.
*/
+ template <typename S>
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space);
+ print_image_coords(std::ofstream& ostr, const mln::Site_Set<S>& b,
+ const char *space);
# ifndef MLN_INCLUDE_ONLY
- inline
+ template <typename S>
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space)
+ print_image_coords(std::ofstream& ostr, const mln::Site_Set<S>& b_,
+ const char *space)
{
std::string sc = space;
std::string sp = sc + " ";
- ostr << sc << "<coords>" << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sc << "</coords>" << std::endl;
+ const S& b = exact(b_);
+ mln_precondition(b.is_valid());
+
+ ostr << sc << "<coords>" << std::endl;
+
+ mln_piter(S) p(b);
+ for_all(p)
+ ostr << sp << "<point x=\"" << p.col()
+ << "\" y=\"" << p.row() << "\"/>"
+ << std::endl;
+
+ ostr << sc << "</coords>" << std::endl;
}
@@ -92,4 +91,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
--
1.5.6.5
1
0

last-svn-commit-806-g8aaa787 Save image edge coordinates in XML output.
by Guillaume Lazzara 14 Mar '11
by Guillaume Lazzara 14 Mar '11
14 Mar '11
* scribo/io/xml/internal/extended_page_xml_visitor.hh: Here.
* scribo/io/xml/internal/print_image_coords.hh: New.
---
scribo/ChangeLog | 8 ++++
.../io/xml/internal/extended_page_xml_visitor.hh | 22 ++++++++-
.../{print_box_coords.hh => print_image_coords.hh} | 45 ++++++++++----------
3 files changed, 49 insertions(+), 26 deletions(-)
copy scribo/scribo/io/xml/internal/{print_box_coords.hh => print_image_coords.hh} (66%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 1644058..5b96508 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,13 @@
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Save image edge coordinates in XML output.
+
+ * scribo/io/xml/internal/extended_page_xml_visitor.hh: Here.
+
+ * scribo/io/xml/internal/print_image_coords.hh: New.
+
+2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* scribo/filter/object_links_aligned.hh: New.
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
index e8c7689..44d8342 100644
--- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
@@ -31,7 +31,13 @@
/// Extended XML PAGE format serializer Visitor.
# include <fstream>
-# include <scribo/core/internal/doc_xml_serializer.hh>
+
+# include <mln/morpho/elementary/gradient_external.hh>
+# include <mln/pw/all.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+
+# include <scribo/core/def/lbl_type.hh>
+
# include <scribo/core/internal/doc_serializer.hh>
# include <scribo/core/document.hh>
# include <scribo/core/component_set.hh>
@@ -42,6 +48,7 @@
# include <scribo/core/line_info.hh>
# include <scribo/io/xml/internal/print_box_coords.hh>
+# include <scribo/io/xml/internal/print_image_coords.hh>
# include <scribo/io/xml/internal/print_page_preambule.hh>
@@ -81,6 +88,7 @@ namespace scribo
private: // Attributes
std::ofstream& output;
+ mutable image2d<scribo::def::lbl_type> elt_edge;
};
@@ -112,7 +120,12 @@ namespace scribo
// Page elements (Pictures, ...)
if (doc.has_elements())
+ {
+ // Prepare element edges
+ elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c4());
+
doc.elements().accept(*this);
+ }
// line seraparators
if (doc.has_vline_seps())
@@ -184,7 +197,10 @@ namespace scribo
<< " img_emb_text=\"No\" "
<< " img_bgcolour=\"White\">" << std::endl;
- internal::print_box_coords(output, info.bbox(), " ");
+ internal::print_image_coords(output,
+ ((elt_edge | info.bbox())
+ | (pw::value(elt_edge) == pw::cst((scribo::def::lbl_type)info.id().to_equiv()))).domain(),
+ " ");
output << " </image_region>" << std::endl;
break;
@@ -252,7 +268,7 @@ namespace scribo
output << " <line text=\"" << line.html_text() << "\" ";
}
else
- output << " <line " << std::endl;
+ output << " <line ";
output << "id=\"" << line.id()
<< "\" txt_orientation=\"" << line.orientation()
diff --git a/scribo/scribo/io/xml/internal/print_box_coords.hh b/scribo/scribo/io/xml/internal/print_image_coords.hh
similarity index 66%
copy from scribo/scribo/io/xml/internal/print_box_coords.hh
copy to scribo/scribo/io/xml/internal/print_image_coords.hh
index ad84709..ebfe402 100644
--- a/scribo/scribo/io/xml/internal/print_box_coords.hh
+++ b/scribo/scribo/io/xml/internal/print_image_coords.hh
@@ -23,15 +23,15 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
-# define SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
+# define SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
/// \file
///
/// \brief Prints box2d coordinates to XML data.
# include <fstream>
-# include <mln/core/alias/box2d.hh>
+# include <mln/core/concept/site_set.hh>
namespace scribo
{
@@ -49,36 +49,35 @@ namespace scribo
/*! \brief Prints box2d coordinates to XML data.
*/
+ template <typename S>
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space);
+ print_image_coords(std::ofstream& ostr, const mln::Site_Set<S>& b,
+ const char *space);
# ifndef MLN_INCLUDE_ONLY
- inline
+ template <typename S>
void
- print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space)
+ print_image_coords(std::ofstream& ostr, const mln::Site_Set<S>& b_,
+ const char *space)
{
std::string sc = space;
std::string sp = sc + " ";
- ostr << sc << "<coords>" << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sc << "</coords>" << std::endl;
+ const S& b = exact(b_);
+ mln_precondition(b.is_valid());
+
+ ostr << sc << "<coords>" << std::endl;
+
+ mln_piter(S) p(b);
+ for_all(p)
+ ostr << sp << "<point x=\"" << p.col()
+ << "\" y=\"" << p.row() << "\"/>"
+ << std::endl;
+
+ ostr << sc << "</coords>" << std::endl;
}
@@ -92,4 +91,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
--
1.5.6.5
1
0

last-svn-commit-806-g0d770d1 scribo/filter/object_links_aligned.hh: New.
by Guillaume Lazzara 14 Mar '11
by Guillaume Lazzara 14 Mar '11
14 Mar '11
---
scribo/ChangeLog | 4 ++
...s_bottom_aligned.hh => object_links_aligned.hh} | 39 ++++++++++----------
2 files changed, 23 insertions(+), 20 deletions(-)
copy scribo/scribo/filter/{object_links_bottom_aligned.hh => object_links_aligned.hh} (70%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index e248b55..d63fa40 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,9 @@
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * scribo/filter/object_links_aligned.hh: New.
+
+2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* scribo/primitive/extract/separators_nonvisible.hh: Cleanup and
improve debug support.
diff --git a/scribo/scribo/filter/object_links_bottom_aligned.hh b/scribo/scribo/filter/object_links_aligned.hh
similarity index 70%
copy from scribo/scribo/filter/object_links_bottom_aligned.hh
copy to scribo/scribo/filter/object_links_aligned.hh
index 2329f37..e37bcb6 100644
--- a/scribo/scribo/filter/object_links_bottom_aligned.hh
+++ b/scribo/scribo/filter/object_links_aligned.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,21 +23,18 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH
-# define SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH
+#ifndef SCRIBO_FILTER_OBJECT_LINKS_ALIGNED_HH
+# define SCRIBO_FILTER_OBJECT_LINKS_ALIGNED_HH
/// \file
///
-/// Invalidate links between two components if their bottom are not
-/// aligned.
-
-
-# include <mln/util/array.hh>
+/// Invalidate links between two components if their not aligned
+/// according to an anchor.
# include <scribo/core/macros.hh>
# include <scribo/core/object_links.hh>
-# include <scribo/filter/object_links_aligned.hh>
+# include <scribo/filter/object_links_non_aligned_simple.hh>
namespace scribo
{
@@ -48,11 +44,11 @@ namespace scribo
using namespace mln;
- /*! \brief Invalidate links between two components if their bottom are not
- aligned.
+ /*! \brief Invalidate links between two components according to a specific anchor.
\param[in] links Object links information.
\param[in] max_alpha Maximum angle value (degrees).
+ \param[in] anchor Anchor used to compute angles.
\verbatim
@@ -75,13 +71,15 @@ namespace scribo
~
\endverbatim
+ Example with an anchor set to the bottom right :
The angle between the two bottoms must be lower than \p max_alpha.
*/
template <typename L>
object_links<L>
- object_links_bottom_aligned(const object_links<L>& links,
- float max_alpha);
+ object_links_aligned(const object_links<L>& links,
+ float max_alpha,
+ anchor::Type anchor);
# ifndef MLN_INCLUDE_ONLY
@@ -89,17 +87,18 @@ namespace scribo
template <typename L>
object_links<L>
- object_links_bottom_aligned(const object_links<L>& links,
- float max_alpha)
+ object_links_aligned(const object_links<L>& links,
+ float max_alpha,
+ anchor::Type anchor)
{
- trace::entering("scribo::filter::object_links_bottom_aligned");
+ trace::entering("scribo::filter::object_links_aligned");
mln_precondition(links.is_valid());
object_links<L>
- output = object_links_aligned(links, max_alpha, anchor::Bottom);
+ output = object_links_non_aligned_simple(links, anchor, max_alpha);
- trace::exiting("scribo::filter::object_links_bottom_aligned");
+ trace::exiting("scribo::filter::object_links_aligned");
return output;
}
@@ -112,4 +111,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH
+#endif // ! SCRIBO_FILTER_OBJECT_LINKS_ALIGNED_HH
--
1.5.6.5
1
0

last-svn-commit-805-g65d9039 scribo/filter/object_links_aligned.hh: New.
by Guillaume Lazzara 14 Mar '11
by Guillaume Lazzara 14 Mar '11
14 Mar '11
---
scribo/ChangeLog | 4 ++
...s_bottom_aligned.hh => object_links_aligned.hh} | 39 ++++++++++----------
2 files changed, 23 insertions(+), 20 deletions(-)
copy scribo/scribo/filter/{object_links_bottom_aligned.hh => object_links_aligned.hh} (70%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index d9e7e96..1644058 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,9 @@
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * scribo/filter/object_links_aligned.hh: New.
+
+2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* scribo/primitive/extract/separators_nonvisible.hh: Cleanup and
improve debug support.
diff --git a/scribo/scribo/filter/object_links_bottom_aligned.hh b/scribo/scribo/filter/object_links_aligned.hh
similarity index 70%
copy from scribo/scribo/filter/object_links_bottom_aligned.hh
copy to scribo/scribo/filter/object_links_aligned.hh
index 2329f37..e37bcb6 100644
--- a/scribo/scribo/filter/object_links_bottom_aligned.hh
+++ b/scribo/scribo/filter/object_links_aligned.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,21 +23,18 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH
-# define SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH
+#ifndef SCRIBO_FILTER_OBJECT_LINKS_ALIGNED_HH
+# define SCRIBO_FILTER_OBJECT_LINKS_ALIGNED_HH
/// \file
///
-/// Invalidate links between two components if their bottom are not
-/// aligned.
-
-
-# include <mln/util/array.hh>
+/// Invalidate links between two components if their not aligned
+/// according to an anchor.
# include <scribo/core/macros.hh>
# include <scribo/core/object_links.hh>
-# include <scribo/filter/object_links_aligned.hh>
+# include <scribo/filter/object_links_non_aligned_simple.hh>
namespace scribo
{
@@ -48,11 +44,11 @@ namespace scribo
using namespace mln;
- /*! \brief Invalidate links between two components if their bottom are not
- aligned.
+ /*! \brief Invalidate links between two components according to a specific anchor.
\param[in] links Object links information.
\param[in] max_alpha Maximum angle value (degrees).
+ \param[in] anchor Anchor used to compute angles.
\verbatim
@@ -75,13 +71,15 @@ namespace scribo
~
\endverbatim
+ Example with an anchor set to the bottom right :
The angle between the two bottoms must be lower than \p max_alpha.
*/
template <typename L>
object_links<L>
- object_links_bottom_aligned(const object_links<L>& links,
- float max_alpha);
+ object_links_aligned(const object_links<L>& links,
+ float max_alpha,
+ anchor::Type anchor);
# ifndef MLN_INCLUDE_ONLY
@@ -89,17 +87,18 @@ namespace scribo
template <typename L>
object_links<L>
- object_links_bottom_aligned(const object_links<L>& links,
- float max_alpha)
+ object_links_aligned(const object_links<L>& links,
+ float max_alpha,
+ anchor::Type anchor)
{
- trace::entering("scribo::filter::object_links_bottom_aligned");
+ trace::entering("scribo::filter::object_links_aligned");
mln_precondition(links.is_valid());
object_links<L>
- output = object_links_aligned(links, max_alpha, anchor::Bottom);
+ output = object_links_non_aligned_simple(links, anchor, max_alpha);
- trace::exiting("scribo::filter::object_links_bottom_aligned");
+ trace::exiting("scribo::filter::object_links_aligned");
return output;
}
@@ -112,4 +111,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH
+#endif // ! SCRIBO_FILTER_OBJECT_LINKS_ALIGNED_HH
--
1.5.6.5
1
0

last-svn-commit-805-g3038605 scribo/filter/object_links_aligned.hh: New.
by Guillaume Lazzara 14 Mar '11
by Guillaume Lazzara 14 Mar '11
14 Mar '11
---
scribo/ChangeLog | 4 ++
...s_bottom_aligned.hh => object_links_aligned.hh} | 39 ++++++++++----------
2 files changed, 23 insertions(+), 20 deletions(-)
copy scribo/scribo/filter/{object_links_bottom_aligned.hh => object_links_aligned.hh} (70%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index d9e7e96..1644058 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,9 @@
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * scribo/filter/object_links_aligned.hh: New.
+
+2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* scribo/primitive/extract/separators_nonvisible.hh: Cleanup and
improve debug support.
diff --git a/scribo/scribo/filter/object_links_bottom_aligned.hh b/scribo/scribo/filter/object_links_aligned.hh
similarity index 70%
copy from scribo/scribo/filter/object_links_bottom_aligned.hh
copy to scribo/scribo/filter/object_links_aligned.hh
index 2329f37..e37bcb6 100644
--- a/scribo/scribo/filter/object_links_bottom_aligned.hh
+++ b/scribo/scribo/filter/object_links_aligned.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,21 +23,18 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH
-# define SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH
+#ifndef SCRIBO_FILTER_OBJECT_LINKS_ALIGNED_HH
+# define SCRIBO_FILTER_OBJECT_LINKS_ALIGNED_HH
/// \file
///
-/// Invalidate links between two components if their bottom are not
-/// aligned.
-
-
-# include <mln/util/array.hh>
+/// Invalidate links between two components if their not aligned
+/// according to an anchor.
# include <scribo/core/macros.hh>
# include <scribo/core/object_links.hh>
-# include <scribo/filter/object_links_aligned.hh>
+# include <scribo/filter/object_links_non_aligned_simple.hh>
namespace scribo
{
@@ -48,11 +44,11 @@ namespace scribo
using namespace mln;
- /*! \brief Invalidate links between two components if their bottom are not
- aligned.
+ /*! \brief Invalidate links between two components according to a specific anchor.
\param[in] links Object links information.
\param[in] max_alpha Maximum angle value (degrees).
+ \param[in] anchor Anchor used to compute angles.
\verbatim
@@ -75,13 +71,15 @@ namespace scribo
~
\endverbatim
+ Example with an anchor set to the bottom right :
The angle between the two bottoms must be lower than \p max_alpha.
*/
template <typename L>
object_links<L>
- object_links_bottom_aligned(const object_links<L>& links,
- float max_alpha);
+ object_links_aligned(const object_links<L>& links,
+ float max_alpha,
+ anchor::Type anchor);
# ifndef MLN_INCLUDE_ONLY
@@ -89,17 +87,18 @@ namespace scribo
template <typename L>
object_links<L>
- object_links_bottom_aligned(const object_links<L>& links,
- float max_alpha)
+ object_links_aligned(const object_links<L>& links,
+ float max_alpha,
+ anchor::Type anchor)
{
- trace::entering("scribo::filter::object_links_bottom_aligned");
+ trace::entering("scribo::filter::object_links_aligned");
mln_precondition(links.is_valid());
object_links<L>
- output = object_links_aligned(links, max_alpha, anchor::Bottom);
+ output = object_links_non_aligned_simple(links, anchor, max_alpha);
- trace::exiting("scribo::filter::object_links_bottom_aligned");
+ trace::exiting("scribo::filter::object_links_aligned");
return output;
}
@@ -112,4 +111,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH
+#endif // ! SCRIBO_FILTER_OBJECT_LINKS_ALIGNED_HH
--
1.5.6.5
1
0

last-svn-commit-805-g5d88dbd scribo/primitive/extract/separators_nonvisible.hh: Cleanup and improve debug support.
by Guillaume Lazzara 14 Mar '11
by Guillaume Lazzara 14 Mar '11
14 Mar '11
---
scribo/ChangeLog | 5 +
.../primitive/extract/separators_nonvisible.hh | 661 ++++++--------------
2 files changed, 200 insertions(+), 466 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 5ad1ca7..e248b55 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,10 @@
2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * scribo/primitive/extract/separators_nonvisible.hh: Cleanup and
+ improve debug support.
+
+2011-03-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Various small fixes.
* scribo/filter/object_links_bottom_aligned.hh,
diff --git a/scribo/scribo/primitive/extract/separators_nonvisible.hh b/scribo/scribo/primitive/extract/separators_nonvisible.hh
index 4e31650..c3e227c 100644
--- a/scribo/scribo/primitive/extract/separators_nonvisible.hh
+++ b/scribo/scribo/primitive/extract/separators_nonvisible.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -76,6 +77,7 @@
#include <mln/norm/l1.hh>
+#include <scribo/debug/logger.hh>
#include <scribo/core/object_groups.hh>
#include <scribo/core/component_set.hh>
#include <scribo/primitive/extract/components.hh>
@@ -90,19 +92,19 @@
#include <scribo/primitive/link/internal/dmax_default.hh>
-#include <scribo/primitive/link/with_single_right_link_dmax_ratio.hh>
#include <scribo/primitive/link/with_single_right_link_dmax_ratio_aligned.hh>
+#include <scribo/primitive/link/with_single_left_link_dmax_ratio_aligned.hh>
#include <scribo/primitive/group/from_double_link_any.hh>
#include <scribo/filter/object_links_top_aligned.hh>
#include <scribo/filter/object_groups_small.hh>
#include <scribo/filter/object_links_bottom_aligned.hh>
-#include <scribo/debug/save_linked_bboxes_image.hh>
-#include <scribo/debug/decision_image.hh>
-
-
+#include <scribo/core/def/lbl_type.hh>
+#include <scribo/core/line_set.hh>
+#include <scribo/text/extract_lines.hh>
+#include <mln/draw/box.hh>
namespace scribo
@@ -115,6 +117,7 @@ namespace scribo
{
using namespace mln;
+ using namespace scribo::debug;
/// \brief Find non visible separators (whitespaces)
@@ -127,269 +130,6 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
- namespace internal
- {
-
- using namespace primitive::link::internal;
-
- template <typename L, typename E>
- class single_dmax_ratio_aligned_functor_base
- : public link_single_dmax_ratio_base<L, dmax_default, E>
- {
- typedef link_single_dmax_ratio_base<L, dmax_default, E> super_;
-
- public:
- typedef mln_site(L) P;
-
- single_dmax_ratio_aligned_functor_base(
- const mln_ch_value(L,bool)& input,
- const component_set<L>& components,
- unsigned dmax,
- float min_angle,
- float max_angle,
- anchor::Type anchor_,
- bool debug)
- : super_(components,
- anchor::Horizontal,
- dmax_default(dmax)),
- anchor(anchor_),
- _debug_(debug)
- {
- (void) input; // FIXME : remove this argument
- min_alpha_rad = (min_angle / 180.0f) * math::pi;
- max_alpha_rad = (max_angle / 180.0f) * math::pi;
-
- // if (_debug_)
- // {
- // debug_ = data::convert(value::rgb8(), input);
- // debug_angle_ = data::convert(value::rgb8(), input);
- // }
- }
-
- void compute_next_site_(P& p)
- {
- ++p.col();
- }
-
- void compute_next_site_f_(unsigned& p)
- {
- ++p;
- }
-
-
- mln_site(L)
- start_point_(unsigned current_object, anchor::Type anchor)
- {
- return link::internal::compute_anchor(this->components_,
- current_object, anchor);
- }
-
-
- inline
- bool
- valid_link_(unsigned current_object,
- const P& start_point,
- const P& p)
- {
- if (!super_::valid_link_(current_object, start_point, p))
- return false;
-
- box<P> b = this->components_(current_object).bbox();
-
- // Distance between the two components.
- float dist;
-
- // current object is on the left.
- if (p[this->direction_] > b.pmax()[this->direction_])
- dist = math::abs(p[this->direction_] - b.pmax()[this->direction_]);
- // current object is on the right.
- else
- dist = math::abs(p[this->direction_] - b.pmin()[this->direction_]);
-
-
- int ldist = this->components_(current_object).bbox().width();
-
- // Components are really close, so the angle is more permissive.
- if (dist < 3 * ldist)
- {
- return
- filter::internal::component_aligned_rad(this->components_,
- current_object,
- this->labeled_image_(p),
- anchor,
- max_alpha_rad);
- }
-
-
- // Components are really far, so the angle is less permissive.
- return
- filter::internal::component_aligned_rad(this->components_,
- current_object,
- this->labeled_image_(p),
- anchor,
- min_alpha_rad);
- }
-
- void validate_link_(unsigned current_object,
- const P& start_point,
- const P& p,
- anchor::Type anchor)
- {
- super_::validate_link_(current_object, start_point, p, anchor);
-
- // if (_debug_)
- // {
- // mln_site(L)
- // p1 = link::internal::compute_anchor(this->components_,
- // current_object, anchor),
- // p2 = link::internal::compute_anchor(this->components_,
- // this->labeled_image_(p),
- // anchor);
- // mln::draw::line(debug_, p1, p2, literal::green);
-
-
- // float
- // angle = filter::internal::alignment_angle(this->components_,
- // current_object,
- // this->labeled_image_(p),
- // anchor);
- // angle = (angle * 180.0f) / math::pi;
- // angle = angle * 20.0f + 1.0f;
- // mln::draw::line(debug_angle_, p1, p2,
- // value::rgb8(unsigned(angle),
- // unsigned(angle),
- // unsigned(angle)));
- // }
- }
-
- void invalidate_link_(unsigned current_object,
- const P& start_point,
- const P& p,
- anchor::Type anchor)
- {
- super_::invalidate_link_(current_object, start_point, p, anchor);
-
- // if (_debug_)
- // {
- // if (this->labeled_image_.domain().has(p) && this->labeled_image_(p) != 0)
- // {
- // mln_site(L)
- // p1 = link::internal::compute_anchor(this->components_,
- // current_object, anchor),
- // p2 = link::internal::compute_anchor(this->components_,
- // this->labeled_image_(p),
- // anchor);
- // if (this->labeled_image_.domain().has(p2)
- // && norm::l1_distance(p1.to_vec(), p2.to_vec()) < 300)
- // {
- // mln::draw::line(debug_, p1, p2, literal::red);
- // }
-
-
- // float
- // angle = filter::internal::alignment_angle(this->components_,
- // current_object,
- // this->labeled_image_(p),
- // anchor);
- // angle = (angle * 180.0f) / math::pi;
- // angle = angle * 20.0f + 1.0f;
- // mln::draw::line(debug_angle_, p1, p2,
- // value::rgb8(unsigned(angle),
- // unsigned(angle),
- // unsigned(angle)));
- // }
- // }
- }
-
-
- float min_alpha_rad;
- float max_alpha_rad;
- anchor::Type anchor;
-
-
- // mln_ch_value(L, value::rgb8) debug_;
- // mln_ch_value(L, value::rgb8) debug_angle_;
- bool _debug_;
- };
-
-
- template <typename L>
- class single_right_dmax_ratio_aligned_functor
- : public single_dmax_ratio_aligned_functor_base<L, single_right_dmax_ratio_aligned_functor<L> >
- {
- typedef single_right_dmax_ratio_aligned_functor<L> self_t;
- typedef single_dmax_ratio_aligned_functor_base<L, self_t> super_;
-
- public:
- typedef mln_site(L) P;
-
- single_right_dmax_ratio_aligned_functor(
- const mln_ch_value(L, bool)& input,
- const component_set<L>& components,
- unsigned dmax,
- float min_angle,
- float max_angle,
- anchor::Type anchor,
- bool debug)
- : super_(input, components, dmax, min_angle,
- max_angle, anchor, debug)
- {
- }
-
- void compute_next_site_(P& p)
- {
- ++p.col();
- }
-
- void compute_next_site_f_(unsigned& p)
- {
- ++p;
- }
-
- };
-
-
- template <typename L>
- class single_left_dmax_ratio_aligned_functor
- : public single_dmax_ratio_aligned_functor_base<L, single_left_dmax_ratio_aligned_functor<L> >
- {
- typedef single_left_dmax_ratio_aligned_functor<L> self_t;
- typedef single_dmax_ratio_aligned_functor_base<L, self_t> super_;
-
- public:
- typedef mln_site(L) P;
-
- single_left_dmax_ratio_aligned_functor(
- const mln_ch_value(L, bool)& input,
- const component_set<L>& components,
- unsigned dmax,
- float min_angle,
- float max_angle,
- anchor::Type anchor,
- bool debug)
- : super_(input, components, dmax, min_angle,
- max_angle, anchor, debug)
- {
- }
-
- void compute_next_site_(P& p)
- {
- --p.col();
- }
-
- void compute_next_site_f_(unsigned& p)
- {
- --p;
- }
-
-
- };
-
- } // end of namespace scribo::primitive::extract::internal
-
-
-
-
// FACADE
template <typename I>
@@ -403,7 +143,9 @@ namespace scribo
typedef mln_value(I) Vi;
mlc_is(Vi,bool)::check();
- bool _debug_ = false;
+ typedef scribo::def::lbl_type V;
+ typedef mln_ch_value(I,V) L;
+
unsigned
min_angle = 3,
max_angle = 5,
@@ -414,33 +156,30 @@ namespace scribo
gt.start();
+ bool _debug_ = logger().is_at_level(AuxiliaryResults);
- // // Remove horizontal lines.
- // t.restart();
-
- // mln_concrete(I) hlines = primitive::extract::lines_h_pattern(in, 50, 3);
- // mln_concrete(I) input = primitive::remove::separators(in, hlines);
+ // Closing structural - Connect characters.
+ t.start();
- // t_ = t;
- // std::cout << "Horizontal lines removed - " << t_ << std::endl;
+ // line_set<L> lines = text::extract_lines(in, c8());
+ // mln_concrete(I) input_clo;
+ // initialize(input_clo, in);
+ // data::fill(input_clo, false);
- // Closing structural - Connect characters.
- t.start();
+ // for_all_lines(l, lines)
+ // draw::box(input_clo, lines(l).bbox(), true);
win::hline2d vl(17);
mln_concrete(I) input_clo = morpho::closing::structural(in, vl);
+
+
float t_ = t;
std::cout << "closing_structural - " << t_ << std::endl;
- // if (_debug_)
- // {
- // // Restore input orientation.
- // input = scribo::preprocessing::rotate_90(input, false);
-
- // io::pbm::save(input_clo, "input_clo.pbm");
- // }
+ // Debug
+ logger().log_image(AuxiliaryResults, input_clo, "input_clo");
// Rotate (OK)
t.restart();
@@ -451,8 +190,6 @@ namespace scribo
/// Finding components.
- typedef value::int_u16 V;
- typedef mln_ch_value(I,V) L;
t.restart();
V ncomponents;
@@ -462,11 +199,11 @@ namespace scribo
t_ = t;
std::cout << "extract::components - " << t_ << std::endl;
- // if (_debug_)
- // io::pgm::save(data::convert(value::int_u8(), components.labeled_image()),
- // "lbl.pgm");
-
-
+ // Debug
+ logger().log_image(AuxiliaryResults,
+ data::convert(value::int_u8(),
+ components.labeled_image()),
+ "lbl");
unsigned dmax = 5;
t.restart();
@@ -475,46 +212,47 @@ namespace scribo
object_links<L> top_left, bot_left;
+ typedef link::internal::dmax_default Dmax_F;
// Top
{
// Right
- internal::single_right_dmax_ratio_aligned_functor<L>
- functor(input_clo, components, dmax, min_angle, max_angle,
- anchor::TopStrictLeft, _debug_);
-// top_right = primitive::link::impl::compute_fastest(functor, anchor::TopStrictLeft);
+ link::internal::single_right_dmax_ratio_aligned_functor<L,Dmax_F>
+ functor(components, Dmax_F(dmax), min_angle, max_angle,
+ anchor::TopStrictLeft);
top_right = primitive::link::compute(functor, anchor::TopStrictLeft);
t.stop();
-
- // if (_debug_)
- // {
- // io::ppm::save(functor.debug_, "right_top.ppm");
- // io::ppm::save(functor.debug_angle_, "right_top_angle.ppm");
- // }
+ // Debug
+ logger().log_image(AuxiliaryResults, functor.debug_, "right_top");
+ logger().log_image(AuxiliaryResults, functor.debug_angle_,
+ "right_top_angle");
t.resume();
// Left
- internal::single_left_dmax_ratio_aligned_functor<L>
- lfunctor(input_clo, components, dmax, min_angle, max_angle,
- anchor::TopStrictLeft, _debug_);
+ link::internal::single_left_dmax_ratio_aligned_functor<L,Dmax_F>
+ lfunctor(components, Dmax_F(dmax), min_angle, max_angle,
+ anchor::TopStrictLeft);
top_left = primitive::link::compute(lfunctor, anchor::TopStrictLeft);
t.stop();
- // if (_debug_)
- // {
- // io::ppm::save(lfunctor.debug_, "left_top.ppm");
- // io::ppm::save(lfunctor.debug_angle_, "left_top_angle.ppm");
+ // Debug
+ if (_debug_)
+ {
+ logger().log_image(AuxiliaryResults, functor.debug_, "left_top");
+ logger().log_image(AuxiliaryResults, functor.debug_angle_,
+ "left_top_angle");
- // mln_ch_value(I, value::rgb8) output = duplicate(functor.debug_);
- // data::paste((lfunctor.debug_ | (pw::value(lfunctor.debug_) != pw::cst(literal::black)))
- // | (pw::value(lfunctor.debug_) != pw::cst(literal::white)), output);
+ mln_ch_value(I, value::rgb8) output = duplicate(functor.debug_);
+ data::paste((lfunctor.debug_
+ | (pw::value(lfunctor.debug_) != pw::cst(literal::black)))
+ | (pw::value(lfunctor.debug_) != pw::cst(literal::white)), output);
- // io::ppm::save(output, "left_right_top.ppm");
- // }
+ logger().log_image(AuxiliaryResults, output, "left_right_top");
+ }
t.resume();
}
@@ -523,38 +261,43 @@ namespace scribo
// Bottom
{
// Right
- internal::single_right_dmax_ratio_aligned_functor<L>
- functor(input_clo, components, dmax, min_angle, max_angle,
- anchor::BottomStrictRight, _debug_);
+ link::internal::single_right_dmax_ratio_aligned_functor<L,Dmax_F>
+ functor(components, Dmax_F(dmax), min_angle, max_angle,
+ anchor::BottomStrictRight);
bot_right = primitive::link::compute(functor, anchor::BottomStrictRight);
t.stop();
- // if (_debug_)
- // {
- // io::ppm::save(functor.debug_, "right_bot.ppm");
- // io::ppm::save(functor.debug_angle_, "right_bot_angle.ppm");
- // }
+ // Debug
+ if (_debug_)
+ {
+ logger().log_image(AuxiliaryResults, functor.debug_, "right_bot");
+ logger().log_image(AuxiliaryResults, functor.debug_angle_,
+ "right_bot_angle");
+ }
t.resume();
// Left
- internal::single_left_dmax_ratio_aligned_functor<L>
- lfunctor(input_clo, components, dmax, min_angle, max_angle,
- anchor::BottomStrictRight, _debug_);
+ link::internal::single_left_dmax_ratio_aligned_functor<L,Dmax_F>
+ lfunctor(components, Dmax_F(dmax), min_angle, max_angle,
+ anchor::BottomStrictRight);
bot_left = primitive::link::compute(lfunctor, anchor::BottomStrictRight);
t.stop();
- // if (_debug_)
- // {
- // io::ppm::save(lfunctor.debug_, "left_bot.ppm");
- // io::ppm::save(lfunctor.debug_angle_, "left_bot_angle.ppm");
+ // Debug
+ if (_debug_)
+ {
+ logger().log_image(AuxiliaryResults, functor.debug_, "left_bot");
+ logger().log_image(AuxiliaryResults, functor.debug_angle_,
+ "left_bot_angle");
- // mln_ch_value(I, value::rgb8) output = duplicate(functor.debug_);
- // data::paste((lfunctor.debug_ | (pw::value(lfunctor.debug_) != pw::cst(literal::black)))
- // | (pw::value(lfunctor.debug_) != pw::cst(literal::white)), output);
+ mln_ch_value(I, value::rgb8) output = duplicate(functor.debug_);
+ data::paste((lfunctor.debug_
+ | (pw::value(lfunctor.debug_) != pw::cst(literal::black)))
+ | (pw::value(lfunctor.debug_) != pw::cst(literal::white)), output);
- // io::ppm::save(output, "left_right_bot.ppm");
- // }
+ logger().log_image(AuxiliaryResults, output, "left_right_bot");
+ }
}
@@ -631,113 +374,113 @@ namespace scribo
std::cout << "Drawing output image - " << t_ << std::endl;
- // if (_debug_)
- // {
- // // Restore input orientation.
- // mln_concrete(I) input = scribo::preprocessing::rotate_90(in, false);
-
-
- // // Debug group bboxes (includes all bboxes before filtering)
- // util::array<accu::shape::bbox<point2d> >
- // btop_accu(top_groups.nelements()),
- // bbot_accu(bot_groups.nelements());
-
-
- // for_all_groups(c, top_groups)
- // {
- // btop_accu(top_groups(c)).take(components(c).bbox());
- // bbot_accu(bot_groups(c)).take(components(c).bbox());
- // }
-
- // mln_ch_value(I, value::rgb8)
- // wo_filtering = data::convert(value::rgb8(), input);
-
- // for_all_comp_data(d, btop_accu)
- // {
- // if (btop_accu(d).is_valid())
- // {
- // mln::draw::line(wo_filtering,
- // btop_accu(d).to_result().pmin(),
- // point2d(btop_accu(d).to_result().pmin().row(),
- // btop_accu(d).to_result().pmax().col()),
- // literal::green);
-
- // }
- // }
-
- // for_all_comp_data(d, bbot_accu)
- // {
- // if (bbot_accu(d).is_valid())
- // {
- // mln::draw::line(wo_filtering,
- // point2d(bbot_accu(d).to_result().pmax().row(),
- // bbot_accu(d).to_result().pmin().col()),
- // bbot_accu(d).to_result().pmax(),
- // literal::green);
- // }
-
- // }
- // io::ppm::save(wo_filtering, "wo_filtering.ppm");
-
- // mln_ch_value(I, value::rgb8) both = data::convert(value::rgb8(), input);
-
- // for_all_comp_data(d, top_accu)
- // {
- // if (top_accu(d).is_valid() || btop_accu(d).is_valid())
- // {
- // if (top_accu(d).is_valid())
- // {
- // mln::draw::line(both,
- // top_accu(d).to_result().pmin(),
- // point2d(top_accu(d).to_result().pmin().row(),
- // top_accu(d).to_result().pmax().col()),
- // literal::green);
- // }
- // else
- // if (btop_accu(d).is_valid())
- // mln::draw::line(both,
- // btop_accu(d).to_result().pmin(),
- // point2d(btop_accu(d).to_result().pmin().row(),
- // btop_accu(d).to_result().pmax().col()),
- // literal::yellow);
-
- // }
- // if (bot_accu(d).is_valid() || bbot_accu(d).is_valid())
- // {
- // if (bot_accu(d).is_valid())
- // {
- // mln::draw::line(both,
- // point2d(bot_accu(d).to_result().pmax().row(),
- // bot_accu(d).to_result().pmin().col()),
- // bot_accu(d).to_result().pmax(),
- // literal::green);
- // }
- // else
- // if (bbot_accu(d).is_valid())
- // mln::draw::line(both,
- // point2d(bbot_accu(d).to_result().pmax().row(),
- // bbot_accu(d).to_result().pmin().col()),
- // bbot_accu(d).to_result().pmax(),
- // literal::yellow);
- // }
-
- // }
-
- // io::ppm::save(both, "both.ppm");
- // io::pbm::save(separators, "separators.pbm");
- // }
+ if (_debug_)
+ {
+ // Restore input orientation.
+ mln_concrete(I) input = scribo::preprocessing::rotate_90(in, false);
+
+ // Debug group bboxes (includes all bboxes before filtering)
+ util::array<accu::shape::bbox<point2d> >
+ btop_accu(top_groups.nelements()),
+ bbot_accu(bot_groups.nelements());
- // Hit or miss
- {
- // if (_debug_)
+
+ for_all_groups(c, top_groups)
+ {
+ btop_accu(top_groups(c)).take(components(c).bbox());
+ bbot_accu(bot_groups(c)).take(components(c).bbox());
+ }
+
+ mln_ch_value(I, value::rgb8)
+ wo_filtering = data::convert(value::rgb8(), input);
+
+ for_all_comp_data(d, btop_accu)
+ {
+ if (btop_accu(d).is_valid())
+ {
+ mln::draw::line(wo_filtering,
+ btop_accu(d).to_result().pmin(),
+ point2d(btop_accu(d).to_result().pmin().row(),
+ btop_accu(d).to_result().pmax().col()),
+ literal::green);
+
+ }
+ }
+
+ for_all_comp_data(d, bbot_accu)
+ {
+ if (bbot_accu(d).is_valid())
+ {
+ mln::draw::line(wo_filtering,
+ point2d(bbot_accu(d).to_result().pmax().row(),
+ bbot_accu(d).to_result().pmin().col()),
+ bbot_accu(d).to_result().pmax(),
+ literal::green);
+ }
+ }
+ logger().log_image(AuxiliaryResults, wo_filtering, "wo_filtering");
+
+ // mln_ch_value(I, value::rgb8) both = data::convert(value::rgb8(), input);
+
+ // for_all_comp_data(d, top_accu)
// {
- // mln_concrete(I) input_with_seps = duplicate(input_clo);
- // data::paste(separators | pw::value(separators), input_with_seps);
+ // if (top_accu(d).is_valid() || btop_accu(d).is_valid())
+ // {
+ // if (top_accu(d).is_valid())
+ // {
+ // mln::draw::line(both,
+ // top_accu(d).to_result().pmin(),
+ // point2d(top_accu(d).to_result().pmin().row(),
+ // top_accu(d).to_result().pmax().col()),
+ // literal::green);
+ // }
+ // else
+ // if (btop_accu(d).is_valid())
+ // mln::draw::line(both,
+ // btop_accu(d).to_result().pmin(),
+ // point2d(btop_accu(d).to_result().pmin().row(),
+ // btop_accu(d).to_result().pmax().col()),
+ // literal::yellow);
+
+ // }
+ // if (bot_accu(d).is_valid() || bbot_accu(d).is_valid())
+ // {
+ // if (bot_accu(d).is_valid())
+ // {
+ // mln::draw::line(both,
+ // point2d(bot_accu(d).to_result().pmax().row(),
+ // bot_accu(d).to_result().pmin().col()),
+ // bot_accu(d).to_result().pmax(),
+ // literal::green);
+ // }
+ // else
+ // if (bbot_accu(d).is_valid())
+ // mln::draw::line(both,
+ // point2d(bbot_accu(d).to_result().pmax().row(),
+ // bbot_accu(d).to_result().pmin().col()),
+ // bbot_accu(d).to_result().pmax(),
+ // literal::yellow);
+ // }
- // io::pbm::save(input_with_seps, "input_with_seps.pbm");
// }
+ // logger().log_image(AuxiliaryResults,
+ // both, "both");
+ logger().log_image(AuxiliaryResults, separators, "separators");
+ }
+
+
+ // Hit or miss
+ {
+ if (_debug_)
+ {
+ mln_concrete(I) input_with_seps = duplicate(input_clo);
+ data::paste(separators | pw::value(separators), input_with_seps);
+
+ logger().log_image(AuxiliaryResults, input_with_seps, "input_with_seps");
+ }
+
t.restart();
unsigned length = 25;
@@ -778,18 +521,22 @@ namespace scribo
extension::adjust_fill(tmp, 21, 0);
- value::int_u8 *sep_lbl_ptr = sep_lbl.buffer() + sep_lbl.index_of_point(sep_lbl.domain().pmin());
- bool *separators_ptr = separators.buffer() + separators.index_of_point(separators.domain().pmin());
+ value::int_u8 *sep_lbl_ptr = sep_lbl.buffer()
+ + sep_lbl.index_of_point(sep_lbl.domain().pmin());
+ bool *separators_ptr = separators.buffer()
+ + separators.index_of_point(separators.domain().pmin());
unsigned *tmp_ptr = tmp.buffer() + tmp.index_of_point(tmp.domain().pmin());;
int idx1 = tmp.delta_index(dp1);
int idx2 = tmp.delta_index(dp2);
- unsigned nrows = separators.nrows();
- unsigned ncols = separators.ncols();
+ unsigned
+ nrows = separators.nrows(),
+ ncols = separators.ncols();
- unsigned row_idx_sep_lbl = sep_lbl.delta_index(dpoint2d(+1, - ncols));
- unsigned row_idx_separators = separators.delta_index(dpoint2d(+1, - ncols));
- unsigned row_idx_tmp = tmp.delta_index(dpoint2d(+1, - ncols));
+ unsigned
+ row_idx_sep_lbl = sep_lbl.delta_index(dpoint2d(+1, - ncols)),
+ row_idx_separators = separators.delta_index(dpoint2d(+1, - ncols)),
+ row_idx_tmp = tmp.delta_index(dpoint2d(+1, - ncols));
for (unsigned row = 0; row < nrows; ++row)
{
@@ -833,29 +580,11 @@ namespace scribo
mln_concrete(I) output = data::convert(bool(), sep_lbl);
- // if (_debug_)
- // {
- // io::pbm::save(output, "separators_hom.pbm");
- // io::pbm::save(separators, "separators_filtered.pbm");
-
- // // value::int_u16 ncomps;
- // // component_set<L> comps = primitive::extract::components(output, c8(), ncomps);
- // // mln_ch_value(I, value::rgb8) both;
-
- // // both = data::convert(value::rgb8(), input);
-
- // // // Needed since the rotated image origin is (0,0).
- // // dpoint2d dp(input.domain().pcenter() - input_clo.domain().pcenter());
-
- // // for_all_comps(c, comps)
- // // {
- // // box2d b = geom::rotate(comps(c).bbox(), -90, input_clo.domain().pcenter());
- // // mln::draw::line(both,
- // // b.pmin() + dp,
- // // b.pmax() + dp,
- // // literal::green);
- // // }
- // }
+ if (_debug_)
+ {
+ logger().log_image(AuxiliaryResults, output,
+ "separators_filtered");
+ }
gt.stop();
t_ = gt;
--
1.5.6.5
1
0