
Add a small tool to map text components to lines. * icdar/2009/hsc/input_lines_to_lines.cc: new. --- milena/sandbox/ChangeLog | 6 ++ .../sandbox/icdar/2009/hsc/input_lines_to_lines.cc | 63 ++++++++++++++++++++ 2 files changed, 69 insertions(+), 0 deletions(-) create mode 100644 milena/sandbox/icdar/2009/hsc/input_lines_to_lines.cc diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog index f1350d6..f6e6e15 100644 --- a/milena/sandbox/ChangeLog +++ b/milena/sandbox/ChangeLog @@ -1,3 +1,9 @@ +2009-04-06 Guillaume Lazzara <z@lrde.epita.fr> + + Add a small tool to map text components to lines. + + * icdar/2009/hsc/input_lines_to_lines.cc: new. + 2009-04-06 Edwin Carlinet <carlinet@lrde.epita.fr> Add function to perform component tree computation until. diff --git a/milena/sandbox/icdar/2009/hsc/input_lines_to_lines.cc b/milena/sandbox/icdar/2009/hsc/input_lines_to_lines.cc new file mode 100644 index 0000000..eb46b36 --- /dev/null +++ b/milena/sandbox/icdar/2009/hsc/input_lines_to_lines.cc @@ -0,0 +1,63 @@ +#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/accu/lbl_maj.hh> +#include <mln/labeling/compute.hh> +#include <mln/pw/all.hh> +#include <mln/core/image/image_if.hh> +#include <mln/data/fill.hh> + +void usage(char* argv[]) +{ + std::cerr << "usage: " << argv[0] << " input.pbm lines.pgm output.pgm" << std::endl + << " HSC @ ICDAR'2009" << std::endl + << " Rebuild splitted components from a label image." << std::endl; + << " input.pbm: input 2D binary image (text is black; background is white)" << std::endl + << " lines.pgm: output image where line components are labeled (int_u8)" << std::endl + << " 0 is the background label." << std::endl + << " output.pgm output image where line components are labeled (int_u8)" << std::endl + << " 0 is the background label." << std::endl; + std::abort(); +} + + +int main(int argc, char *argv[]) +{ + using namespace mln; + using namespace mln::value; + + if (argc < 4) + usage(argv); + + image2d<bool> input; + io::pbm::load(input, argv[1]); + + 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::lbl_maj<label_16, int_u8> accu(nlabels.next()); + mln_piter_(image2d<int_u8>) p(lines.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.9f) + data::fill(((lines | bboxes[i]).rw() | (pw::value(lbl) != 0u)).rw(), res[i].first()); + + // Save result. + io::pgm::save(lines, argv[3]); +} -- 1.5.6.5