show_separators.cc 2.85 KB
Newer Older
Guillaume Lazzara's avatar
Guillaume Lazzara committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena.  If not, see <http://www.gnu.org/licenses/>.

#include <mln/core/image/image2d.hh>
#include <mln/core/alias/box2d.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/io/pbm/all.hh>
21
#include <mln/io/ppm/save.hh>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
22
23
#include <mln/arith/plus.hh>
#include <mln/labeling/foreground.hh>
24
#include <mln/labeling/compute.hh>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
25
26
27
28

#include <scribo/primitive/extract/lines_h_pattern.hh>
#include <scribo/primitive/extract/lines_v_pattern.hh>
#include <scribo/debug/usage.hh>
29
#include <scribo/debug/bboxes_image.hh>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77


const char *args_desc[][2] =
{
  { "length", "   Minimum line length. (default: 101)" },
  { "delta", "    Distance between the object pixel and the background pixel"
    "(default: 4)" },
  {0, 0}
};


int main(int argc, char *argv[])
{
  using namespace mln;

  if (argc != 7 && argc != 5)
    return scribo::debug::usage(argv,
				"Extract horizontal and vertical lines patterns",
				"input.pbm output.pbm input_wo_seps.pbm output.ppm length delta",
				args_desc);

  trace::entering("main");

  image2d<bool> input;
  io::pbm::load(input, argv[1]);

  // Set default option value
  unsigned
    length = 101,
    delta = 4;
  if (argc > 5)
  {
    length = atoi(argv[5]);
    delta = atoi(argv[6]);
  }

  util::timer t;
  t.start();

  image2d<bool>
    h_lines = scribo::primitive::extract::lines_h_pattern(input, length, delta);

  image2d<bool>
    v_lines = scribo::primitive::extract::lines_v_pattern(input, length, delta);

  v_lines += h_lines;

  t.stop();
78
79
80
81
  /* FIXME: Help the compiler to ``unproxy' the float stored in the
     timer.  There is a problem with an overload resolution of
     `mln::unproxy_rec' here.  */
  std::cout << t.read() << "s" << std::endl;
Guillaume Lazzara's avatar
Guillaume Lazzara committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

  // Save binary image.
  io::pbm::save(v_lines, argv[2]);

  // Save input without separators
  {
    image2d<bool> in_wo_seps = duplicate(input);
    data::fill((in_wo_seps | pw::value(v_lines)).rw(), false);
    io::pbm::save(in_wo_seps, argv[3]);
  }

  // Save bbox image
  value::int_u8 nlabels;
  image2d<value::int_u8> lbl = labeling::foreground(v_lines, c4(), nlabels);
  mln::util::array<box2d>
    bbox = labeling::compute(accu::shape::bbox<point2d>(), lbl, nlabels);
98
  io::ppm::save(scribo::debug::bboxes_image(input, bbox, literal::red), argv[4]);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
99
100
101

  trace::exiting("main");
}