28 #include <mln/core/image/image2d.hh>
29 #include <mln/labeling/colorize.hh>
30 #include <mln/debug/println.hh>
31 #include <mln/util/array.hh>
32 #include <mln/literal/colors.hh>
33 #include <mln/io/pbm/load.hh>
34 #include <mln/core/alias/neighb2d.hh>
35 #include <mln/value/label_16.hh>
37 #include <scribo/core/object_image.hh>
39 #include <scribo/primitive/extract/objects.hh>
40 #include <scribo/primitive/link/with_single_left_link.hh>
41 #include <scribo/primitive/link/with_single_right_link.hh>
42 #include <scribo/debug/save_linked_bboxes_image.hh>
43 #include <scribo/primitive/group/from_double_link.hh>
44 #include <scribo/primitive/group/from_single_link.hh>
45 #include <scribo/primitive/link/merge_double_link.hh>
46 #include <scribo/primitive/group/apply.hh>
47 #include <scribo/filter/objects_small.hh>
49 #include <scribo/filter/object_links_non_h_aligned.hh>
51 #include <scribo/debug/save_bboxes_image.hh>
52 #include <scribo/make/debug_filename.hh>
55 #include <scribo/debug/usage.hh>
57 const char *args_desc[][2] =
59 {
"input.pbm",
"A binary image. 'True' for objects, 'False'\
60 for the background." },
61 {
"hlmax",
"Maximum distance between two grouped objects while browsing on the left." },
62 {
"hrmax",
"Maximum distance between two grouped objects while browsing on the right." },
63 {
"hdelta_max",
"Maximum horizontal distance between top/bottom corner of two grouped bboxes." },
64 {
"prefix",
"Output names prefix" },
68 int main(
int argc,
char *argv[])
70 using namespace scribo;
75 "Group potential text objects using a double validation link.",
76 "input.pbm hlmax hrmax hdelta_max prefix",
78 "Several images showing the process.");
81 scribo::make::internal::debug_filename_prefix = argv[5];
86 value::label_16 nbboxes;
88 typedef object_image(L) text_t;
90 text_t text = primitive::extract::objects(input,
c8(), nbboxes);
92 text = filter::objects_small(text, 4);
95 = primitive::link::with_single_left_link(text, atoi(argv[2]));
97 = primitive::link::with_single_right_link(text, atoi(argv[3]));
99 std::cout << "BEFORE - nbboxes = " << nbboxes << std::endl;
110 scribo::debug::save_linked_bboxes_image(input,
111 text, left_link, right_link,
112 literal::red, literal::cyan, literal::yellow,
114 scribo::make::debug_filename("links.ppm"));
118 = primitive::link::merge_double_link(text,
124 grouped_text = primitive::group::
apply(text, double_link);
125 std::cout << "AFTER
double grouping - nbboxes = "
126 << grouped_text.bboxes().nelements() << std::endl;
131 grouped_text.nlabels()),
132 scribo::make::debug_filename("label_color.ppm"));
135 scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
137 scribo::make::debug_filename("bboxes.ppm"));
144 = filter::object_links_non_h_aligned(text, double_link, atof(argv[4]));
147 text_t aligned_grouped_text
148 = primitive::group::
apply(text, filtered_links);
151 std::cout << "AFTER filtering - Links may have been canceled - nbboxes = "
152 << aligned_grouped_text.bboxes().nelements() << std::endl;
156 aligned_grouped_text,
157 aligned_grouped_text.nlabels()),
158 scribo::make::debug_filename("label_color-filtered.ppm"));
161 scribo::debug::save_bboxes_image(input, aligned_grouped_text.bboxes(),
163 scribo::make::debug_filename("bboxes-filtered.ppm"));