* icdar/2009/hsc/clean_lines.hh: new routine.
* icdar/2009/hsc/input_lines_to_lines.cc: use this new routine.
---
milena/sandbox/ChangeLog | 7 ++
milena/sandbox/icdar/2009/hsc/clean_lines.hh | 72 ++++++++++++++++++++
.../sandbox/icdar/2009/hsc/input_lines_to_lines.cc | 23 +------
3 files changed, 81 insertions(+), 21 deletions(-)
create mode 100644 milena/sandbox/icdar/2009/hsc/clean_lines.hh
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 681b6bf..2d8698f 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,3 +1,10 @@
+2009-04-08 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add clean_lines routine.
+
+ * icdar/2009/hsc/clean_lines.hh: new routine.
+ * icdar/2009/hsc/input_lines_to_lines.cc: use this new routine.
+
2009-04-07 Guillaume Lazzara <z(a)lrde.epita.fr>
Add icdar2ppm.
diff --git a/milena/sandbox/icdar/2009/hsc/clean_lines.hh
b/milena/sandbox/icdar/2009/hsc/clean_lines.hh
new file mode 100644
index 0000000..956c150
--- /dev/null
+++ b/milena/sandbox/icdar/2009/hsc/clean_lines.hh
@@ -0,0 +1,72 @@
+#ifndef CLEAN_LINES_HH
+# define CLEAN_LINES_HH
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/labeling/background.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/value/label_8.hh>
+#include <mln/value/label_16.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pgm/all.hh>
+#include <mln/labeling/compute.hh>
+#include <mln/pw/all.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/data/fill.hh>
+#include "label_maj.hh"
+
+
+namespace mln
+{
+
+ template <typename I, typename L>
+ mln_concrete(L)
+ clean_lines(const Image<I>& input, const Image<L>& lines_,
+ float maj_threshold);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename L>
+ mln_concrete(L)
+ clean_lines(const Image<I>& input, const Image<L>& lines_,
+ float maj_threshold)
+ {
+ trace::entering("clean_lines");
+
+ const L& lines = exact(lines_);
+ mln_precondition(lines.is_valid());
+ typedef value::label_16 LV;
+
+ LV nlabels;
+ mln_ch_value(L,LV) lbl = labeling::background(input, c8(), nlabels);
+ util::array<box<mln_site(L)> > bboxes =
labeling::compute(accu::meta::bbox(), lbl, nlabels);
+
+ /// Compute the most represented label for each component.
+ accu::label_maj<LV, mln_value(L)> accu(nlabels.next());
+ mln_piter(image2d<mln_value(L)>) p(lbl.domain());
+ for_all(p)
+ if (lines(p) != 0u)
+ accu.take(lbl(p), lines(p));
+
+ mln_concrete(L) output = duplicate(lines);
+
+ // Rebuild components.
+ util::array<util::couple<mln_value(L), float> > res = accu.to_result();
+ for (unsigned i = 1; i < res.nelements(); ++i)
+ if (res[i].second() >= maj_threshold)
+ data::fill(((output | bboxes[i]).rw()
+ | (pw::value(lbl) != pw::cst(literal::zero))).rw(),
+ res[i].first());
+// else
+// std::cout << res[i].first() << " - " << res[i].second()
<< std::endl;
+
+ trace::exiting("clean_lines");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+#endif // CLEAN_LINES_HH
diff --git a/milena/sandbox/icdar/2009/hsc/input_lines_to_lines.cc
b/milena/sandbox/icdar/2009/hsc/input_lines_to_lines.cc
index 56aafab..18f7d3a 100644
--- a/milena/sandbox/icdar/2009/hsc/input_lines_to_lines.cc
+++ b/milena/sandbox/icdar/2009/hsc/input_lines_to_lines.cc
@@ -11,6 +11,7 @@
#include <mln/core/image/image_if.hh>
#include <mln/data/fill.hh>
#include "label_maj.hh"
+#include "clean_lines.hh"
void usage(char* argv[])
{
@@ -40,26 +41,6 @@ int main(int argc, char *argv[])
image2d<int_u8> lines;
io::pgm::load(lines, argv[2]);
- label_16 nlabels;
- image2d<label_16> lbl = labeling::background(input, c8(), nlabels);
- util::array<box2d> bboxes = labeling::compute(accu::meta::bbox(), lbl, nlabels);
-
- /// Compute the most represented label for each component.
- accu::label_maj<label_16, int_u8> accu(nlabels.next());
- mln_piter_(image2d<int_u8>) p(lbl.domain());
- for_all(p)
- if (lines(p) != 0u)
- accu.take(lbl(p), lines(p));
-
-
- // Rebuild components.
- util::array<util::couple<int_u8, float> > res = accu.to_result();
- for (unsigned i = 1; i < res.nelements(); ++i)
- if (res[i].second() >= 0.70f)
- data::fill(((lines | bboxes[i]).rw() | (pw::value(lbl) != 0u)).rw(),
res[i].first());
- else
- std::cout << res[i].first() << " - " << res[i].second()
<< std::endl;
-
// Save result.
- io::pgm::save(lines, argv[3]);
+ io::pgm::save(clean_lines(input, lines, 0.7f), argv[3]);
}
--
1.5.6.5
Show replies by date