* src/extract/primitive/Makefile.am: Add new examples.
* src/extract/primitive/find_discontinued_lines.cc: Cleanup.
* src/extract/primitive/find_single_lines.cc,
* src/extract/primitive/find_thick_lines.cc: New.
---
scribo/ChangeLog | 11 +++
scribo/src/extract/primitive/Makefile.am | 6 ++-
.../extract/primitive/find_discontinued_lines.cc | 23 +++----
..._discontinued_lines.cc => find_single_lines.cc} | 52 +++++++++-----
...d_discontinued_lines.cc => find_thick_lines.cc} | 76 ++++++++++++++-----
5 files changed, 115 insertions(+), 53 deletions(-)
copy scribo/src/extract/primitive/{find_discontinued_lines.cc => find_single_lines.cc}
(59%)
copy scribo/src/extract/primitive/{find_discontinued_lines.cc => find_thick_lines.cc}
(51%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index a1ffa34..0fd3083 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,16 @@
2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add/improve line extraction examples.
+
+ * src/extract/primitive/Makefile.am: Add new examples.
+
+ * src/extract/primitive/find_discontinued_lines.cc: Cleanup.
+
+ * src/extract/primitive/find_single_lines.cc,
+ * src/extract/primitive/find_thick_lines.cc: New.
+
+2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
* extract/primitive/objects.hh: use blobs_and_compute.
2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
diff --git a/scribo/src/extract/primitive/Makefile.am
b/scribo/src/extract/primitive/Makefile.am
index bab3f62..99be780 100644
--- a/scribo/src/extract/primitive/Makefile.am
+++ b/scribo/src/extract/primitive/Makefile.am
@@ -26,7 +26,9 @@ bin_PROGRAMS = \
extract_discontinued_hlines \
extract_thick_vlines \
extract_thick_hlines \
- find_discontinued_lines
+ find_discontinued_lines \
+ find_single_lines \
+ find_thick_lines
extract_discontinued_lines_SOURCES = extract_discontinued_lines.cc
extract_discontinued_vlines_SOURCES = extract_discontinued_vlines.cc
@@ -34,5 +36,7 @@ extract_discontinued_hlines_SOURCES = extract_discontinued_hlines.cc
extract_thick_vlines_SOURCES = extract_thick_vlines.cc
extract_thick_hlines_SOURCES = extract_thick_hlines.cc
find_discontinued_lines_SOURCES = find_discontinued_lines.cc
+find_single_lines_SOURCES = find_single_lines.cc
+find_thick_lines_SOURCES = find_thick_lines.cc
diff --git a/scribo/src/extract/primitive/find_discontinued_lines.cc
b/scribo/src/extract/primitive/find_discontinued_lines.cc
index 4fc76f6..ac3725a 100644
--- a/scribo/src/extract/primitive/find_discontinued_lines.cc
+++ b/scribo/src/extract/primitive/find_discontinued_lines.cc
@@ -34,6 +34,7 @@
#include <scribo/debug/usage.hh>
+#include <scribo/core/object_image.hh>
#include <scribo/extract/primitive/lines_h_pattern.hh>
#include <scribo/extract/primitive/lines_v_pattern.hh>
@@ -52,26 +53,22 @@ int main(int argc, char *argv[])
if (argc != 4)
return scribo::debug::usage(argv,
"Extract discontinued horizontal and vertical lines",
- "input.pbm length output.pbm",
+ "input.pbm length output.ppm",
args_desc,
- "A binary image of horizontal and vertical lines.");
+ "A color image. Horizontal lines are in red and vertical lines in
green.");
trace::entering("main");
- image2d<bool> input;
+ typedef image2d<bool> I;
+ I input;
io::pbm::load(input, argv[1]);
- value::label_16 nhlines;
- image2d<bool> hlines
- = data::convert(bool(),
- scribo::extract::primitive::lines_h_pattern(input, atoi(argv[2])));
- value::label_16 nvlines;
- image2d<bool> vlines
- = data::convert(bool(),
- scribo::extract::primitive::lines_v_pattern(input, atoi(argv[2])));
+ I hlines = scribo::extract::primitive::lines_h_pattern(input, atoi(argv[2]));
+ I vlines = scribo::extract::primitive::lines_v_pattern(input, atoi(argv[2]));
+
+ image2d<value::rgb8> out = debug::superpose(input, hlines, literal::red);
+ out = debug::superpose(out, vlines, literal::green);
- data::fill((hlines | pw::value(vlines)).rw(), true);
- image2d<value::rgb8> out = debug::superpose(input, hlines);
io::ppm::save(out, argv[3]);
trace::exiting("main");
diff --git a/scribo/src/extract/primitive/find_discontinued_lines.cc
b/scribo/src/extract/primitive/find_single_lines.cc
similarity index 59%
copy from scribo/src/extract/primitive/find_discontinued_lines.cc
copy to scribo/src/extract/primitive/find_single_lines.cc
index 4fc76f6..bd7b559 100644
--- a/scribo/src/extract/primitive/find_discontinued_lines.cc
+++ b/scribo/src/extract/primitive/find_single_lines.cc
@@ -34,13 +34,17 @@
#include <scribo/debug/usage.hh>
-#include <scribo/extract/primitive/lines_h_pattern.hh>
-#include <scribo/extract/primitive/lines_v_pattern.hh>
+#include <scribo/extract/primitive/objects.hh>
+#include <scribo/extract/primitive/lines_h_single.hh>
+#include <scribo/extract/primitive/lines_v_single.hh>
const char *args_desc[][2] =
{
- { "input.pbm", "A binary image." },
- { "length", " Minimum line length." },
+ { "input.pbm", "A binary image. Background must be set to False."
},
+ { "hlength", "Minimum horizontal line length." },
+ { "hbratio", "Bbox size ratio for horizontal lines." },
+ { "vlength", "Minimum vertical line length." },
+ { "vbratio", "Bbox size ratio for vertical lines." },
{0, 0}
};
@@ -49,30 +53,40 @@ int main(int argc, char *argv[])
{
using namespace mln;
- if (argc != 4)
+ if (argc != 7)
return scribo::debug::usage(argv,
- "Extract discontinued horizontal and vertical lines",
- "input.pbm length output.pbm",
+ "Extract single horizontal and vertical lines. \
+\n Common argument values: 100 10 100 10",
+ "<input.pbm> <length> <hbratio> <vbratio>\
+ <output.pbm>",
args_desc,
- "A binary image of horizontal and vertical lines.");
+ "A binary image of horizontal and vertical single lines.");
trace::entering("main");
image2d<bool> input;
io::pbm::load(input, argv[1]);
+ typedef image2d<value::label_16> L;
+
value::label_16 nhlines;
- image2d<bool> hlines
- = data::convert(bool(),
- scribo::extract::primitive::lines_h_pattern(input, atoi(argv[2])));
- value::label_16 nvlines;
- image2d<bool> vlines
- = data::convert(bool(),
- scribo::extract::primitive::lines_v_pattern(input, atoi(argv[2])));
-
- data::fill((hlines | pw::value(vlines)).rw(), true);
- image2d<value::rgb8> out = debug::superpose(input, hlines);
- io::ppm::save(out, argv[3]);
+ object_image(L)
+ objects = scribo::extract::primitive::objects(input, c8(), nhlines);
+
+
+ object_image(L)
+ hlines = scribo::extract::primitive::lines_h_single(objects,
+ atoi(argv[2]),
+ atof(argv[3]));
+
+ object_image(L)
+ vlines = scribo::extract::primitive::lines_v_single(objects,
+ atoi(argv[4]),
+ atof(argv[5]));
+
+ image2d<value::rgb8> out = debug::superpose(input, hlines, literal::red);
+ out = debug::superpose(out, vlines, literal::green);
+ io::ppm::save(out, argv[6]);
trace::exiting("main");
}
diff --git a/scribo/src/extract/primitive/find_discontinued_lines.cc
b/scribo/src/extract/primitive/find_thick_lines.cc
similarity index 51%
copy from scribo/src/extract/primitive/find_discontinued_lines.cc
copy to scribo/src/extract/primitive/find_thick_lines.cc
index 4fc76f6..ed5fb8c 100644
--- a/scribo/src/extract/primitive/find_discontinued_lines.cc
+++ b/scribo/src/extract/primitive/find_thick_lines.cc
@@ -34,13 +34,22 @@
#include <scribo/debug/usage.hh>
-#include <scribo/extract/primitive/lines_h_pattern.hh>
-#include <scribo/extract/primitive/lines_v_pattern.hh>
+#include <scribo/core/object_image.hh>
+#include <scribo/extract/primitive/lines_h_thick.hh>
+#include <scribo/extract/primitive/lines_v_thick.hh>
+
+#include <scribo/extract/primitive/lines_h_single.hh>
+#include <scribo/extract/primitive/lines_v_single.hh>
+
+#include <mln/util/timer.hh>
const char *args_desc[][2] =
{
- { "input.pbm", "A binary image." },
- { "length", " Minimum line length." },
+ { "input.pbm", "A binary image. Objects are set to True." },
+ { "vlength ", "Minimum vertical line length." },
+ { "vratio " "Minimum vertical ratio height/width." },
+ { "hlength ", "Minimum horizontal line length." },
+ { "hratio " "Minimum horizontal ratio width/height." },
{0, 0}
};
@@ -49,29 +58,56 @@ int main(int argc, char *argv[])
{
using namespace mln;
- if (argc != 4)
+ if (argc != 7)
return scribo::debug::usage(argv,
- "Extract discontinued horizontal and vertical lines",
- "input.pbm length output.pbm",
+ "Extract thick horizontal and vertical lines.\
+\n Common argument values: 150 10 150 10.",
+ "<input.pbm> <vlength> <vratio> <hlength>\
+ <hration> <output.ppm>",
args_desc,
- "A binary image of horizontal and vertical lines.");
+ "A color image. Horizontal lines are in red\
+ and vertical lines in green.");
trace::entering("main");
- image2d<bool> input;
+ typedef image2d<bool> I;
+ I input;
io::pbm::load(input, argv[1]);
- value::label_16 nhlines;
- image2d<bool> hlines
- = data::convert(bool(),
- scribo::extract::primitive::lines_h_pattern(input, atoi(argv[2])));
- value::label_16 nvlines;
- image2d<bool> vlines
- = data::convert(bool(),
- scribo::extract::primitive::lines_v_pattern(input, atoi(argv[2])));
-
- data::fill((hlines | pw::value(vlines)).rw(), true);
- image2d<value::rgb8> out = debug::superpose(input, hlines);
+ typedef image2d<value::label_16> L;
+
+ value::label_16
+ nhlines,
+ nvlines;
+
+ util::timer t;
+
+ t.start();
+
+ object_image(L)
+ hlines = scribo::extract::primitive::lines_h_thick(input, c8(),
+ nhlines, atoi(argv[2])),
+ vlines = scribo::extract::primitive::lines_v_thick(input, c8(),
+ nvlines, atoi(argv[2]));
+ std::cout << "lines thick done" << std::endl;
+ std::cout << t << std::endl;
+ t.restart();
+
+
+ hlines = scribo::extract::primitive::lines_h_single(hlines,
+ atoi(argv[2]),
+ 10);
+
+ vlines = scribo::extract::primitive::lines_v_single(vlines,
+ atoi(argv[2]),
+ 10);
+
+ std::cout << "lines single done" << std::endl;
+ std::cout << t << std::endl;
+
+ image2d<value::rgb8> out = debug::superpose(input, hlines, literal::red);
+ out = debug::superpose(out, vlines, literal::green);
+
io::ppm::save(out, argv[3]);
trace::exiting("main");
--
1.5.6.5