Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
11 Mar '10
* scribo/debug/alignment_decision_image.hh,
* scribo/debug/links_decision_image.hh,
* scribo/debug/save_linked_bboxes_image.hh,
* scribo/draw/bounding_box_links.hh: Make use of anchor points to
draw debug outputs.
---
scribo/ChangeLog | 10 +++++
scribo/debug/alignment_decision_image.hh | 26 ++++++++++--
scribo/debug/links_decision_image.hh | 34 ++++++++++++++---
scribo/debug/save_linked_bboxes_image.hh | 48 +++++++++++++++++------
scribo/draw/bounding_box_links.hh | 61 ++++++++++++------------------
5 files changed, 118 insertions(+), 61 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 01ab3a1..52a13dd 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,15 @@
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add anchor support in debug routines.
+
+ * scribo/debug/alignment_decision_image.hh,
+ * scribo/debug/links_decision_image.hh,
+ * scribo/debug/save_linked_bboxes_image.hh,
+ * scribo/draw/bounding_box_links.hh: Make use of anchor points to
+ draw debug outputs.
+
+2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add new link filters.
* scribo/filter/object_links_non_aligned_simple.hh: Handle new
diff --git a/scribo/debug/alignment_decision_image.hh b/scribo/debug/alignment_decision_image.hh
index 9a4fa50..e3b6163 100644
--- a/scribo/debug/alignment_decision_image.hh
+++ b/scribo/debug/alignment_decision_image.hh
@@ -114,7 +114,8 @@ namespace scribo
alignment_decision_image(const Image<I>& input_,
const object_links<L>& links,
const object_links<L>& filtered_links,
- const Alignment& alignment)
+ const Alignment& alignment,
+ unsigned max_link_length)
{
trace::entering("scribo::debug::alignment_decision_image");
const I& input = exact(input_);
@@ -147,10 +148,11 @@ namespace scribo
mln::util::couple<P,P>
anchors = internal::find_anchors(objects, i, links[i], alignment);
- mln::draw::line(decision_image,
- anchors.first(),
- anchors.second(),
- value);
+ if (norm::l1_distance(anchors.first(), anchors.second()) < max_link_length)
+ mln::draw::line(decision_image,
+ anchors.first(),
+ anchors.second(),
+ value);
}
}
@@ -159,6 +161,20 @@ namespace scribo
}
+ template <typename I, typename L>
+ mln_ch_value(I,value::rgb8)
+ alignment_decision_image(const Image<I>& input_,
+ const object_links<L>& links,
+ const object_links<L>& filtered_links,
+ const Alignment& alignment)
+ {
+ return alignment_decision_image(input_,
+ links,
+ filtered_links,
+ alignment,
+ mln_max(unsigned));
+ }
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/debug/links_decision_image.hh b/scribo/debug/links_decision_image.hh
index 368d9b7..e1cf766 100644
--- a/scribo/debug/links_decision_image.hh
+++ b/scribo/debug/links_decision_image.hh
@@ -36,6 +36,7 @@
# include <mln/value/rgb8.hh>
# include <mln/literal/colors.hh>
# include <mln/util/array.hh>
+# include <mln/norm/l1.hh>
# include <scribo/core/object_groups.hh>
# include <scribo/draw/bounding_boxes.hh>
@@ -54,8 +55,15 @@ namespace scribo
mln_ch_value(I,value::rgb8)
links_decision_image(const Image<I>& input_,
const object_links<L>& links,
- const object_links<L>& filtered_links);
+ const object_links<L>& filtered_links,
+ unsigned max_link_length);
+ /// \overload
+ template <typename I, typename L>
+ mln_ch_value(I,value::rgb8)
+ links_decision_image(const Image<I>& input_,
+ const object_links<L>& links,
+ const object_links<L>& filtered_links);
# ifndef MLN_INCLUDE_ONLY
@@ -63,7 +71,8 @@ namespace scribo
mln_ch_value(I,value::rgb8)
links_decision_image(const Image<I>& input_,
const object_links<L>& links,
- const object_links<L>& filtered_links)
+ const object_links<L>& filtered_links,
+ unsigned max_link_length)
{
trace::entering("scribo::debug::links_decision_image");
const I& input = exact(input_);
@@ -105,10 +114,11 @@ namespace scribo
while (objects(p2) != links[i] && objects.domain().has(p2))
++p2.col();
- mln::draw::line(links_decision_image,
- p1,
- p2,
- value);
+ if (norm::l1_distance(p2.to_vec(), p1.to_vec()) < max_link_length)
+ mln::draw::line(links_decision_image,
+ p1,
+ p2,
+ value);
}
}
@@ -117,6 +127,18 @@ namespace scribo
}
+ template <typename I, typename L>
+ mln_ch_value(I,value::rgb8)
+ links_decision_image(const Image<I>& input_,
+ const object_links<L>& links,
+ const object_links<L>& filtered_links)
+ {
+ return links_decision_image(input_,
+ links,
+ filtered_links,
+ mln_max(unsigned));
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::debug
diff --git a/scribo/debug/save_linked_bboxes_image.hh b/scribo/debug/save_linked_bboxes_image.hh
index 364f06e..c4e3cd1 100644
--- a/scribo/debug/save_linked_bboxes_image.hh
+++ b/scribo/debug/save_linked_bboxes_image.hh
@@ -62,6 +62,21 @@ namespace scribo
/// \param[in] box_value Value used to draw line bounding boxes.
/// \param[in] link_value Value used to draw line links.
/// \param[in] filename The target file name.
+ /// \param[in] anchor Anchor from where the links are drawn.
+ //
+ template <typename I, typename L>
+ void
+ save_linked_bboxes_image(const Image<I>& input,
+ const object_image(L)& objects,
+ const object_links<L>& array,
+ const value::rgb8& box_value,
+ const value::rgb8& link_value,
+ const std::string& filename,
+ anchor::Type anchor);
+
+ /// \overload
+ /// The default anchor type is set to anchor::Center.
+ //
template <typename I, typename L>
void
save_linked_bboxes_image(const Image<I>& input,
@@ -145,20 +160,16 @@ namespace scribo
const object_links<L>& array,
const value::rgb8& box_value,
const value::rgb8& link_value,
- const std::string& filename)
+ const std::string& filename,
+ anchor::Type anchor)
{
trace::entering("scribo::debug::save_linked_bboxes_image");
mln_precondition(exact(input).is_valid());
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
- mln::util::array<mln_result(accu::center<mln_psite(L)>)>
- mass_center = labeling::compute(accu::meta::center(),
- objects,
- objects.nlabels());
-
draw::bounding_boxes(tmp, objects.bboxes(), box_value);
- draw::bounding_box_links(tmp, mass_center, array, link_value);
+ draw::bounding_box_links(tmp, array, link_value, anchor);
io::ppm::save(tmp, filename);
@@ -171,6 +182,22 @@ namespace scribo
void
save_linked_bboxes_image(const Image<I>& input,
const object_image(L)& objects,
+ const object_links<L>& array,
+ const value::rgb8& box_value,
+ const value::rgb8& link_value,
+ const std::string& filename)
+ {
+ save_linked_bboxes_image(input, objects, array, box_value,
+ link_value, filename, anchor::Center);
+ }
+
+
+
+ template <typename I, typename L>
+ inline
+ void
+ save_linked_bboxes_image(const Image<I>& input,
+ const object_image(L)& objects,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
@@ -182,13 +209,8 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
- mln::util::array<mln_result(accu::center<mln_psite(L)>)>
- mass_center = labeling::compute(accu::meta::center(),
- objects,
- objects.nlabels());
-
draw::bounding_boxes(tmp, objects.bboxes(), box_value);
- draw::bounding_box_links(tmp, mass_center,
+ draw::bounding_box_links(tmp, objects.mass_centers(),
left_link, right_link,
value);
diff --git a/scribo/draw/bounding_box_links.hh b/scribo/draw/bounding_box_links.hh
index 47a4f0a..ed6337d 100644
--- a/scribo/draw/bounding_box_links.hh
+++ b/scribo/draw/bounding_box_links.hh
@@ -35,9 +35,11 @@
# include <mln/util/array.hh>
# include <mln/canvas/browsing/depth_first_search.hh>
+# include <scribo/core/tag/anchor.hh>
# include <scribo/core/macros.hh>
# include <scribo/core/object_links.hh>
# include <scribo/primitive/internal/is_link_valid.hh>
+# include <scribo/primitive/link/internal/compute_anchor.hh>
namespace scribo
{
@@ -54,25 +56,22 @@ namespace scribo
/// \param[in] bboxes Bounding boxes.
/// \param[in] links Bounding box links.
/// \param[in] value Value used to draw links.
+ /// \param[in] anchor Anchor from where the links are drawn.
+ //
template <typename I, typename L>
void
bounding_box_links(Image<I>& input_,
- const mln::util::array< box<mln_site(I)> >& bboxes,
const object_links<L>& link,
- const mln_value(I)& value);
+ const mln_value(I)& value,
+ anchor::Type anchor);
- /// Draw a list of bounding box links from their mass centers.
- ///
- /// \param[in,out] input_ An image where to draw.
- /// \param[in] mass_centers Bounding boxes mass centers.
- /// \param[in] links Bounding box links.
- /// \param[in] value Value used to draw links.
+ /// \overload
+ /// The default anchor type is set to anchor::Center.
+ //
template <typename I, typename L>
- inline
void
bounding_box_links(Image<I>& input_,
- const mln::util::array<mln_site(I)::vec>& mass_centers,
const object_links<L>& link,
const mln_value(I)& value);
@@ -236,9 +235,9 @@ namespace scribo
inline
void
bounding_box_links(Image<I>& input_,
- const mln::util::array< box<mln_site(I)> >& bboxes,
const object_links<L>& links,
- const mln_value(I)& value)
+ const mln_value(I)& value,
+ anchor::Type anchor)
{
trace::entering("scribo::draw::bounding_box_links");
@@ -246,41 +245,29 @@ namespace scribo
mln_precondition(input.is_valid());
+ const object_image(L)& objects = links.object_image_();
for_all_components(i, links)
- if (links[i] != i)
- mln::draw::line(input,
- bboxes[i].center(),
- bboxes[links[i]].center(),
- value);
+ if (links[i] != i && links[i] != 0)
+ {
+ mln_site(L)
+ p1 = primitive::link::internal::compute_anchor(objects, i, anchor),
+ p2 = primitive::link::internal::compute_anchor(objects, links[i], anchor);
+
+ mln::draw::line(input, p1, p2, value);
+ }
trace::exiting("scribo::draw::bounding_box_links");
}
+
template <typename I, typename L>
inline
void
- bounding_box_links(Image<I>& input_,
- const mln::util::array<mln_site(I)::vec>& mass_centers,
+ bounding_box_links(Image<I>& input,
const object_links<L>& links,
const mln_value(I)& value)
{
- trace::entering("scribo::draw::bounding_box_links");
-
- I& input = exact(input_);
-
- mln_precondition(input.is_valid());
-
- for_all_components(i, links)
- {
- if (links[i] != i)
- mln::draw::line(input,
- mass_centers[i],
- mass_centers[links[i]],
- value);
- input(mass_centers[i]) = value;
- }
-
- trace::exiting("scribo::draw::bounding_box_links");
+ return bounding_box_links(input, links, value, anchor::Center);
}
@@ -401,7 +388,7 @@ namespace scribo
mln_precondition(exact(g).v_nmax() == bboxes.nelements());
internal::draw_graph_edges_functor<I> f(exact(input), bboxes, link_value);
- canvas::browsing::depth_first_search(g, f);
+ mln::canvas::browsing::depth_first_search(g, f);
trace::exiting("scribo::draw::bounding_box_links");
}
--
1.5.6.5
1
0
last-svn-commit-41-g41b6112 io/xml/save_text_lines.hh: New. Add partial support for PageContent XML format.
by Guillaume Lazzara 11 Mar '10
by Guillaume Lazzara 11 Mar '10
11 Mar '10
---
scribo/ChangeLog | 59 +++++++++-------
scribo/io/xml/save_text_lines.hh | 144 ++++++++++++++++++++++++++++++++++++++
2 files changed, 176 insertions(+), 27 deletions(-)
create mode 100644 scribo/io/xml/save_text_lines.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index dfac25a..f3c022a 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,8 @@
+2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ * io/xml/save_text_lines.hh: New. Add partial support for
+ PageContent XML format.
+
2010-03-11 Guillaume Lazzara <z(a)lrde.epita.fr>
Introduce new Scribo core classes and start using them.
@@ -48,58 +53,58 @@
Add anchor support in debug routines.
- * scribo/debug/alignment_decision_image.hh,
- * scribo/debug/links_decision_image.hh,
- * scribo/debug/save_linked_bboxes_image.hh,
- * scribo/draw/bounding_box_links.hh: Make use of anchor points to
+ * debug/alignment_decision_image.hh,
+ * debug/links_decision_image.hh,
+ * debug/save_linked_bboxes_image.hh,
+ * draw/bounding_box_links.hh: Make use of anchor points to
draw debug outputs.
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
Add new link filters.
- * scribo/filter/object_links_non_aligned_simple.hh: Handle new
+ * filter/object_links_non_aligned_simple.hh: Handle new
cases.
- * scribo/filter/object_links_left_aligned.hh,
- * scribo/filter/object_links_right_aligned.hh: New filters.
+ * filter/object_links_left_aligned.hh,
+ * filter/object_links_right_aligned.hh: New filters.
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
Improve object linking backend.
- * scribo/primitive/internal/find_left_link.hh,
- * scribo/primitive/internal/find_right_link.hh,
- * scribo/primitive/internal/is_invalid_link.hh: Remove.
+ * primitive/internal/find_left_link.hh,
+ * primitive/internal/find_right_link.hh,
+ * primitive/internal/is_invalid_link.hh: Remove.
- * scribo/primitive/link/internal/compute_anchor.hh,
- * scribo/primitive/link/internal/link_ms_dmax_base.hh,
- * scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh,
- * scribo/primitive/link/internal/link_single_dmax_base.hh,
- * scribo/primitive/link/internal/link_single_dmax_ratio_base.hh,
- * scribo/primitive/link/with_single_down_link.hh,
- * scribo/primitive/link/with_single_left_link.hh,
- * scribo/primitive/link/with_single_left_link_dmax_ratio.hh,
- * scribo/primitive/link/with_single_right_link.hh,
- * scribo/primitive/link/with_single_right_link_dmax_ratio.hh,
- * scribo/primitive/link/with_single_up_link.hh: Introduce the
+ * primitive/link/internal/compute_anchor.hh,
+ * primitive/link/internal/link_ms_dmax_base.hh,
+ * primitive/link/internal/link_ms_dmax_ratio_base.hh,
+ * primitive/link/internal/link_single_dmax_base.hh,
+ * primitive/link/internal/link_single_dmax_ratio_base.hh,
+ * primitive/link/with_single_down_link.hh,
+ * primitive/link/with_single_left_link.hh,
+ * primitive/link/with_single_left_link_dmax_ratio.hh,
+ * primitive/link/with_single_right_link.hh,
+ * primitive/link/with_single_right_link_dmax_ratio.hh,
+ * primitive/link/with_single_up_link.hh: Introduce the
anchor concept and make use of it.
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
- * scribo/filter/objects_with_holes.hh: New component filter.
+ * filter/objects_with_holes.hh: New component filter.
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
- * scribo/draw/bounding_boxes.hh: Do not draw box centers anymore.
+ * draw/bounding_boxes.hh: Do not draw box centers anymore.
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
Add dedicated routines for AFP's use case.
- * scribo/src/afp/components.hh,
- * scribo/src/afp/link.hh,
- * scribo/src/afp/regroup.hh: New.
+ * src/afp/components.hh,
+ * src/afp/link.hh,
+ * src/afp/regroup.hh: New.
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/scribo/io/xml/save_text_lines.hh b/scribo/io/xml/save_text_lines.hh
new file mode 100644
index 0000000..c86f121
--- /dev/null
+++ b/scribo/io/xml/save_text_lines.hh
@@ -0,0 +1,144 @@
+// Copyright (C) 2010 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_XML_SAVE_TEXT_LINES_HH
+# define SCRIBO_IO_XML_SAVE_TEXT_LINES_HH
+
+/// \file
+///
+/// \brief Save text line information as XML.
+
+#include <fstream>
+#include <sstream>
+
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace xml
+ {
+
+ /*! \brief Save text line information as XML.
+
+ We use a XML Schema part of the PAGE (Page Analysis and Ground
+ truth Elements) image representation framework.
+
+ This schema was used in the Page Segmentation COMPetition
+ (PSCOMP) for ICDAR 2009.
+
+ Its XSD file is located here:
+ http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16/pagecontent…
+
+ */
+ template <typename L>
+ void
+ save_text_lines(const std::string& input_name,
+ const line_set<L>& lines,
+ const std::string& output_name);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename L>
+ void
+ save_text_lines(const std::string& input_name,
+ const line_set<L>& lines,
+ const std::string& output_name)
+ {
+ trace::entering("scribo::io::xml:save_text_lines");
+
+ std::ofstream file(output_name.c_str());
+ if (! file)
+ {
+ std::cerr << "error: cannot open file '" << input_name << "'!";
+ abort();
+ }
+
+ file << "<?xml version=\"1.0\"?>" << std::endl;
+ file << "<pcGts xmlns=\"http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16 http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16/pagecontent…" pcGtsId=\"" << input_name << "\">" << std::endl;
+
+
+ file << " <pcMetadata>" << std::endl;
+ file << " <pcCreator>LRDE</pcCreator>" << std::endl;
+ file << " <pcCreated/>" << std::endl;
+ file << " <pcLastChange/>" << std::endl;
+ file << " <pcComments/>" << std::endl;
+ file << " </pcMetadata>" << std::endl;
+
+ file << " <page image_filename=\"" << input_name
+ << "\" image_width=\"" << lines.component_set_().labeled_image().ncols()
+ << "\" image_height=\"" << lines.component_set_().labeled_image().nrows()
+ << "\">" << std::endl;
+
+ for_all_lines(l, lines)
+ {
+ file << " <text_region id=\"" << lines(l).id()
+ << "\" txt_orientation=\"0.000\" "
+ << "txt_reading_orientation=\"0.000\" "
+ << "txt_reading_direction=\"Left_To_Right\" "
+ << "txt_reverse_video=\"No\" "
+ << "txt_indented=\"No\">"
+ << std::endl;
+
+ file << " <coords>" << std::endl
+ << " <point x=\"" << lines(l).bbox().pmin().row()
+ << "\" y=\"" << lines(l).bbox().pmin().col() << "\"/>"
+ << std::endl
+ << " <point x=\"" << lines(l).bbox().pmin().row()
+ << "\" y=\"" << lines(l).bbox().pmax().col() << "\"/>"
+ << std::endl
+ << " <point x=\"" << lines(l).bbox().pmax().row()
+ << "\" y=\"" << lines(l).bbox().pmin().col() << "\"/>"
+ << std::endl
+ << " <point x=\"" << lines(l).bbox().pmax().row()
+ << "\" y=\"" << lines(l).bbox().pmax().col() << "\"/>"
+ << std::endl
+ << " </coords>" << std::endl;
+ }
+
+ file << " </text_region>" << std::endl;
+ file << " </page>" << std::endl;
+ file << "</pcGts>" << std::endl;
+
+
+
+ trace::exiting("scribo::io::xml::save_text_lines");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::xml
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_IO_XML_SAVE_TEXT_LINES_HH
--
1.5.6.5
1
0
* milena/mln/accu/center.hh: Add nsites() member.
* milena/mln/accu/pair.hh: Provide access to the underlying accus.
* milena/mln/accu/stat/variance.hh: Use literal::zero.
* milena/mln/core/internal/labeled_image_base.hh: Indent.
* milena/mln/core/site_set/box.hh: Rename center() as pcenter().
* milena/mln/labeling/blobs_and_compute.hh: Return the array of
accumulators.
* milena/mln/labeling/colorize.hh: Make sure a color is not used
twice in the same image.
* milena/mln/labeling/compute.hh: Add a new overload.
* milena/mln/transform/influence_zone_geodesic.hh: Fix a
segmentation fault when an image had a border.
---
milena/ChangeLog | 25 +++++
milena/mln/accu/center.hh | 14 +++-
milena/mln/accu/pair.hh | 26 ++++++
milena/mln/accu/stat/variance.hh | 4 +-
milena/mln/core/internal/labeled_image_base.hh | 2 +-
milena/mln/core/site_set/box.hh | 4 +-
milena/mln/labeling/blobs_and_compute.hh | 14 ++-
milena/mln/labeling/colorize.hh | 51 ++++++++---
milena/mln/labeling/compute.hh | 111 +++++++++++++++++++----
milena/mln/transform/influence_zone_geodesic.hh | 13 +--
10 files changed, 214 insertions(+), 50 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 73b9647..ec2ef35 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,28 @@
+2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Small fixes in Milena.
+
+ * milena/mln/accu/center.hh: Add nsites() member.
+
+ * milena/mln/accu/pair.hh: Provide access to the underlying accus.
+
+ * milena/mln/accu/stat/variance.hh: Use literal::zero.
+
+ * milena/mln/core/internal/labeled_image_base.hh: Indent.
+
+ * milena/mln/core/site_set/box.hh: Rename center() as pcenter().
+
+ * milena/mln/labeling/blobs_and_compute.hh: Return the array of
+ accumulators.
+
+ * milena/mln/labeling/colorize.hh: Make sure a color is not used
+ twice in the same image.
+
+ * milena/mln/labeling/compute.hh: Add a new overload.
+
+ * milena/mln/transform/influence_zone_geodesic.hh: Fix a
+ segmentation fault when an image had a border.
+
2009-12-14 Guillaume Lazzara <z(a)lrde.epita.fr>
Add rbg_to_int_u function.
diff --git a/milena/mln/accu/center.hh b/milena/mln/accu/center.hh
index 7cfbe78..a3622b3 100644
--- a/milena/mln/accu/center.hh
+++ b/milena/mln/accu/center.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009, 2010 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -73,6 +74,9 @@ namespace mln
/// Check whether this accu is able to return a result.
bool is_valid() const;
+ /// Return the number of sites taken in consideration.
+ unsigned nsites() const;
+
protected:
algebra::vec<P::dim, mln_sum(mln_coord(P))> center_;
unsigned nsites_;
@@ -158,6 +162,14 @@ namespace mln
return nsites_ > 0;
}
+ template <typename P, typename V>
+ inline
+ unsigned
+ center<P,V>::nsites() const
+ {
+ return nsites_;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/mln/accu/pair.hh b/milena/mln/accu/pair.hh
index bb0b691..11f4dc6 100644
--- a/milena/mln/accu/pair.hh
+++ b/milena/mln/accu/pair.hh
@@ -81,9 +81,16 @@ namespace mln
void get_result(result_1& r1, result_2& r2) const;
/// \}
+ /// Return the result of the first accumulator.
mln_result(A1) first() const;
+ /// Return the result of the second accumulator.
mln_result(A2) second() const;
+ /// Return the first accumulator.
+ A1 first_accu() const;
+ /// Return the second accumulator.
+ A2 second_accu() const;
+
/// Check whether this accu is able to return a result.
/// Always true here.
bool is_valid() const;
@@ -194,6 +201,25 @@ namespace mln
return a2_.to_result();
}
+
+
+ template <typename A1, typename A2, typename T>
+ inline
+ A1
+ pair<A1,A2,T>::first_accu() const
+ {
+ return a1_;
+ }
+
+ template <typename A1, typename A2, typename T>
+ inline
+ A2
+ pair<A1,A2,T>::second_accu() const
+ {
+ return a2_;
+ }
+
+
template <typename A1, typename A2, typename T>
inline
bool
diff --git a/milena/mln/accu/stat/variance.hh b/milena/mln/accu/stat/variance.hh
index 23e7731..c19761e 100644
--- a/milena/mln/accu/stat/variance.hh
+++ b/milena/mln/accu/stat/variance.hh
@@ -125,7 +125,7 @@ namespace mln
variance<T,S,R>::init()
{
n_ = 0;
- sum_ = sum2_ = 0;
+ sum_ = sum2_ = literal::zero;
}
template <typename T, typename S, typename R>
@@ -187,7 +187,7 @@ namespace mln
variance<T,S,R>::mean() const
{
if (n_ == 0u)
- return 0; // Safety.
+ return literal::zero; // Safety.
return sum_ / n_;
}
diff --git a/milena/mln/core/internal/labeled_image_base.hh b/milena/mln/core/internal/labeled_image_base.hh
index 9e2d314..86bb077 100644
--- a/milena/mln/core/internal/labeled_image_base.hh
+++ b/milena/mln/core/internal/labeled_image_base.hh
@@ -310,7 +310,7 @@ namespace mln
const util::array<typename labeled_image_base<I,E>::bbox_t>&
labeled_image_base<I,E>::bboxes() const
{
- return this->data_->bboxes_;
+ return this->data_->bboxes_;
}
diff --git a/milena/mln/core/site_set/box.hh b/milena/mln/core/site_set/box.hh
index 75fb91c..077ac3d 100644
--- a/milena/mln/core/site_set/box.hh
+++ b/milena/mln/core/site_set/box.hh
@@ -143,7 +143,7 @@ namespace mln
box<P> to_larger(unsigned b) const;
/// Return the approximated central site of this box.
- P center() const;
+ P pcenter() const;
/// Test that the box owns valid data, i.e., is initialized and
/// with pmin being 'less-than' pmax.
@@ -390,7 +390,7 @@ namespace mln
template <typename P>
inline
P
- box<P>::center() const
+ box<P>::pcenter() const
{
mln_precondition(is_valid());
P center;
diff --git a/milena/mln/labeling/blobs_and_compute.hh b/milena/mln/labeling/blobs_and_compute.hh
index 4d5d5d8..b76b62a 100644
--- a/milena/mln/labeling/blobs_and_compute.hh
+++ b/milena/mln/labeling/blobs_and_compute.hh
@@ -53,7 +53,9 @@ namespace mln
*/
template <typename I, typename N, typename L, typename A>
- util::couple<mln_ch_value(I, L), util::array<mln_result(A)> >
+ util::couple<mln_ch_value(I,L),
+ util::couple<util::array<mln_result(A)>,
+ util::array<A> > >
blobs_and_compute(const Image<I>& input, const Neighborhood<N>& nbh,
L& nlabels, const Accumulator<A>& accu);
@@ -72,7 +74,8 @@ namespace mln
{
typedef mln_result(A) accu_result;
typedef mln_argument(A) accu_argument;
- typedef util::array<accu_result> result;
+ typedef util::couple<util::array<accu_result>,
+ util::array<A> > result;
void init()
{
@@ -133,7 +136,9 @@ namespace mln
template <typename I, typename N, typename L, typename A>
- util::couple<mln_ch_value(I,L), util::array<mln_result(A)> >
+ util::couple<mln_ch_value(I,L),
+ util::couple<util::array<mln_result(A)>,
+ util::array<A> > >
blobs_and_compute(const Image<I>& input, const Neighborhood<N>& nbh,
L& nlabels, const Accumulator<A>& accu)
{
@@ -151,7 +156,8 @@ namespace mln
output = canvas::labeling::blobs(input, nbh, nlabels, functor);
util::couple<out_t, typename func_t::result>
- result = make::couple(output, functor.result_);
+ result = make::couple(output,
+ make::couple(functor.result_, functor.accus_));
trace::exiting("labeling::blobs_and_compute");
return result;
diff --git a/milena/mln/labeling/colorize.hh b/milena/mln/labeling/colorize.hh
index 26a78df..69493d5 100644
--- a/milena/mln/labeling/colorize.hh
+++ b/milena/mln/labeling/colorize.hh
@@ -103,11 +103,9 @@ namespace mln
unsigned random_number()
{
- static unsigned last = 1;
+ unsigned last = colorize_::min_value + (colorize_::max_value - colorize_::min_value + 1) * rand();
- last = (323 * last + 6603) % 1025;
-
- return colorize_::min_value + last % colorize_::max_value;
+ return math::min(colorize_::min_value + last % colorize_::max_value, colorize_::max_value);
}
@@ -120,17 +118,42 @@ namespace mln
mln::value::rgb<n>
random_color(const mln::value::rgb<n>&)
{
- // Make sure the numbers are generated in the same order
- // whatever the compiler used.
- // For instance, ICC does not compute function arguments in
- // the same order as GCC does.
- unsigned
- red = random_number(),
- green = random_number(),
+ static unsigned
+ nelements = colorize_::max_value - colorize_::min_value + 1;
+ static util::array<util::set<unsigned> >
+ red_(nelements),
+ green_(nelements);
+
+ unsigned red, green, blue;
+
+ unsigned ntries = 0;
+ do
+ {
+ red = random_number();
+ ++ntries;
+ }
+ while (red_[red - colorize_::min_value].nelements() == nelements
+ && ntries < nelements);
+
+ if (ntries == nelements)
+ {
+ trace::warning("labeling::colorize - Can't find a new unique color. Returning black.");
+ return literal::black;
+ }
+
+
+ do
+ green = random_number();
+ while (red_[red - colorize_::min_value].has(green)
+ || green_[green - colorize_::min_value].nelements() == nelements);
+ red_[red - colorize_::min_value].insert(green);
+
+ do
blue = random_number();
- return mln::value::rgb<n>(red,
- green,
- blue);
+ while (green_[green - colorize_::min_value].has(blue));
+ green_[green - colorize_::min_value].insert(blue);
+
+ return mln::value::rgb<n>(red, green, blue);
}
}
diff --git a/milena/mln/labeling/compute.hh b/milena/mln/labeling/compute.hh
index d29242f..4f0d97d 100644
--- a/milena/mln/labeling/compute.hh
+++ b/milena/mln/labeling/compute.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -60,23 +61,6 @@ namespace mln
/// Compute an accumulator onto the pixel values of the image \p input.
/// for each component of the image \p label.
///
- /// \param[in] a An array of accumulator.
- /// \param[in] input The input image.
- /// \param[in] label The labeled image.
- /// \param[in] nlabels The number of labels in \p label.
- /// \return A mln::p_array of accumulator result (one result per label).
- //
- template <typename A, typename I, typename L>
- util::array<mln_result(A)>
- compute(util::array<A>& a,
- const Image<I>& input,
- const Image<L>& label,
- const mln_value(L)& nlabels);
-
-
- /// Compute an accumulator onto the pixel values of the image \p input.
- /// for each component of the image \p label.
- ///
/// \param[in] a An accumulator.
/// \param[in] input The input image.
/// \param[in] label The labeled image.
@@ -138,6 +122,23 @@ namespace mln
const mln_value(L)& nlabels);
+ /// Compute an accumulator onto the pixel values of the image \p input.
+ /// for each component of the image \p label.
+ ///
+ /// \param[in] a An array of accumulator.
+ /// \param[in] input The input image.
+ /// \param[in] label The labeled image.
+ /// \param[in] nlabels The number of labels in \p label.
+ /// \return A mln::p_array of accumulator result (one result per label).
+ //
+ template <typename A, typename I, typename L>
+ util::array<mln_result(A)>
+ compute(util::array<A>& a,
+ const Image<I>& input,
+ const Image<L>& label,
+ const mln_value(L)& nlabels);
+
+
# ifndef MLN_INCLUDE_ONLY
@@ -221,6 +222,49 @@ namespace mln
return res;
}
+ /// Generic implementation of labeling::compute.
+ ///
+ /// \param[in] accus_ An array of accumulators. If the size is
+ /// set to nlabels + 1, the accumulators are
+ /// considered as initialized. Otherwise,
+ /// the size is adjusted.
+ /// \param[in] label_ The labeled image.
+ /// \param[in] nlabels The number of labels in \p label.
+ ///
+ /// \return A mln::p_array of accumulator result (one result per label).
+ //
+ template <typename A, typename L>
+ inline
+ util::array<mln_result(A)>
+ compute(util::array<A>& accus,
+ const Image<L>& label_,
+ const mln_value(L)& nlabels)
+ {
+ trace::entering("labeling::impl::generic::compute");
+ internal::compute_tests(A(), label_, nlabels);
+
+ if (static_cast<unsigned>(nlabels) + 1 != accus.size())
+ {
+ accus.resize(0); // Make sure all the accumulators are
+ // re-initialized when resizing on next
+ // line.
+ accus.resize(static_cast<unsigned>(nlabels) + 1);
+ }
+
+ const L& label = exact(label_);
+
+ mln_piter(L) p(label.domain());
+ for_all(p)
+ accus[label(p)].take(p);
+
+ util::array<mln_result(A)> res;
+ convert::from_to(accus, res);
+
+ trace::exiting("labeling::impl::generic::compute");
+ return res;
+ }
+
+
/// Generic implementation of labeling::compute.
///
@@ -343,6 +387,15 @@ namespace mln
return impl::generic::compute(a, input, label, nlabels);
}
+ template <typename A, typename L>
+ inline
+ util::array<mln_result(A)>
+ compute_dispatch(util::array<A>& accus,
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
+ {
+ return impl::generic::compute(accus, label, nlabels);
+ }
} // end of namespace mln::labeling::internal
@@ -406,6 +459,28 @@ namespace mln
template <typename A, typename L>
inline
util::array<mln_result(A)>
+ compute(util::array<A>& accus,
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
+ {
+ trace::entering("labeling::compute");
+
+ internal::compute_tests(A(), label, nlabels);
+
+ typedef util::array<mln_result(A)> R;
+ R res = internal::compute_dispatch(accus, label, nlabels);
+
+ mln_postcondition(res.nelements() == static_cast<unsigned>(nlabels) + 1);
+
+ trace::exiting("labeling::compute");
+ return res;
+ }
+
+
+
+ template <typename A, typename L>
+ inline
+ util::array<mln_result(A)>
compute(const Accumulator<A>& a,
const Image<L>& label,
const mln_value(L)& nlabels)
diff --git a/milena/mln/transform/influence_zone_geodesic.hh b/milena/mln/transform/influence_zone_geodesic.hh
index 4d7255a..b9a763f 100644
--- a/milena/mln/transform/influence_zone_geodesic.hh
+++ b/milena/mln/transform/influence_zone_geodesic.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -104,16 +105,12 @@ namespace mln
const N& nbh = exact(nbh_);
internal::influence_zone_geodesic_tests(input, nbh);
- mln_precondition(input.domain().pmin() == literal::origin);
std::queue<mln_value(I)*> q;
mln_concrete(I) output;
util::array<int> dp = offsets_wrt(input, nbh);
const unsigned n_nbhs = dp.nelements();
- const unsigned
- ncols = input.ncols(),
- first_offset = input.border() * (ncols + 2 * input.border() + 1);
// Initialization.
{
@@ -124,9 +121,9 @@ namespace mln
extension::fill(output, 1); // in propagation
const unsigned nelts = input.nelements();
- const mln_value(I)* p_i = & input.at_(0, 0);
- mln_value(I)* p_o = & output.at_(0, 0);
- for (unsigned i = first_offset; i < nelts; ++i, ++p_i, ++p_o)
+ const mln_value(I)* p_i = input.buffer();
+ mln_value(I)* p_o = output.buffer();
+ for (unsigned i = 0; i < nelts; ++i, ++p_i, ++p_o)
{
if (*p_i == 0)
continue;
--
1.5.6.5
1
0
* demo/Makefile.am,
* demo/demo.pro,
* demo/demo.qrc,
* demo/icons/document-open.png,
* demo/icons/edit-find.png,
* demo/icons/format-indent-more.png,
* demo/icons/go-next.png,
* demo/icons/image-x-generic.png,
* demo/icons/list-add.png,
* demo/icons/ocr.png,
* demo/icons/text-x-generic.png,
* demo/icons/view-refresh.png,
* demo/icons/x-office-spreadsheet.png,
* demo/src/main.cc,
* demo/src/mainwindow.cc,
* demo/src/mainwindow.hh,
* demo/ui/mainwindow.ui: Move...
* demo/review/Makefile.am,
* demo/review/icons/document-open.png,
* demo/review/icons/edit-find.png,
* demo/review/icons/format-indent-more.png,
* demo/review/icons/go-next.png,
* demo/review/icons/image-x-generic.png,
* demo/review/icons/list-add.png,
* demo/review/icons/ocr.png,
* demo/review/icons/text-x-generic.png,
* demo/review/icons/view-refresh.png,
* demo/review/icons/x-office-spreadsheet.png,
* demo/review/review.pro,
* demo/review/review.qrc,
* demo/review/src/main.cc,
* demo/review/src/mainwindow.cc,
* demo/review/src/mainwindow.hh,
* demo/review/ui/mainwindow.ui: ... here.
---
scribo/ChangeLog | 40 ++++++++++++++++++++
scribo/demo/{ => review}/Makefile.am | 0
scribo/demo/{ => review}/icons/document-open.png | Bin 1550 -> 1550 bytes
scribo/demo/{ => review}/icons/edit-find.png | Bin 1636 -> 1636 bytes
.../demo/{ => review}/icons/format-indent-more.png | Bin 766 -> 766 bytes
scribo/demo/{ => review}/icons/go-next.png | Bin 1219 -> 1219 bytes
scribo/demo/{ => review}/icons/image-x-generic.png | Bin 1163 -> 1163 bytes
scribo/demo/{ => review}/icons/list-add.png | Bin 601 -> 601 bytes
scribo/demo/{ => review}/icons/ocr.png | Bin 14929 -> 14929 bytes
scribo/demo/{ => review}/icons/text-x-generic.png | Bin 744 -> 744 bytes
scribo/demo/{ => review}/icons/view-refresh.png | Bin 2024 -> 2024 bytes
.../{ => review}/icons/x-office-spreadsheet.png | Bin 1518 -> 1518 bytes
scribo/demo/{demo.pro => review/review.pro} | 4 +-
scribo/demo/{demo.qrc => review/review.qrc} | 0
scribo/demo/{ => review}/src/main.cc | 0
scribo/demo/{ => review}/src/mainwindow.cc | 0
scribo/demo/{ => review}/src/mainwindow.hh | 0
scribo/demo/{ => review}/ui/mainwindow.ui | 0
18 files changed, 42 insertions(+), 2 deletions(-)
rename scribo/demo/{ => review}/Makefile.am (100%)
rename scribo/demo/{ => review}/icons/document-open.png (100%)
rename scribo/demo/{ => review}/icons/edit-find.png (100%)
rename scribo/demo/{ => review}/icons/format-indent-more.png (100%)
rename scribo/demo/{ => review}/icons/go-next.png (100%)
rename scribo/demo/{ => review}/icons/image-x-generic.png (100%)
rename scribo/demo/{ => review}/icons/list-add.png (100%)
rename scribo/demo/{ => review}/icons/ocr.png (100%)
rename scribo/demo/{ => review}/icons/text-x-generic.png (100%)
rename scribo/demo/{ => review}/icons/view-refresh.png (100%)
rename scribo/demo/{ => review}/icons/x-office-spreadsheet.png (100%)
rename scribo/demo/{demo.pro => review/review.pro} (84%)
rename scribo/demo/{demo.qrc => review/review.qrc} (100%)
rename scribo/demo/{ => review}/src/main.cc (100%)
rename scribo/demo/{ => review}/src/mainwindow.cc (100%)
rename scribo/demo/{ => review}/src/mainwindow.hh (100%)
rename scribo/demo/{ => review}/ui/mainwindow.ui (100%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index f3c022a..26f6201 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,43 @@
+2010-02-09 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Move Scribo demo.
+
+ * demo/Makefile.am,
+ * demo/demo.pro,
+ * demo/demo.qrc,
+ * demo/icons/document-open.png,
+ * demo/icons/edit-find.png,
+ * demo/icons/format-indent-more.png,
+ * demo/icons/go-next.png,
+ * demo/icons/image-x-generic.png,
+ * demo/icons/list-add.png,
+ * demo/icons/ocr.png,
+ * demo/icons/text-x-generic.png,
+ * demo/icons/view-refresh.png,
+ * demo/icons/x-office-spreadsheet.png,
+ * demo/src/main.cc,
+ * demo/src/mainwindow.cc,
+ * demo/src/mainwindow.hh,
+ * demo/ui/mainwindow.ui: Move...
+
+ * demo/review/Makefile.am,
+ * demo/review/icons/document-open.png,
+ * demo/review/icons/edit-find.png,
+ * demo/review/icons/format-indent-more.png,
+ * demo/review/icons/go-next.png,
+ * demo/review/icons/image-x-generic.png,
+ * demo/review/icons/list-add.png,
+ * demo/review/icons/ocr.png,
+ * demo/review/icons/text-x-generic.png,
+ * demo/review/icons/view-refresh.png,
+ * demo/review/icons/x-office-spreadsheet.png,
+ * demo/review/review.pro,
+ * demo/review/review.qrc,
+ * demo/review/src/main.cc,
+ * demo/review/src/mainwindow.cc,
+ * demo/review/src/mainwindow.hh,
+ * demo/review/ui/mainwindow.ui: ... here.
+
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
* io/xml/save_text_lines.hh: New. Add partial support for
diff --git a/scribo/demo/Makefile.am b/scribo/demo/review/Makefile.am
similarity index 100%
rename from scribo/demo/Makefile.am
rename to scribo/demo/review/Makefile.am
diff --git a/scribo/demo/icons/document-open.png b/scribo/demo/review/icons/document-open.png
similarity index 100%
rename from scribo/demo/icons/document-open.png
rename to scribo/demo/review/icons/document-open.png
diff --git a/scribo/demo/icons/edit-find.png b/scribo/demo/review/icons/edit-find.png
similarity index 100%
rename from scribo/demo/icons/edit-find.png
rename to scribo/demo/review/icons/edit-find.png
diff --git a/scribo/demo/icons/format-indent-more.png b/scribo/demo/review/icons/format-indent-more.png
similarity index 100%
rename from scribo/demo/icons/format-indent-more.png
rename to scribo/demo/review/icons/format-indent-more.png
diff --git a/scribo/demo/icons/go-next.png b/scribo/demo/review/icons/go-next.png
similarity index 100%
rename from scribo/demo/icons/go-next.png
rename to scribo/demo/review/icons/go-next.png
diff --git a/scribo/demo/icons/image-x-generic.png b/scribo/demo/review/icons/image-x-generic.png
similarity index 100%
rename from scribo/demo/icons/image-x-generic.png
rename to scribo/demo/review/icons/image-x-generic.png
diff --git a/scribo/demo/icons/list-add.png b/scribo/demo/review/icons/list-add.png
similarity index 100%
rename from scribo/demo/icons/list-add.png
rename to scribo/demo/review/icons/list-add.png
diff --git a/scribo/demo/icons/ocr.png b/scribo/demo/review/icons/ocr.png
similarity index 100%
rename from scribo/demo/icons/ocr.png
rename to scribo/demo/review/icons/ocr.png
diff --git a/scribo/demo/icons/text-x-generic.png b/scribo/demo/review/icons/text-x-generic.png
similarity index 100%
rename from scribo/demo/icons/text-x-generic.png
rename to scribo/demo/review/icons/text-x-generic.png
diff --git a/scribo/demo/icons/view-refresh.png b/scribo/demo/review/icons/view-refresh.png
similarity index 100%
rename from scribo/demo/icons/view-refresh.png
rename to scribo/demo/review/icons/view-refresh.png
diff --git a/scribo/demo/icons/x-office-spreadsheet.png b/scribo/demo/review/icons/x-office-spreadsheet.png
similarity index 100%
rename from scribo/demo/icons/x-office-spreadsheet.png
rename to scribo/demo/review/icons/x-office-spreadsheet.png
diff --git a/scribo/demo/demo.pro b/scribo/demo/review/review.pro
similarity index 84%
rename from scribo/demo/demo.pro
rename to scribo/demo/review/review.pro
index 01e36ee..3ee66e9 100644
--- a/scribo/demo/demo.pro
+++ b/scribo/demo/review/review.pro
@@ -5,7 +5,7 @@
TEMPLATE = app
TARGET =
DEPENDPATH += . src ui
-INCLUDEPATH += . src ../../ ../../milena
+INCLUDEPATH += . src ../../../ ../../../milena
DEFINES += NDEBUG
# Input
@@ -13,4 +13,4 @@ HEADERS += src/mainwindow.hh
FORMS += ui/mainwindow.ui
SOURCES += src/main.cc src/mainwindow.cc
-RESOURCES = demo.qrc
+RESOURCES = review.qrc
diff --git a/scribo/demo/demo.qrc b/scribo/demo/review/review.qrc
similarity index 100%
rename from scribo/demo/demo.qrc
rename to scribo/demo/review/review.qrc
diff --git a/scribo/demo/src/main.cc b/scribo/demo/review/src/main.cc
similarity index 100%
rename from scribo/demo/src/main.cc
rename to scribo/demo/review/src/main.cc
diff --git a/scribo/demo/src/mainwindow.cc b/scribo/demo/review/src/mainwindow.cc
similarity index 100%
rename from scribo/demo/src/mainwindow.cc
rename to scribo/demo/review/src/mainwindow.cc
diff --git a/scribo/demo/src/mainwindow.hh b/scribo/demo/review/src/mainwindow.hh
similarity index 100%
rename from scribo/demo/src/mainwindow.hh
rename to scribo/demo/review/src/mainwindow.hh
diff --git a/scribo/demo/ui/mainwindow.ui b/scribo/demo/review/ui/mainwindow.ui
similarity index 100%
rename from scribo/demo/ui/mainwindow.ui
rename to scribo/demo/review/ui/mainwindow.ui
--
1.5.6.5
1
0
last-svn-commit-44-g27b5f71 configure.ac: Configure scribo/demo/review.
by Guillaume Lazzara 11 Mar '10
by Guillaume Lazzara 11 Mar '10
11 Mar '10
---
ChangeLog | 4 ++++
configure.ac | 2 +-
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 961ff85..4f21dd6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-02-16 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ * configure.ac: Configure scribo/demo/review.
+
2009-12-15 Guillaume Lazzara <z(a)lrde.epita.fr>
* configure.ac: Configure scribo/tests/core.
diff --git a/configure.ac b/configure.ac
index 0f66fa3..0edfcb6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -210,7 +210,7 @@ AM_CONDITIONAL([ENABLE_SCRIBO], [test x$enable_scribo = xyes])
AC_CONFIG_FILES([
scribo/Makefile
- scribo/demo/Makefile
+ scribo/demo/review/Makefile
scribo/src/Makefile
scribo/src/binarization/Makefile
scribo/src/debug/Makefile
--
1.5.6.5
1
0
11 Mar '10
* mln/fun/all.hh: Include a new file.
* mln/fun/n2v/all.hh,
* mln/fun/n2v/white_gaussian.hh: New.
---
milena/ChangeLog | 9 +++
milena/mln/fun/all.hh | 2 +
milena/mln/fun/{stat => n2v}/all.hh | 17 ++---
.../fun/{v2w2v/cos.hh => n2v/white_gaussian.hh} | 75 +++++++++++--------
4 files changed, 62 insertions(+), 41 deletions(-)
copy milena/mln/fun/{stat => n2v}/all.hh (79%)
copy milena/mln/fun/{v2w2v/cos.hh => n2v/white_gaussian.hh} (61%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 9a870bf..fae42e1 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,12 @@
+2010-02-24 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add white gaussian noise function.
+
+ * mln/fun/all.hh: Include a new file.
+
+ * mln/fun/n2v/all.hh,
+ * mln/fun/n2v/white_gaussian.hh: New.
+
2010-02-16 Guillaume Lazzara <z(a)lrde.epita.fr>
Cleanup to_qimage convertion routines.
diff --git a/milena/mln/fun/all.hh b/milena/mln/fun/all.hh
index b353f38..b4f3ebb 100644
--- a/milena/mln/fun/all.hh
+++ b/milena/mln/fun/all.hh
@@ -57,6 +57,8 @@ namespace mln
// Sub-directories.
+# include <mln/fun/n2v/all.hh>
+
# include <mln/fun/i2v/all.hh>
//<<lrde
# include <mln/fun/meta/all.hh>
diff --git a/milena/mln/fun/stat/all.hh b/milena/mln/fun/n2v/all.hh
similarity index 79%
copy from milena/mln/fun/stat/all.hh
copy to milena/mln/fun/n2v/all.hh
index d207047..0e0e55c 100644
--- a/milena/mln/fun/stat/all.hh
+++ b/milena/mln/fun/n2v/all.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,12 +23,12 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_FUN_STAT_ALL_HH
-# define MLN_FUN_STAT_ALL_HH
+#ifndef MLN_FUN_N2V_ALL_HH
+# define MLN_FUN_N2V_ALL_HH
/// \file
///
-/// File that includes all statistical functions.
+/// File that includes all functions from nil to value.
namespace mln
@@ -37,16 +37,15 @@ namespace mln
namespace fun
{
- /// \brief Namespace of statistical functions.
+ /// \brief Namespace of functions from nil to value.
///
/// \ingroup modfun
- namespace stat {}
+ namespace n2v {}
}
}
-# include <mln/fun/stat/mahalanobis.hh>
+# include <mln/fun/n2v/white_gaussian.hh>
-
-#endif // ! MLN_FUN_STAT_ALL_HH
+#endif // ! MLN_FUN_N2V_ALL_HH
diff --git a/milena/mln/fun/v2w2v/cos.hh b/milena/mln/fun/n2v/white_gaussian.hh
similarity index 61%
copy from milena/mln/fun/v2w2v/cos.hh
copy to milena/mln/fun/n2v/white_gaussian.hh
index 7616e05..53afbf6 100644
--- a/milena/mln/fun/v2w2v/cos.hh
+++ b/milena/mln/fun/n2v/white_gaussian.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,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 MLN_FUN_V2W2V_COS_HH
-# define MLN_FUN_V2W2V_COS_HH
+#ifndef MLN_FUN_N2V_WHITE_GAUSSIAN_HH
+# define MLN_FUN_N2V_WHITE_GAUSSIAN_HH
-/*! \file
- *
- * \brief Cos functor.
- *
- * \see mln/math/.
- */
+/// \file
+///
+/// White Gaussian noise.
+
+# include <cstdlib>
+# include <ctime>
# include <mln/core/concept/function.hh>
-# include <mln/trait/value_.hh>
-# include <mln/math/cos.hh>
-# include <mln/math/acos.hh>
namespace mln
@@ -46,48 +43,62 @@ namespace mln
namespace fun
{
- namespace v2w2v
+ namespace n2v
{
- /*! \brief Cosinus bijective functor.
- *
- * \c V is the type of input values and the result type.
- *
- * \see mln::math::cos.
+ /*! \brief Generate a White Gaussian Noise.
+
+
+ Reference:
+ http://www.dspguru.com/dsp/howtos/how-to-generate-white-gaussian-noise
*/
template <typename V>
- struct cos : public Function_v2v< cos<V> >
+ struct white_gaussian : Function_n2v< white_gaussian<V> >
{
typedef V result;
- V operator()(const V& v) const;
- V f_1 (const V& v) const;
+
+ white_gaussian(double sigma_);
+ V operator()() const;
+
+ double sigma;
};
+
# ifndef MLN_INCLUDE_ONLY
+
template <typename V>
- inline
- V
- cos<V>::operator()(const V& v) const
+ white_gaussian<V>::white_gaussian(double sigma_)
+ : sigma(sigma_)
{
- return mln::math::cos (v);
+ srand(time(0));
}
+
template <typename V>
- inline
- V
- cos<V>::f_1(const V& v) const
+ V white_gaussian<V>::operator()() const
{
- return mln::math::acos (v);
- }
+ double X = 0;
+ for (int i = 1; i < 50; ++i)
+ {
+ double U = rand() / (float)RAND_MAX;
+ X = X + U;
+ }
+
+ X = X - 25.f; /* set mean to 0 */
+ X = X * sqrt(12 / 50.f); /* adjust variance to 1 */
+
+ return sigma * X;
+ };
+
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::fun::v2w2v
+ } // end of namespace mln::fun::n2v
} // end of namespace mln::fun
} // end of namespace mln
-#endif // ! MLN_FUN_V2W2V_COS_HH
+#endif // ! MLN_FUN_N2V_WHITE_GAUSSIAN_HH
--
1.5.6.5
1
0
last-svn-commit-20-g27ae9e6 Improve stats computation in Sauvola Multi-scale.
by Guillaume Lazzara 11 Mar '10
by Guillaume Lazzara 11 Mar '10
11 Mar '10
* binarization/internal/first_pass_functor.hh: Use
sauvola_threshold routine.
* binarization/sauvola_threshold.hh: Remove debug and fix invalid
read in integral image.
* canvas/integral_browsing.hh,
* subsampling/integral_single_image.hh: Fix stats computation.
* src/binarization/sauvola_ms.cc: Fix window parameter and make
debug output optional.
---
scribo/ChangeLog | 16 +
scribo/binarization/internal/first_pass_functor.hh | 14 +-
scribo/binarization/sauvola_threshold.hh | 73 ++-
scribo/canvas/integral_browsing.hh | 58 ++-
scribo/src/binarization/sauvola_ms.cc | 740 ++++++++++++++++++--
scribo/subsampling/integral_single_image.hh | 100 ++-
6 files changed, 904 insertions(+), 97 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 9eac19c..0fcd35f 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,19 @@
+2009-12-11 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Improve Sauvola Multi-scale.
+
+ * binarization/internal/first_pass_functor.hh: Use
+ sauvola_threshold routine.
+
+ * binarization/sauvola_threshold.hh: Remove debug and fix invalid
+ read in integral image.
+
+ * canvas/integral_browsing.hh,
+ * subsampling/integral_single_image.hh: Fix stats computation.
+
+ * src/binarization/sauvola_ms.cc: Fix window parameter and make
+ debug output optional.
+
2009-12-04 Guillaume Lazzara <z(a)lrde.epita.fr>
Optimize Sauvola's multiscale binarization.
diff --git a/scribo/binarization/internal/first_pass_functor.hh b/scribo/binarization/internal/first_pass_functor.hh
index 13fc62a..6a9bbb9 100644
--- a/scribo/binarization/internal/first_pass_functor.hh
+++ b/scribo/binarization/internal/first_pass_functor.hh
@@ -98,8 +98,16 @@ namespace scribo
// Use an inlined and developed version of sauvola's
// threshold formula.
- value::int_u8 t_p = mean * (one_k + k_R * stddev);
-// value::int_u8 t_p = sauvola_threshold_formula(mean, stddev);
+// value::int_u8 t_p = mean * (one_k + k_R * stddev);
+
+// std::cout << t_p << ", ";
+
+// std::cout << input.element(p) << " - " << t_p << std::endl;
+ value::int_u8 t_p = sauvola_threshold_formula(mean, stddev);
+
+// std::cout << input.point_at_index(p)
+// << " - " << sauvola_threshold_formula(mean, stddev);
+
msk.element(p) = input.element(p) < t_p;
t_sub.element(p) = t_p;
@@ -128,6 +136,8 @@ namespace scribo
void finalize()
{
mln_assertion(! pxl.is_valid());
+
+// std::cout << std::endl << " ------- " << std::endl;
}
};
diff --git a/scribo/binarization/sauvola_threshold.hh b/scribo/binarization/sauvola_threshold.hh
index 857de1f..b1f9a81 100644
--- a/scribo/binarization/sauvola_threshold.hh
+++ b/scribo/binarization/sauvola_threshold.hh
@@ -46,6 +46,9 @@
# include <scribo/core/init_integral_image.hh>
+
+#include <mln/io/pgm/save.hh>
+
namespace scribo
{
@@ -168,8 +171,8 @@ namespace scribo
// Window half width.
int w_2 = win_width >> 1;
- int row_min = std::max(0, p.row() - w_2);
- int col_min = std::max(0, p.col() - w_2);
+ int row_min = std::max(0, p.row() - w_2 - 1);
+ int col_min = std::max(0, p.col() - w_2 - 1);
int row_max = std::min(static_cast<int>(simple.nrows()) - 1,
p.row() + w_2);
@@ -177,12 +180,7 @@ namespace scribo
p.col() + w_2);
-// std::cout << "sauvola threshold : "
-// << simple.domain() << " - "
-// << row_max << " - "
-// << col_max << std::endl;
-
- double wh = (row_max - row_min + 1) * (col_max - col_min + 1);
+ double wh = (row_max - row_min) * (col_max - col_min);
// Mean.
double m_x_y_tmp = (simple.at_(row_max, col_max)
@@ -200,9 +198,38 @@ namespace scribo
double s_x_y = std::sqrt((s_x_y_tmp - (m_x_y_tmp * m_x_y_tmp) / wh) / (wh - 1.f));
+
+// if (p == point2d(3,3))// || p == point2d(4,4) || p == point2d(1,1))
+// {
+// // std::cout << "p" << p << " - A(" << row_min << ", " << col_min
+// // << ") = " << simple.at_(row_min, col_min)
+
+// << " - B(" << row_min << ", " << col_max
+// << ") = " << simple.at_(row_min, col_max)
+
+// << " - C(" << row_max << ", " << col_min
+// << ") = " << simple.at_(row_max, col_min)
+
+// << " - D(" << row_max << ", " << col_max
+// << ") = " << simple.at_(row_max, col_max)
+// << " - n = " << wh
+// << std::endl;
+
+// << std::endl;
+// }
+
// Thresholding.
double t_x_y = sauvola_threshold_formula(m_x_y, s_x_y, k, R);
+
+// std::cout << p
+// << " - m = " << m_x_y
+// << " - s = " << s_x_y
+// << " - t = " << t_x_y
+// << " - sum = " << m_x_y_tmp
+// << " - sum_2 = " << s_x_y_tmp
+// << std::endl;
+
return t_x_y;
}
@@ -219,19 +246,12 @@ namespace scribo
int row_min = std::max(0, p.row() - w_2);
int col_min = std::max(0, p.col() - w_2);
- //FIXME: offset (-4) should be replaced by the number of
- //padding pixels.
int row_max = std::min(static_cast<int>(integral.nrows()) - 1,
p.row() + w_2);
int col_max = std::min(static_cast<int>(integral.ncols()) - 1,
p.col() + w_2);
-// std::cout << "sauvola threshold : "
-// << simple.domain() << " - "
-// << row_max << " - "
-// << col_max << std::endl;
-
double wh = (row_max - row_min + 1) * (col_max - col_min + 1);
// Mean.
@@ -251,7 +271,7 @@ namespace scribo
double s_x_y = std::sqrt((s_x_y_tmp - (m_x_y_tmp * m_x_y_tmp) / wh) / (wh - 1.f));
// Thresholding.
- double t_x_y = m_x_y * (1.0 + 0.14 * ((s_x_y / 128) - 1.0));
+ double t_x_y = m_x_y * (1.0 + 0.34 * ((s_x_y / 128) - 1.0));
return t_x_y;
}
@@ -438,6 +458,25 @@ namespace scribo
mln_precondition(mln_site_(I)::dim == 2);
mln_precondition(exact(input).is_valid());
+
+// {
+// J& simple_ = exact(simple);
+// J& squared_ = exact(squared);
+// mln_piter(J) p(simple_.domain());
+// for_all(p)
+// {
+// std::cout << simple_(p) << ", ";
+// }
+// std::cout << std::endl << " ------- " << std::endl;
+// for_all(p)
+// {
+// std::cout << squared_(p) << ", ";
+// }
+// std::cout << std::endl << " ------- " << std::endl;
+// }
+
+
+
typedef mln_value(I) value_t;
mln_ch_value(I, value::int_u8)
output = internal::sauvola_threshold_dispatch(value_t(), exact(input),
@@ -445,6 +484,8 @@ namespace scribo
exact(simple),
exact(squared));
+// std::cout << std::endl << " ------- " << std::endl;
+ io::pgm::save(output, "ref_2_t.pgm");
trace::exiting("scribo::text::ppm2pbm");
return output;
}
diff --git a/scribo/canvas/integral_browsing.hh b/scribo/canvas/integral_browsing.hh
index 814733f..44d73a0 100644
--- a/scribo/canvas/integral_browsing.hh
+++ b/scribo/canvas/integral_browsing.hh
@@ -58,9 +58,13 @@ namespace scribo
double& mean, double& stddev)
{
mean = sum / n;
- stddev = std::sqrt(sum_2 / n - mean * mean);
+// stddev = std::sqrt(sum_2 / n - mean * mean);
+
+// std::cout << "(" << mean << " - " << stddev << " - " << n << "),";
+
// unbias version:
- // stddev = std::sqrt((sum_2 - n * mean * mean) / (n - 1));
+ stddev = std::sqrt((sum_2 - sum * sum / n) / (n - 1));
+
}
} // end of namespace scribo::canvas::internal
@@ -72,6 +76,7 @@ namespace scribo
void integral_browsing(const image2d<util::couple<double, double> >& ima,
unsigned step,
unsigned w, unsigned h,
+ unsigned s,
F& functor)
{
typedef util::couple<double, double> V;
@@ -112,6 +117,8 @@ namespace scribo
double mean, stddev;
+ unsigned s_2 = s * s;
+
// -------------------------------
// T (top)
@@ -146,7 +153,7 @@ namespace scribo
// D
internal::compute_stats(d_ima->first(),
d_ima->second(),
- size_tl,
+ size_tl * s_2,
mean, stddev);
functor.exec(mean, stddev);
d_ima += step;
@@ -166,7 +173,7 @@ namespace scribo
// D - C
internal::compute_stats(d_ima->first() - c_ima->first(),
d_ima->second() - c_ima->second(),
- size_tc,
+ size_tc * s_2,
mean, stddev);
functor.exec(mean, stddev);
c_ima += step;
@@ -188,7 +195,7 @@ namespace scribo
// D* - C
internal::compute_stats(d_sum - c_ima->first(),
d_sum_2 - c_ima->second(),
- size_tr,
+ size_tr * s_2,
mean, stddev);
functor.exec(mean, stddev);
c_ima += step;
@@ -239,7 +246,7 @@ namespace scribo
// D - B
internal::compute_stats(d_ima->first() - b_ima->first(),
d_ima->second() - b_ima->second(),
- size_ml,
+ size_ml * s_2,
mean, stddev);
functor.exec(mean, stddev);
b_ima += step;
@@ -258,11 +265,40 @@ namespace scribo
for (; col <= max_col_mid; col += step)
{
// D + A - B - C
+
+// if (row == 3 && col == 3)
+// std::cout << "p(" << row << "," << col << ") - "
+
+// << "A" << ima.point_at_index(a_ima - ima.buffer())
+// << "=" << a_ima->first() << " - "
+
+// << "B" << ima.point_at_index(b_ima - ima.buffer())
+// << "=" << b_ima->first() << " - "
+
+// << "C" << ima.point_at_index(c_ima - ima.buffer())
+// << "=" << c_ima->first() << " - "
+
+// << "D" << ima.point_at_index(d_ima - ima.buffer())
+// << "=" << d_ima->first() << " - "
+
+// << "n =" << size_mc << " - "
+// << "n*s_2 =" << size_mc * s_2
+// << std::endl;
+
internal::compute_stats((d_ima->first() - b_ima->first()) + (a_ima->first() - c_ima->first()),
(d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second()),
- size_mc,
+ size_mc * s_2,
mean, stddev);
+
functor.exec(mean, stddev);
+
+// std::cout << " - " << mean
+// << " - " << stddev
+// << " - " << (d_ima->first() - b_ima->first()) + (a_ima->first() - c_ima->first())
+// << " - " << (d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second())
+// << std::endl;
+
+
a_ima += step;
b_ima += step;
c_ima += step;
@@ -283,7 +319,7 @@ namespace scribo
// D* + A - B* - C
internal::compute_stats(d_b_sum + (a_ima->first() - c_ima->first()),
d_b_sum_2 + (a_ima->second() - c_ima->second()),
- size_mr,
+ size_mr * s_2,
mean, stddev);
functor.exec(mean, stddev);
a_ima += step;
@@ -332,7 +368,7 @@ namespace scribo
// D* - B
internal::compute_stats(d_ima->first() - b_ima->first(),
d_ima->second() - b_ima->second(),
- size_bl,
+ size_bl * s_2,
mean, stddev);
functor.exec(mean, stddev);
b_ima += step;
@@ -354,7 +390,7 @@ namespace scribo
// D* + A - B - C*
internal::compute_stats((d_ima->first() - b_ima->first()) + (a_ima->first() - c_ima->first()),
(d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second()),
- size_bc,
+ size_bc * s_2,
mean, stddev);
// std::cout << (d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second()) << std::endl;
@@ -385,7 +421,7 @@ namespace scribo
// D* + A - B* - C*
internal::compute_stats(d_b_sum + (a_ima->first() - c_ima->first()),
d_b_sum_2 + (a_ima->second() - c_ima->second()),
- size_br,
+ size_br * s_2,
mean, stddev);
functor.exec(mean, stddev);
a_ima += step;
diff --git a/scribo/src/binarization/sauvola_ms.cc b/scribo/src/binarization/sauvola_ms.cc
index 8a07dcc..ff5a99d 100644
--- a/scribo/src/binarization/sauvola_ms.cc
+++ b/scribo/src/binarization/sauvola_ms.cc
@@ -26,10 +26,10 @@
#include <mln/core/alias/neighb2d.hh>
#include <mln/data/stretch.hh>
#include <mln/data/paste.hh>
-// #include <mln/debug/iota.hh>
-// #include <mln/debug/quiet.hh>
-// #include <mln/debug/println.hh>
-// #include <mln/debug/println_with_border.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/quiet.hh>
+#include <mln/debug/println.hh>
+#include <mln/debug/println_with_border.hh>
#include <mln/debug/filename.hh>
#include <mln/fun/i2v/array.hh>
#include <mln/io/pbm/all.hh>
@@ -96,6 +96,7 @@ namespace mln
image2d<int_u8>
compute_t_n_and_e_2(const image2d<int_u8>& sub, image2d<int_u8>& e_2,
unsigned lambda_min, unsigned lambda_max,
+ unsigned s,
unsigned q, unsigned i, unsigned w,
const image2d<util::couple<double,double> >& integral_sum_sum_2)
// lambdas: limits of component cardinality at this scale
@@ -111,22 +112,38 @@ namespace mln
tt.restart();
- unsigned w_2 = w / 2 * ratio;
+ unsigned
+ w_local = w * ratio,
+ w_local_h = w_local,
+ w_local_w = w_local;
+
+ if (! (w_local % 2))
+ {
+ --w_local_w;
+ ++w_local_h;
+ }
+
+// std::cout << "Echelle " << i
+// << " - w_local_h = " << w_local_h
+// << " - w_local_w = " << w_local_w
+// << " - w_1 = " << (w_local - 1) * s + 1
+// << std::endl;
+
+// std::cout << "Ratio = " << ratio << std::endl;
+// std::cout << " -----------" << std::endl;
// 1st pass
scribo::binarization::internal::first_pass_functor< image2d<int_u8> >
f(sub);
scribo::canvas::integral_browsing(integral_sum_sum_2,
ratio,
- w_2, w_2,
+ w_local_w, w_local_h,
+ s,
f);
-// debug::println("mask", f.msk);
-// debug::println("parent", f.parent);
-// debug::println("card", f.card);
t_ = tt;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "1st pass - " << t_ << std::endl;
tt.restart();
@@ -175,7 +192,6 @@ namespace mln
{
for (unsigned l = 0; l < ptr.size(); ++l)
std::memset(ptr(l), i, ratio * sizeof(mln_value_(I)));
-// debug(sq) = i;
}
}
@@ -188,7 +204,6 @@ namespace mln
{
for (unsigned l = 0; l < ptr.size(); ++l)
std::memset(ptr(l), i, ratio * sizeof(mln_value_(I)));
-// debug(sq) = i;
}
}
@@ -204,12 +219,10 @@ namespace mln
}
t_ = tt;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "2nd pass - " << t_ << std::endl;
// io::pgm::save(e_2, mln::debug::filename("e.pgm", i));
-// io::pgm::save(debug, mln::debug::filename("debug.pgm", i));
-// debug::println(msk);
// io::pbm::save(f.msk, mln::debug::filename("mask.pbm", i));
// io::pgm::save(data::stretch(int_u8(), card), mln::debug::filename("card.pgm"));
} // end of 2nd pass
@@ -245,9 +258,9 @@ namespace mln
// image at scale 1 does not always have a size which can be
// divided by (4*s), some sites in the border may not be processed
// and we must skip them.
- unsigned more_offset = in.border() - ((4 * s) - in.ncols() % (4 * s));
+ int more_offset = - ((4 * s) - in.ncols() % (4 * s));
- if (more_offset == (4 * s))
+ if (more_offset == - (static_cast<int>(4*s)))
more_offset = 0; // No offset needed.
const int
@@ -267,7 +280,7 @@ namespace mln
delta3 = t_ima[3].delta_index(dpoint2d(+1, -1)),
- eor1 = in.delta_index(dpoint2d(+4 * s, - in.ncols() - in.border())) + more_offset,
+ eor1 = in.delta_index(dpoint2d(+4 * s, - in.ncols())) + more_offset,
eor2 = t_ima[2].delta_index(dpoint2d(+4,- t_ima[2].ncols())),
eor3 = t_ima[3].delta_index(dpoint2d(+2,- t_ima[3].ncols())),
eor4 = t_ima[4].delta_index(dpoint2d(+1,- t_ima[4].ncols()));
@@ -700,6 +713,499 @@ namespace mln
+// template <typename I, typename J, typename K>
+// mln_ch_value(I, unsigned)
+// binarize_generic_debug(const I& in, const J& e2, const util::array<K>& t_ima,
+// unsigned s)
+// {
+// mln_ch_value(I,unsigned) out;
+// initialize(out, in);
+// data::fill(out, 0);
+
+// typedef const mln_value(K)* ptr_type;
+
+// ptr_type ptr_t[5];
+// ptr_t[2] = & t_ima[2].at_(0, 0);
+// ptr_t[3] = & t_ima[3].at_(0, 0);
+// ptr_t[4] = & t_ima[4].at_(0, 0);
+
+
+// const mln_value(J)* ptr_e2 = & e2.at_(0, 0);
+// const mln_value(I)* ptr__in = & in.at_(0, 0);
+// unsigned* ptr__out = & out.at_(0, 0);
+
+
+// // Since we iterate from a smaller image in the largest ones and
+// // image at scale 1 does not always have a size which can be
+// // divided by (4*s), some sites in the border may not be processed
+// // and we must skip them.
+
+// std::cout << in.ncols() << std::endl;
+// std::cout << in.ncols() % (4 * s) << std::endl;
+// int more_offset = - ((4 * s) - in.ncols() % (4 * s));
+
+// if (more_offset == - (4*s))
+// more_offset = 0; // No offset needed.
+
+// std::cout << "more_offset == " << more_offset << std::endl;
+// std::cout << "- b1 = " << in.border()
+// << "- b2 = " << t_ima[2].border()
+// << "- b3 = " << t_ima[3].border()
+// << "- b4 = " << t_ima[4].border()
+// << std::endl;
+
+// const int
+// nrows4 = t_ima[4].nrows(), ncols4 = t_ima[4].ncols(),
+
+
+// delta1 = in.delta_index(dpoint2d(+1, -(s - 1))),
+// delta1b = in.delta_index(dpoint2d(+1, -(s + s - 1))),
+// delta1c = in.delta_index(dpoint2d(-(s + s - 1), +1)),
+// delta1d = in.delta_index(dpoint2d(+1, -(s * 4 - 1))),
+// delta1e = in.delta_index(dpoint2d(-(s * 4 - 1), +1)),
+// delta1f = in.delta_index(dpoint2d(-(s - 1), +1)),
+
+// delta2 = t_ima[2].delta_index(dpoint2d(+1, -1)),
+// delta2b = t_ima[2].delta_index(dpoint2d(+1, -3)),
+// delta2c = t_ima[2].delta_index(dpoint2d(-3, +1)),
+
+// delta3 = t_ima[3].delta_index(dpoint2d(+1, -1)),
+
+// eor1 = in.delta_index(dpoint2d(+4 * s, - in.ncols())) + more_offset,
+// eor2 = t_ima[2].delta_index(dpoint2d(+4,- t_ima[2].ncols())),
+// eor3 = t_ima[3].delta_index(dpoint2d(+2,- t_ima[3].ncols())),
+// eor4 = t_ima[4].delta_index(dpoint2d(+1,- t_ima[4].ncols()));
+
+// unsigned pid = 0;
+
+// mln_value(J) threshold;
+// for (int row4 = 0; row4 < nrows4; ++row4)
+// {
+// for (int col4 = 0; col4 < ncols4; ++col4)
+// {
+// // top left 1
+// {
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1f; ptr__in += delta1f;
+// }
+
+// ++ptr_t[2]; ++ptr_e2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1b; ptr__in += delta1b;
+// }
+
+// ptr_t[2] += delta2; ptr_e2 += delta2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1f; ptr__in += delta1f;
+
+// }
+
+// ++ptr_t[2]; ++ptr_e2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1c; ptr__in += delta1c;
+// }
+
+// ptr_t[2] -= delta2; ptr_e2 -= delta2;
+// }
+
+// // top right 1
+// ptr_t[3] += 1;
+// {
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1f; ptr__in += delta1f;
+// }
+
+// ++ptr_t[2]; ++ptr_e2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1b; ptr__in += delta1b;
+// }
+
+// ptr_t[2] += delta2; ptr_e2 += delta2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1f; ptr__in += delta1f;
+// }
+
+// ++ptr_t[2]; ++ptr_e2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1d; ptr__in += delta1d;
+// }
+
+// ptr_t[2] += delta2b; ptr_e2 += delta2b;
+// }
+
+// // bot left 1
+// ptr_t[3] += delta3;
+// {
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1f; ptr__in += delta1f;
+// }
+
+// ++ptr_t[2]; ++ptr_e2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1b; ptr__in += delta1b;
+// }
+
+// ptr_t[2] += delta2; ptr_e2 += delta2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1f; ptr__in += delta1f;
+// }
+
+// ++ptr_t[2]; ++ptr_e2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1c; ptr__in += delta1c;
+// }
+
+// ptr_t[2] -= delta2; ptr_e2 -= delta2;
+// }
+
+// // bot right 1
+// ptr_t[3] += 1;
+// {
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1f; ptr__in += delta1f;
+// }
+
+// ++ptr_t[2]; ++ptr_e2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1b; ptr__in += delta1b;
+// }
+
+// ptr_t[2] += delta2; ptr_e2 += delta2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1f; ptr__in += delta1f;
+// }
+
+// ++ptr_t[2]; ++ptr_e2;
+// threshold = *ptr_t[*ptr_e2];
+// {
+// for (unsigned i = 1; i < s; ++i)
+// {
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+
+// *ptr__out = pid++;
+// ptr__out += delta1; ptr__in += delta1;
+// }
+
+// for (unsigned j = 1; j < s; ++j)
+// {
+// *ptr__out = pid++;
+// ++ptr__out; ++ptr__in;
+// }
+// *ptr__out = pid++;
+// ptr__out += delta1e; ptr__in += delta1e;
+// }
+// }
+
+// // bot right -> next top left
+// ptr_t[2] += delta2c; ptr_e2 += delta2c;
+// ptr_t[3] = ptr_t[3] - delta3;
+// ptr_t[4] += 1;
+// }
+
+// // eof -> next bof
+// ptr__out += eor1; ptr__in += eor1;
+// ptr_t[2] += eor2; ptr_e2 += eor2;
+// ptr_t[3] += eor3;
+// ptr_t[4] += eor4;
+// }
+
+
+// // mln::debug::println(out);
+
+// return out;
+// }
+
+
+
unsigned sub(unsigned nbr, unsigned down_scaling)
{
@@ -807,9 +1313,9 @@ namespace mln
const char *args_desc[][2] =
{
{ "input.pgm", "A graylevel image." },
- { "w", "Window size. (Common value: 51)" },
+ { "w", "Window size at scale 1. (Common value: 101)" },
{ "s", "First subsampling ratio (Common value: 2)." },
- { "min_area", "Minimum object area (relative to scale 2) (Common value: 200)" },
+ { "min_area", "Minimum object area (at scale 2) (Common value: 200)" },
{ "debug", "Display debug/bench data if set to 1" },
{0, 0}
};
@@ -838,12 +1344,14 @@ int main(int argc, char *argv[])
mln::debug::internal::filename_prefix = argv[1];
- // Window size.
- unsigned w = atoi(argv[2]);
-
// First subsampling scale.
unsigned s = atoi(argv[3]);
+ // Window size.
+ unsigned
+ w_1 = atoi(argv[2]), // Scale 1
+ w_work = w_1 / s; // Scale 2
+
// Number of subscales.
unsigned nb_subscale = 3;//atoi(argv[3]);
@@ -856,8 +1364,8 @@ int main(int argc, char *argv[])
mln::debug::quiet = ! atoi(argv[6]);
- if (mln::debug::quiet)
- std::cout << "Running Sauvola_ms with w = " << w
+ if (! mln::debug::quiet)
+ std::cout << "Running Sauvola_ms with w_1 = " << w_1
<< ", s = " << s
<< ", nb_subscale = " << nb_subscale
<< ", q = " << q
@@ -877,13 +1385,13 @@ int main(int argc, char *argv[])
io::pgm::load(input_full, argv[1]);
{
- unsigned max_dim = math::max(input_full.ncols() / 2,
- input_full.nrows() / 2);
- if (w > max_dim)
+ unsigned max_dim = math::max(input_full.ncols() / s,
+ input_full.nrows() / s);
+ if (w_work > max_dim)
{
std::cout << "------------------" << std::endl;
std::cout << "The window is too large! Image size is only "
- << input_full.nrows() << "x" << input_full.ncols()
+ << input_full.nrows() / s << "x" << input_full.ncols() / s
<< std::endl
<< "Window size must not exceed " << max_dim
<< std::endl;
@@ -927,7 +1435,7 @@ int main(int argc, char *argv[])
util::array<util::couple<box2d, unsigned> >
sub_domains = compute_sub_domains(input_full, nb_subscale, s);
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "adjusting input border to " << sub_domains(1).second()
<< std::endl;
@@ -937,15 +1445,16 @@ int main(int argc, char *argv[])
// mln::debug::println_with_border(input_full);
t_ = timer_;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "sub domains computed and adjust input border size - "
<< t_ << std::endl;
// Resize input and compute integral images.
timer_.restart();
- image2d<util::couple<double,double> > integral_sum_sum_2;
+ typedef image2d<util::couple<double,double> > integral_t;
+ integral_t integral_sum_sum_2;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "sub_domain(2).domain() == " << sub_domains(2).first() << std::endl;
sub_ima.append(scribo::subsampling::integral(input_full, s,
@@ -953,10 +1462,26 @@ int main(int argc, char *argv[])
sub_domains[2].first(),
sub_domains[2].second()));
+// {
+// io::pgm::save(sub_ima[2], "in_50p.pgm");
+// mln_piter_(integral_t) p(integral_sum_sum_2.domain());
+// for_all(p)
+// {
+// std::cout << integral_sum_sum_2(p).first() << ", ";
+// }
+// std::cout << std::endl << " ------- " << std::endl;
+
+// for_all(p)
+// {
+// std::cout << integral_sum_sum_2(p).second() << ", ";
+// }
+// std::cout << std::endl << " ------- " << std::endl;
+// }
+
// mln::debug::println(integral_sum_sum_2);
t_ = timer_;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "subsampling 1 -> 2 And integral images - " << t_
<< " - nsites = "
<< input_full.domain().nsites() << " -> "
@@ -972,7 +1497,7 @@ int main(int argc, char *argv[])
sub_domains[i].first(),
sub_domains[i].second()));
t_ = timer_;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "subsampling " << (i - 1) << " -> " << i
<< " - " << t_
<< " - nsites = "
@@ -995,10 +1520,11 @@ int main(int argc, char *argv[])
t_ima[i] = compute_t_n_and_e_2(sub_ima[i], e_2,
lambda_min / ratio,
mln_max(unsigned),
- q, i, w, integral_sum_sum_2);
+ s,
+ q, i, w_work, integral_sum_sum_2);
t_ = timer_;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "Scale " << i
<< " - 1/" << s * ratio
<< " compute t_n and update e - " << t_ << std::endl;
@@ -1013,10 +1539,11 @@ int main(int argc, char *argv[])
t_ima[i] = compute_t_n_and_e_2(sub_ima[i], e_2,
lambda_min / ratio,
lambda_max / ratio,
- q, i, w, integral_sum_sum_2);
+ s,
+ q, i, w_work, integral_sum_sum_2);
t_ = timer_;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "Scale " << i
<< " - 1/" << s * ratio
<< " compute t_n and update e - " << t_ << std::endl;
@@ -1027,16 +1554,16 @@ int main(int argc, char *argv[])
{
timer_.restart();
t_ima[2] = compute_t_n_and_e_2(sub_ima[2], e_2, 0, lambda_max,
- 1, 2, w, integral_sum_sum_2);
+ s, 1, 2, w_work, integral_sum_sum_2);
t_ = timer_;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "Scale " << 2
<< " - 1/" << s
<< " compute t_n and update e - " << t_ << std::endl;
}
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "--------" << std::endl;
// io::pgm::save(e_2, mln::debug::filename("e.pgm"));
@@ -1045,7 +1572,7 @@ int main(int argc, char *argv[])
timer_.restart();
e_2 = transform::influence_zone_geodesic(e_2, c8());
t_ = timer_;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "influence zone - " << t_ << std::endl;
@@ -1058,17 +1585,138 @@ int main(int argc, char *argv[])
// for (unsigned i = 2; i < t_ima.size(); ++i)
// io::pgm::save(t_ima[i], mln::debug::filename("t.pgm", i));
+// {
+// image2d<bool> out_2;
+// initialize(out_2, e_2);
+// mln_piter_(image2d<int_u8>) p(e_2.domain());
+// for_all(p)
+// {
+// out_2(p) = sub_ima[2](p) < t_ima[2](p);
+// }
+// io::pbm::save(out_2, argv[5]);
+// }
+
timer_.restart();
image2d<bool> out_new = binarize_generic(input_full, e_2, t_ima, s);
// image2d<bool> out_new = binarize(input_full, e_2, t_ima);
t_ = timer_;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "Compute bin - " << t_ << std::endl;
t_ = sauvola_timer_;
- if (mln::debug::quiet)
+ if (! mln::debug::quiet)
std::cout << "Sauvola : " << t_ << std::endl;
- io::pbm::save(out_new, argv[5]);
+
+ io::pbm::save(out_new, argv[5]);
+// abort();
}
+
+
+
+// int main(int argc, char *argv[])
+// {
+// using namespace mln;
+// using namespace scribo;
+// using value::rgb8;
+// using value::int_u8;
+// using value::int_u16;
+// using value::label_16;
+
+// typedef image2d<label_16> L;
+
+// unsigned s = atoi(argv[3]);
+
+
+// typedef image2d<value::int_u8> I;
+// dpoint2d none(0, 0);
+
+// I input_full(atoi(argv[1]),atoi(argv[2]));
+// // I input_full(30,20); // Cas pourri
+// // I input_full(30,24); // Cas 'row <<'
+// // I input_full(36,24); // Cas ideal
+// // I input_full(36,20); // Cas 'col <<'
+// mln::debug::iota(input_full);
+
+// mln::debug::println(input_full);
+
+
+// util::array<I> sub_ima;
+// util::array<I> t_ima;
+
+
+// // Make sure t_ima indexes start from 2.
+// {
+// I dummy(1,1);
+// for (unsigned i = 0; i < 3 + 2; ++i)
+// t_ima.append(dummy);
+// }
+
+// // Make sure sub_ima indexes start from 2.
+// {
+// I dummy(1,1);
+// sub_ima.append(dummy);
+// sub_ima.append(dummy);
+// }
+
+
+
+// util::array<util::couple<box2d, unsigned> >
+// sub_domains = compute_sub_domains(input_full, 3, s);
+
+// border::adjust(input_full, sub_domains(1).second());
+// border::mirror(input_full);
+
+// // Resize input and compute integral images.
+// typedef image2d<util::couple<double,double> > integral_t;
+// integral_t integral_sum_sum_2;
+
+// sub_ima.append(scribo::subsampling::integral(input_full, s,
+// integral_sum_sum_2,
+// sub_domains[2].first(),
+// sub_domains[2].second()));
+
+// std::cout << "input border = " << input_full.border() << std::endl;
+// std::cout << "subsampling 1 -> 2 And integral images - "
+// << " - nsites = "
+// << input_full.domain().nsites() << " -> "
+// << sub_ima[2].domain().nsites() << " - "
+// << input_full.domain() << " -> "
+// << sub_ima[2].domain() << std::endl;
+
+
+// for (unsigned i = 3; i <= 3 + 1; ++i)
+// {
+// sub_ima.append(mln::subsampling::antialiased(sub_ima[i - 1], 2, none,
+// sub_domains[i].first(),
+// sub_domains[i].second()));
+// std::cout << "subsampling " << (i - 1) << " -> " << i
+// << " - "
+// << " - nsites = "
+// << sub_ima[i].domain().nsites() << " - "
+// << sub_ima[i].domain()
+// << std::endl;
+// t_ima[i] = I(sub_ima[i].domain());
+// }
+
+
+
+
+
+// image2d<int_u8> e_2;
+// initialize(e_2, sub_ima[2]);
+// data::fill(e_2, 2);
+
+// data::fill(t_ima[2], 30);
+
+// image2d<unsigned> out_new = binarize_generic_debug(input_full, e_2, t_ima, s);
+
+// mln::debug::println_with_border(out_new);
+// // io::pgm::save(out_new, "out.pgm");
+
+// std::cout << "------------" << std::endl;
+
+// // out_new = binarize_generic_debug(input_full, e_2, t_ima, 2);
+// // mln::debug::println(out_new);
+// }
diff --git a/scribo/subsampling/integral_single_image.hh b/scribo/subsampling/integral_single_image.hh
index 07b391d..6ed1cc6 100644
--- a/scribo/subsampling/integral_single_image.hh
+++ b/scribo/subsampling/integral_single_image.hh
@@ -107,7 +107,6 @@ namespace scribo
const I& input = exact(input_);
J& integral_sum_sum_2 = exact(integral_sum_sum_2_);
- const unsigned area = scale * scale;
mln_precondition(input.is_valid());
mln_precondition(input.domain().pmin() == literal::origin);
@@ -142,19 +141,22 @@ namespace scribo
const V* ptr3 = & input.at_(row + 2, 0);
for (unsigned col = 0; col < ncols; col += scale)
{
- S sum;
- sum = *ptr1 + *(ptr1 + 1) + *(ptr1 + 2);
- sum += *ptr2 + *(ptr2 + 1) + *(ptr2 + 2);
- sum += *ptr3 + *(ptr3 + 1) + *(ptr3 + 2);
+ V v11 = *ptr1, v12 = *(ptr1 + 1), v13 = *(ptr1 + 2),
+ v21 = *ptr2, v22 = *(ptr2 + 1), v23 = *(ptr2 + 2),
+ v31 = *ptr3, v32 = *(ptr3 + 1), v33 = *(ptr3 + 2);
ptr1 += 3;
ptr2 += 3;
ptr3 += 3;
+ S local_sum = v11 + v12 + v13
+ + v21 + v22 + v23
+ + v31 + v32 + v33,
+ local_sum_2 = v11*v11 + v12*v12 + v13*v13
+ + v21*v21 + v22*v22 + v23*v23
+ + v31*v31 + v32*v32 + v33*v33;
- S val = sum / area;
- *p_sub++ = val;
-
- h_sum += val;
- h_sum_2 += val * val;
+ *p_sub++ = local_sum / 9;
+ h_sum += local_sum;
+ h_sum_2 += local_sum_2;
// exception
p_integ->first() = h_sum;
@@ -172,24 +174,27 @@ namespace scribo
for (row += scale; row < nrows; row += scale)
{
S h_sum = 0, h_sum_2 = 0;
- const V* ptr1 = & input.at_(row, 0);
+ const V* ptr1 = & input.at_(row, 0);
const V* ptr2 = & input.at_(row + 1, 0);
const V* ptr3 = & input.at_(row + 2, 0);
for (unsigned col = 0; col < ncols; col += scale)
{
- S sum;
- sum = *ptr1 + *(ptr1 + 1) + *(ptr1 + 2);
- sum += *ptr2 + *(ptr2 + 1) + *(ptr2 + 2);
- sum += *ptr3 + *(ptr3 + 1) + *(ptr3 + 2);
+ V v11 = *ptr1, v12 = *(ptr1 + 1), v13 = *(ptr1 + 2),
+ v21 = *ptr2, v22 = *(ptr2 + 1), v23 = *(ptr2 + 2),
+ v31 = *ptr3, v32 = *(ptr3 + 1), v33 = *(ptr3 + 2);
ptr1 += 3;
ptr2 += 3;
ptr3 += 3;
+ S local_sum = v11 + v12 + v13
+ + v21 + v22 + v23
+ + v31 + v32 + v33,
+ local_sum_2 = v11*v11 + v12*v12 + v13*v13
+ + v21*v21 + v22*v22 + v23*v23
+ + v31*v31 + v32*v32 + v33*v33;
- S val = sum / area;
- *p_sub++ = val;
-
- h_sum += val;
- h_sum_2 += val * val;
+ *p_sub++ = local_sum / 9;
+ h_sum += local_sum;
+ h_sum_2 += local_sum_2;
p_integ->first() = h_sum + (p_integ + up)->first();
p_integ->second() = h_sum_2 + (p_integ + up)->second();
@@ -220,7 +225,6 @@ namespace scribo
const I& input = exact(input_);
J& integral_sum_sum_2 = exact(integral_sum_sum_2_);
- const unsigned area = scale * scale;
typedef mln_value(I) V;
typedef mln_sum(V) S;
@@ -257,6 +261,7 @@ namespace scribo
const V* ptr2 = & input.at_(row + 1, 0);
for (unsigned col = 0; col < ncols; col += scale)
{
+/*
S sum;
sum = *ptr1 + *(ptr1 + 1);
sum += *ptr2 + *(ptr2 + 1);
@@ -268,6 +273,22 @@ namespace scribo
h_sum += val;
h_sum_2 += val * val;
+*/
+
+ // NEW:
+
+ V v11 = *ptr1, v12 = *(ptr1 + 1),
+ v21 = *ptr2, v22 = *(ptr2 + 1);
+ ptr1 += 2;
+ ptr2 += 2;
+ S local_sum = v11 + v12 + v21 + v22,
+ local_sum_2 = v11*v11 + v12*v12 + v21*v21 + v22*v22;
+ *p_sub++ = local_sum / 4;
+ h_sum += local_sum;
+ h_sum_2 += local_sum_2;
+
+ // end of NEW.
+
// exception
p_integ->first() = h_sum;
@@ -289,6 +310,29 @@ namespace scribo
const V* ptr2 = & input.at_(row + 1, 0);
for (unsigned col = 0; col < ncols; col += scale)
{
+ // NEW:
+
+ V v11 = *ptr1, v12 = *(ptr1 + 1),
+ v21 = *ptr2, v22 = *(ptr2 + 1);
+ ptr1 += 2;
+ ptr2 += 2;
+ S local_sum = v11 + v12 + v21 + v22,
+ local_sum_2 = v11*v11 + v12*v12 + v21*v21 + v22*v22;
+ *p_sub++ = local_sum / 4;
+ h_sum += local_sum;
+ h_sum_2 += local_sum_2;
+
+ // end of NEW.
+
+
+ /*
+
+ // To get the strict equivalent to the integral image
+ // computed at working scale (scale (2)), we need the code
+ // below. In addition, the integral_browsing shall call
+ // the threshold formula with (..size..) and NOT with
+ // (..size * s_2..).
+
S sum;
sum = *ptr1 + *(ptr1 + 1);
sum += *ptr2 + *(ptr2 + 1);
@@ -297,10 +341,22 @@ namespace scribo
S val = sum / area;
*p_sub++ = val;
-
h_sum += val;
h_sum_2 += val * val;
+ */
+
+
+ // Never write something like this:
+ // *p_sub++ = sum / area;
+ // h_sum += sum;
+ // h_sum_2 += sum * sum;
+ // because the product 'sum * sum' is not
+ // equivalent to the sum of the value^2. E.g.
+ // we have (v1 + v2 + v3 + v4)^2 + etc. instead
+ // of having the correct sum_2 being v1^2 + v2^2 etc.
+
+
p_integ->first() = h_sum + (p_integ + up)->first();
p_integ->second() = h_sum_2 + (p_integ + up)->second();
--
1.5.6.5
1
0
last-svn-commit-21-g495dd2d Add hooks for subclasses in labeled_image_base.
by Guillaume Lazzara 11 Mar '10
by Guillaume Lazzara 11 Mar '10
11 Mar '10
* mln/core/internal/labeled_image_base.hh: New methods which can
be overridden in subclasses.
* mln/core/image/imorph/labeled_image.hh: Add a missing header.
---
milena/ChangeLog | 9 +++++++
milena/mln/core/image/imorph/labeled_image.hh | 2 +
milena/mln/core/internal/labeled_image_base.hh | 29 ++++++++++++++++++++++++
3 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index bcaf644..39c2d80 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,12 @@
+2009-12-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add hooks for subclasses in labeled_image_base.
+
+ * mln/core/internal/labeled_image_base.hh: New methods which can
+ be overridden in subclasses.
+
+ * mln/core/image/imorph/labeled_image.hh: Add a missing header.
+
2010-03-11 Guillaume Lazzara <z(a)lrde.epita.fr>
* mln/draw/dashed_line.hh: New draw line routine.
diff --git a/milena/mln/core/image/imorph/labeled_image.hh b/milena/mln/core/image/imorph/labeled_image.hh
index 438f6ae..fc151e8 100644
--- a/milena/mln/core/image/imorph/labeled_image.hh
+++ b/milena/mln/core/image/imorph/labeled_image.hh
@@ -34,6 +34,8 @@
# include <mln/core/routine/duplicate.hh>
+# include <mln/data/compute.hh>
+
# include <mln/util/array.hh>
# include <mln/accu/center.hh>
diff --git a/milena/mln/core/internal/labeled_image_base.hh b/milena/mln/core/internal/labeled_image_base.hh
index e79bb12..9e2d314 100644
--- a/milena/mln/core/internal/labeled_image_base.hh
+++ b/milena/mln/core/internal/labeled_image_base.hh
@@ -168,7 +168,13 @@ namespace mln
template <typename F>
void relabel_(const Function_v2b<F>& f);
+ /// Called during relabeling.
+ /// @{
+ void init_update_data_();
+ void prepare_update_data_(const mln_value(I)& lbl,
+ const mln_value(I)& new_lbl);
void update_data_(const fun::i2v::array<mln_value(I)>& relabel_fun);
+ /// @}
};
@@ -275,9 +281,14 @@ namespace mln
util::array<accu::shape::bbox<mln_psite(I)> >
new_bboxes(static_cast<unsigned>(this->data_->nlabels_) + 1);
+ exact(this)->init_update_data_();
+
for (unsigned i = 1; i < this->data_->bboxes_.size(); ++i)
if (relabel_fun(i) != 0)
+ {
new_bboxes[relabel_fun(i)].take(this->data_->bboxes_[i]);
+ exact(this)->prepare_update_data_(i, relabel_fun(i));
+ }
convert::from_to(new_bboxes, this->data_->bboxes_);
@@ -341,6 +352,24 @@ namespace mln
// No-Op.
}
+ template <typename I, typename E>
+ void
+ labeled_image_base<I,E>::prepare_update_data_(const mln_value(I)& lbl,
+ const mln_value(I)& new_lbl)
+ {
+ (void) lbl;
+ (void) new_lbl;
+ // No-Op.
+ }
+
+ template <typename I, typename E>
+ void
+ labeled_image_base<I,E>::init_update_data_()
+ {
+ // No-Op.
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
--
1.5.6.5
1
0
11 Mar '10
* mln/subsampling/antialiased.hh: New.
---
milena/ChangeLog | 6 +
milena/mln/subsampling/antialiased.hh | 421 +++++++++++++++++++++++++++++++++
2 files changed, 427 insertions(+), 0 deletions(-)
create mode 100644 milena/mln/subsampling/antialiased.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 39c2d80..c2335e8 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,11 @@
2009-12-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add an antialiased subsampling.
+
+ * mln/subsampling/antialiased.hh: New.
+
+2009-12-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add hooks for subclasses in labeled_image_base.
* mln/core/internal/labeled_image_base.hh: New methods which can
diff --git a/milena/mln/subsampling/antialiased.hh b/milena/mln/subsampling/antialiased.hh
new file mode 100644
index 0000000..ccb947e
--- /dev/null
+++ b/milena/mln/subsampling/antialiased.hh
@@ -0,0 +1,421 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef MLN_SUBSAMPLING_ANTIALIASED_HH
+# define MLN_SUBSAMPLING_ANTIALIASED_HH
+
+/// \file
+///
+/// Antialiased subsampling.
+
+/// \fixme: shift is not used for the moment......
+
+#include <mln/core/concept/image.hh>
+#include <mln/border/thickness.hh>
+
+
+namespace mln
+{
+
+ namespace subsampling
+ {
+
+ /*! FIXME: Doc.
+ */
+ template <typename I>
+ inline
+ mln_concrete(I)
+ antialiased(const Image<I>& input,
+ unsigned gap,
+ const mln_deduce(I, site, delta)& shift,
+ const mln_domain(I)& output_domain,
+ unsigned border_thickness);
+
+
+ /*! \overload
+ */
+ template <typename I>
+ mln_concrete(I)
+ antialiased(const Image<I>& input,
+ unsigned gap,
+ const mln_deduce(I, site, delta)& shift); // FIXME: Add round_up_size.
+
+
+ /*! \overload
+ */
+ template <typename I>
+ mln_concrete(I)
+ antialiased(const Image<I>& input, unsigned gap);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // Tests
+
+ namespace internal
+ {
+
+ template <typename I>
+ inline
+ void
+ antialiased_tests(const Image<I>& input,
+ unsigned gap,
+ const mln_deduce(I, site, delta)& shift,
+ const mln_domain(I)& output_domain,
+ unsigned border_thickness)
+ {
+ typedef mln_site(I) P;
+
+ mlc_is_a(mln_domain(I), Box)::check();
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(exact(input).domain().pmin() == literal::origin);
+ mln_precondition(gap > 1);
+ for (unsigned i = 0; i < P::dim; ++i)
+ mln_precondition(shift[i] < static_cast<int>(gap));
+
+ (void) input;
+ (void) gap;
+ (void) shift;
+ (void) output_domain;
+ (void) border_thickness;
+ }
+
+
+ } // end of namespace mln::subsampling::internal
+
+
+
+
+ // Implementations.
+
+ namespace impl
+ {
+
+ namespace generic
+ {
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ antialiased(const Image<I>& input_,
+ unsigned gap,
+ const mln_deduce(I, site, delta)& shift,
+ const mln_domain(I)& output_domain,
+ unsigned border_thickness)
+ {
+ // To be written...
+ mlc_abort(I)::check();
+
+ mln_concrete(I) output;
+ return output;
+ }
+
+ } // end of namespace mln::subsampling::impl::generic
+
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ antialiased_2d_antialias_fastest_2(const Image<I>& input_,
+ const mln_deduce(I, site, delta)& shift,
+ const mln_domain(I)& output_domain,
+ unsigned border_thickness)
+ {
+ trace::entering("subsampling::impl::antialiased_2d_antialias_fastest_2");
+
+ internal::antialiased_tests(input_, 2, shift,
+ output_domain, border_thickness);
+
+ const I& input = exact(input_);
+
+ typedef mln_value(I) V;
+ typedef mln_sum(V) S;
+
+ typedef mln_site(I) P;
+ box<P> b = output_domain;
+ if (!b.is_valid())
+ {
+ P pmin = input.domain().pmin() / 2,
+ pmax = input.domain().pmax() / 2;
+ b = box<P>(pmin, pmax);
+ }
+
+ typedef mln_concrete(I) O;
+ O output(b, border_thickness);
+
+ const V* ptr1 = & input.at_(0, 0);
+ const V* ptr2 = & input.at_(1, 0);
+
+ mln_box_runstart_piter(O) s(output.domain());
+ const unsigned n = s.run_length();
+
+ unsigned offset = input.delta_index(point2d(2,0) - point2d(0,2*n));
+
+ for_all(s)
+ {
+ mln_value(O)* po = & output(s);
+ for (unsigned i = 0; i < n; ++i)
+ {
+ S s;
+ s = *ptr1 + *(ptr1 + 1);
+ s += *ptr2 + *(ptr2 + 1);
+ ptr1 += 2;
+ ptr2 += 2;
+
+ *po++ = (s + 2) / 4;
+ }
+ ptr1 += offset;
+ ptr2 += offset;
+ }
+
+ trace::exiting("subsampling::impl::antialiased_2d_antialias_fastest_2");
+ return output;
+ }
+
+
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ antialiased_2d_antialias_fastest_3(const Image<I>& input_,
+ const mln_deduce(I, site, delta)& shift,
+ const mln_domain(I)& output_domain,
+ unsigned border_thickness)
+ {
+ trace::entering("subsampling::impl::antialiased_2d_antialias_fastest_3");
+
+ internal::antialiased_tests(input_, 3, shift,
+ output_domain, border_thickness);
+
+ const I& input = exact(input_);
+
+ typedef mln_value(I) V;
+ typedef mln_sum(V) S;
+
+ typedef mln_site(I) P;
+ box<P> b = output_domain;
+ if (!b.is_valid())
+ {
+ P pmin = input.domain().pmin() / 3,
+ pmax = input.domain().pmax() / 3;
+ b = box<P>(pmin, pmax);
+ }
+ typedef mln_concrete(I) O;
+ O output(b, border_thickness);
+
+ const V* ptr1 = & input.at_(0, 0);
+ const V* ptr2 = & input.at_(1, 0);
+ const V* ptr3 = & input.at_(2, 0);
+
+ mln_box_runstart_piter(O) s(output.domain());
+ const unsigned n = s.run_length();
+
+ unsigned offset = input.delta_index(point2d(3,0) - point2d(0,3*n));
+
+ for_all(s)
+ {
+ mln_value(O)* po = & output(s);
+ for (unsigned i = 0; i < n; ++i)
+ {
+ S s;
+ s = *ptr1 + *(ptr1 + 1) + *(ptr1 + 2);
+ s += *ptr2 + *(ptr2 + 1) + *(ptr2 + 2);
+ s += *ptr3 + *(ptr3 + 1) + *(ptr3 + 2);
+ ptr1 += 3;
+ ptr2 += 3;
+ ptr3 += 3;
+
+ *po++ = (s + 4) / 9;
+ }
+ ptr1 += offset;
+ ptr2 += offset;
+ ptr3 += offset;
+ }
+
+ trace::exiting("subsampling::impl::antialiased_2d_antialias_fastest_3");
+ return output;
+ }
+
+
+
+ } // end of namespace mln::subsampling::impl
+
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <unsigned dim, typename I>
+ inline
+ mln_concrete(I)
+ antialiased_dispatch(trait::image::value_alignment::any,
+ trait::image::value_storage::any,
+ trait::image::value_access::any,
+ const Image<I>& input,
+ unsigned gap,
+ const mln_deduce(I, site, delta)& shift,
+ const mln_domain(I)& output_domain,
+ unsigned border_thickness)
+ {
+ // Not implemented yet.
+ mlc_abort(I)::check();
+ }
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ antialiased_2d_antialias_fastest_dispatch(
+ const Image<I>& input,
+ unsigned gap,
+ const mln_deduce(I, site, delta)& shift,
+ const mln_domain(I)& output_domain,
+ unsigned border_thickness)
+ {
+ if (gap == 2)
+ return impl::antialiased_2d_antialias_fastest_2(input, shift,
+ output_domain,
+ border_thickness);
+ else if (gap == 3)
+ return impl::antialiased_2d_antialias_fastest_3(input, shift,
+ output_domain,
+ border_thickness);
+ else
+ trace::warning("Not implemented yet!");
+
+ mln_concrete(I) output;
+ return output;
+ }
+
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ antialiased_dispatch_2d(trait::image::value_alignment::with_grid,
+ trait::image::value_storage::one_block,
+ trait::image::value_access::direct,
+ const Image<I>& input,
+ unsigned gap,
+ const mln_deduce(I, site, delta)& shift,
+ const mln_domain(I)& output_domain,
+ unsigned border_thickness)
+ {
+ return antialiased_2d_antialias_fastest_dispatch(input, gap,
+ shift,
+ output_domain,
+ border_thickness);
+ }
+
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ antialiased_dispatch(const Image<I>& input,
+ unsigned gap,
+ const mln_deduce(I, site, delta)& shift,
+ const mln_domain(I)& output_domain,
+ unsigned border_thickness)
+ {
+ unsigned dim = mln_site_(I)::dim;
+
+ if (dim == 2)
+ return antialiased_dispatch_2d(
+ mln_trait_image_value_alignment(I)(),
+ mln_trait_image_value_storage(I)(),
+ mln_trait_image_value_access(I)(),
+ input,
+ gap,
+ shift,
+ output_domain,
+ border_thickness);
+ else
+ trace::warning("Not implemented yet.");
+
+ mln_concrete(I) output;
+ return output;
+ }
+
+ } // end of namespace mln::subsampling::internal
+
+
+
+ // Facades.
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ antialiased(const Image<I>& input,
+ unsigned gap,
+ const mln_deduce(I, site, delta)& shift,
+ const mln_domain(I)& output_domain,
+ unsigned border_thickness)
+ {
+ trace::entering("subsampling::antialiased");
+
+ typedef mln_site(I) P;
+
+ internal::antialiased_tests(input, gap, shift,
+ output_domain, border_thickness);
+
+ mln_concrete(I) output;
+ output = internal::antialiased_dispatch(input, gap, shift,
+ output_domain, border_thickness);
+
+ trace::exiting("subsampling::antialiased");
+ return output;
+ }
+
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ antialiased(const Image<I>& input,
+ unsigned gap,
+ const mln_deduce(I, site, delta)& shift)
+ {
+ mln_domain(I) domain;
+ return antialiased(input, gap, shift, domain, border::thickness);
+ }
+
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ antialiased(const Image<I>& input, unsigned gap)
+ {
+ return antialiased(input, gap, literal::zero);
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::subsampling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_SUBSAMPLING_ANTIALIASED_HH
--
1.5.6.5
1
0
* mln/fun/v2v/all.hh: Include the new header.
* mln/fun/v2v/rgb_to_int_u.hh: New.
---
milena/ChangeLog | 8 +++++
milena/mln/fun/v2v/all.hh | 1 +
milena/mln/fun/v2v/{id.hh => rgb_to_int_u.hh} | 38 ++++++++----------------
3 files changed, 22 insertions(+), 25 deletions(-)
copy milena/mln/fun/v2v/{id.hh => rgb_to_int_u.hh} (72%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index c2335e8..73b9647 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,13 @@
2009-12-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add rbg_to_int_u function.
+
+ * mln/fun/v2v/all.hh: Include the new header.
+
+ * mln/fun/v2v/rgb_to_int_u.hh: New.
+
+2009-12-14 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add an antialiased subsampling.
* mln/subsampling/antialiased.hh: New.
diff --git a/milena/mln/fun/v2v/all.hh b/milena/mln/fun/v2v/all.hh
index 425d24e..2c455a5 100644
--- a/milena/mln/fun/v2v/all.hh
+++ b/milena/mln/fun/v2v/all.hh
@@ -60,6 +60,7 @@ namespace mln
# include <mln/fun/v2v/linear.hh>
# include <mln/fun/v2v/norm.hh>
# include <mln/fun/v2v/projection.hh>
+# include <mln/fun/v2v/rgb_to_int_u.hh>
//<<lrde
# include <mln/fun/v2v/rgb_to_hsi.hh>
# include <mln/fun/v2v/rgb_to_hsl.hh>
diff --git a/milena/mln/fun/v2v/id.hh b/milena/mln/fun/v2v/rgb_to_int_u.hh
similarity index 72%
copy from milena/mln/fun/v2v/id.hh
copy to milena/mln/fun/v2v/rgb_to_int_u.hh
index 21398c7..d04dbf0 100644
--- a/milena/mln/fun/v2v/id.hh
+++ b/milena/mln/fun/v2v/rgb_to_int_u.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,16 +23,9 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_FUN_V2V_ID_HH
-# define MLN_FUN_V2V_ID_HH
-
-/*! \file
- *
- * \brief Identity function.
- */
-
-# include <mln/fun/internal/selector.hh>
+#ifndef MLN_FUN_V2V_RGB_TO_INT_U_HH
+# define MLN_FUN_V2V_RGB_TO_INT_U_HH
namespace mln
{
@@ -43,25 +36,21 @@ namespace mln
namespace v2v
{
- // FIXME: Doc!
-
- template <typename T>
- struct id
- : fun::internal::selector_<T, T, id<T> >::ret
+ template <unsigned n>
+ struct rgb_to_int_u : Function_v2v< rgb_to_int_u<n> >
{
- typedef T result;
- T operator()(const T& t) const;
- };
+ typedef value::int_u<n> result;
+ result operator()(const value::rgb<n>& c) const;
+ };
# ifndef MLN_INCLUDE_ONLY
- template <typename T>
- inline
- T
- id<T>::operator()(const T& t) const
+ template <unsigned n>
+ typename rgb_to_int_u<n>::result
+ rgb_to_int_u<n>::operator()(const value::rgb<n>& c) const
{
- return t;
+ return (c.red() + c.green() + c.blue()) / 3;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -72,5 +61,4 @@ namespace mln
} // end of namespace mln
-
-#endif // ! MLN_FUN_V2V_ID_HH
+#endif // ! MLN_FUN_V2V_RGB_TO_INT_U_HH
--
1.5.6.5
1
0