$extrastylesheet
Olena
User documentation 2.1
An Image Processing Platform
Scribo
Modules
Namespaces
Classes
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
group_from_single_link.cc
1
// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
2
// Laboratory (LRDE)
3
//
4
// This file is part of Olena.
5
//
6
// Olena is free software: you can redistribute it and/or modify it under
7
// the terms of the GNU General Public License as published by the Free
8
// Software Foundation, version 2 of the License.
9
//
10
// Olena is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
17
//
18
// As a special exception, you may use this file as part of a free
19
// software project without restriction. Specifically, if other files
20
// instantiate templates or use macros or inline functions from this
21
// file, or you compile this file and link it with other files to produce
22
// an executable, this file does not by itself cause the resulting
23
// executable to be covered by the GNU General Public License. This
24
// exception does not however invalidate any other reasons why the
25
// executable file might be covered by the GNU General Public License.
26
27
#include <iostream>
28
29
#include <mln/core/image/image2d.hh>
30
#include <mln/core/alias/neighb2d.hh>
31
32
#include <mln/labeling/colorize.hh>
33
34
#include <mln/util/array.hh>
35
36
#include <mln/value/label_16.hh>
37
#include <mln/literal/colors.hh>
38
39
#include <mln/io/pbm/load.hh>
40
41
#include <scribo/primitive/extract/components.hh>
42
#include <scribo/primitive/link/with_single_left_link.hh>
43
#include <scribo/primitive/link/with_single_right_link.hh>
44
#include <scribo/primitive/group/from_single_link.hh>
45
#include <scribo/primitive/group/apply.hh>
46
47
#include <scribo/debug/bboxes_image.hh>
48
#include <scribo/debug/linked_bboxes_image.hh>
49
#include <scribo/make/debug_filename.hh>
50
51
52
int
usage
(
char
*argv[])
53
{
54
std::cout <<
"Usage: "
<< argv[0] <<
" <input.pbm> "
<< std::endl;
55
return
1;
56
}
57
58
59
int
main(
int
argc,
char
* argv[])
60
{
61
using namespace
scribo;
62
using namespace
mln;
63
64
if
(argc != 2)
65
return
usage
(argv);
66
67
scribo::make::internal::debug_filename_prefix =
"group_with_single_link"
;
68
69
image2d<bool>
input;
70
io::pbm::load
(input, argv[1]);
71
72
value::label_16 nbboxes;
73
typedef
image2d<value::label_16>
L;
74
component_set<L>
75
comps =
scribo::primitive::extract::components
(input,
c8
(), nbboxes);
76
77
{
78
std::cout <<
"* Left grouping"
<< std::endl;
79
object_links<L>
left_link
80
=
primitive::link::with_single_left_link
(comps, 30);
81
82
std::cout <<
"BEFORE - nbboxes = "
<< nbboxes << std::endl;
83
io::ppm::save
(
scribo::debug::linked_bboxes_image
(input,
84
left_link,
85
literal::red,
86
literal::cyan),
87
scribo::make::debug_filename
(
"left_links.ppm"
));
88
// io::ppm::save(mln::labeling::colorize(value::rgb8(),
89
// comps,
90
// comps.nlabels()),
91
// scribo::make::debug_filename("lbl_before.ppm"));
92
93
object_groups<L>
94
groups =
primitive::group::from_single_link
(left_link);
95
96
component_set<L>
grouped_comps =
primitive::group::apply
(groups);
97
98
std::cout <<
"AFTER - nbboxes = "
<< grouped_comps.
nelements
() << std::endl;
99
io::ppm::save
(
mln::labeling::colorize
(value::rgb8(),
100
grouped_comps.
labeled_image
(),
101
grouped_comps.
nelements
()),
102
scribo::make::debug_filename
(
"left_label_color.ppm"
));
103
io::ppm::save
(
scribo::debug::bboxes_image
(input, grouped_comps,
104
literal::red),
105
scribo::make::debug_filename
(
"left_bboxes.ppm"
));
106
}
107
108
{
109
std::cout <<
"* Left grouping"
<< std::endl;
110
object_links<L>
right_link
111
=
primitive::link::with_single_right_link
(comps, 30);
112
113
std::cout <<
"BEFORE - nbboxes = "
<< nbboxes << std::endl;
114
io::ppm::save
(
scribo::debug::linked_bboxes_image
(input,
115
right_link,
116
literal::red, literal::cyan),
117
scribo::make::debug_filename
(
"right_links.ppm"
));
118
// io::ppm::save(mln::labeling::colorize(value::rgb8(),
119
// comps,
120
// comps.nlabels()),
121
// scribo::make::debug_filename("lbl_before.ppm"));
122
123
object_groups<L>
124
groups =
primitive::group::from_single_link
(right_link);
125
126
component_set<L>
grouped_comps =
primitive::group::apply
(groups);
127
128
io::ppm::save
(
mln::labeling::colorize
(value::rgb8(),
129
grouped_comps.
labeled_image
(),
130
grouped_comps.
nelements
()),
131
scribo::make::debug_filename
(
"right_label_color.ppm"
));
132
std::cout <<
"AFTER - nbboxes = "
<< grouped_comps.
nelements
() << std::endl;
133
134
io::ppm::save
(
scribo::debug::bboxes_image
(input, grouped_comps,
135
literal::red),
136
scribo::make::debug_filename
(
"right_bboxes.ppm"
));
137
}
138
139
140
}
scribo
src
primitive
group
group_from_single_link.cc
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)