$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fill-subdomain.cc
1 #include <mln/core/image/image2d.hh>
2 #include <mln/core/image/dmorph/image_if.hh>
3 #include <mln/core/var.hh>
4 #include <mln/core/alias/neighb2d.hh>
5 
6 #include <mln/make/image.hh>
7 
8 #include <mln/value/rgb8.hh>
9 #include <mln/value/label_8.hh>
10 #include <mln/literal/colors.hh>
11 
12 #include <mln/pw/all.hh>
13 
14 #include <mln/labeling/blobs.hh>
15 #include <mln/labeling/colorize.hh>
16 
17 #include <mln/data/fill.hh>
18 
19 #include <doc/tools/sample_utils.hh>
20 
21 int main()
22 {
23  using namespace mln;
24  using value::rgb8;
25  using value::label_8;
26 
27 
28  // \{
29  bool vals[6][5] = {
30  {0, 1, 1, 0, 0},
31  {0, 1, 1, 0, 0},
32  {0, 0, 0, 0, 0},
33  {1, 1, 0, 1, 0},
34  {1, 0, 1, 1, 1},
35  {1, 0, 0, 0, 0}
36  };
37  image2d<bool> ima = make::image(vals);
38  // \}
39 
40  doc::pbmsave(ima, "fill-subdomain");
41 
42  // Find and label the different components.
43  // \{
44  label_8 nlabels;
45  image2d<label_8> lbl = labeling::blobs(ima, c4(), nlabels);
46  // \}
47 
48  doc::ppmsave(labeling::colorize(rgb8(), lbl, nlabels), "fill-subdomain");
49 
50  // Create a new image from lbl's sites being part of component 2.
51  // \{
52  mln_VAR(lbl_2, lbl | (pw::value(lbl) == pw::cst(2u)));
53  // \}
54 
55  image2d<label_8> tmp;
56  initialize(tmp, lbl);
57  data::fill(tmp, 0);
58  data::fill((tmp | lbl_2.domain()).rw(), 1);
59  doc::ppmsave(labeling::colorize(rgb8(), tmp, 1), "fill-subdomain");
60 
61  // Create a black image from ima.
62  // Fill sites being part of component 2 with red.
63  // \{
64  image2d<rgb8> ima2;
65  initialize(ima2, ima);
67 
68  data::fill((ima2 | lbl_2.domain()).rw(), literal::red);
69  // \}
70 
71  doc::ppmsave(ima2, "fill-subdomain");
72 }