$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
doc/examples/extend.cc
1 #include <mln/core/image/dmorph/extended.hh>
2 #include <mln/core/image/dmorph/image_if.hh>
3 #include <mln/core/routine/extend.hh>
4 #include <mln/core/var.hh>
5 
6 #include <mln/data/transform.hh>
7 #include <mln/data/paste.hh>
8 
9 #include <mln/fun/p2b/big_chess.hh>
10 
11 #include <mln/value/rgb8.hh>
12 #include <mln/literal/colors.hh>
13 
14 #include <tests/data.hh>
15 
16 #include <doc/tools/sample_utils.hh>
17 
18 namespace mln
19 {
20 
21  struct saturate_rgb8 : public Function_v2v<saturate_rgb8>
22  {
23 
24  typedef value::rgb8 result;
25 
26  value::rgb8 operator()(const value::rgb8& v) const
27  {
28  value::rgb8 v2 = v;
29  v2.red() > 50 ? v2.red() -= 50 : v2.red() = 0;
30  v2.green() > 50 ? v2.green() -= 50 : v2.green() = 0;
31  v2.blue() > 50 ? v2.blue() -= 50 : v2.blue() = 0;
32  return v2;
33  }
34 
35  };
36 
37 } // end of namespace mln
38 
39 // \{
40 namespace mln
41 {
42 
43  struct my_ext : public Function_v2v<my_ext>
44  {
45 
46  typedef value::rgb8 result;
47 
48  value::rgb8 operator()(const point2d& p) const
49  {
50  if ((p.row() + p.col()) % 20)
51  return literal::black;
52  return literal::white;
53  }
54 
55  };
56 
57 } // end of namespace mln
58 // \}
59 
60 int main()
61 {
62  using namespace mln;
63  using value::rgb8;
64 
66 
67  // \{
68  image2d<rgb8> lena;
69  io::ppm::load(lena, MLN_IMG_DIR "/small.ppm");
70  box2d bbox_enlarged = lena.domain();
71  bbox_enlarged.enlarge(border::thickness);
72  mln_VAR(ima_roi, lena | fun::p2b::big_chess<box2d>(lena.domain(), 10));
73  // \}
74 
75  image2d<rgb8> tmp;
76  initialize(tmp, lena);
78  data::paste(ima_roi, tmp);
79  doc::ppmsave(tmp, "extend");
80 
81  // \{
82  mln_VAR(ext_with_val, extended_to(extend(ima_roi, literal::blue), bbox_enlarged));
83  // \}
84  doc::ppmsave(ext_with_val, "extend");
85 
86  // \{
87  mln_VAR(ext_with_fun, extended_to(extend(ima_roi, my_ext()), bbox_enlarged));
88  // \}
89  doc::ppmsave(ext_with_fun, "extend");
90 
91 
92  // \{
93  mln_VAR(ext_with_ima, extend(ima_roi, lena));
94  // \}
95  doc::ppmsave(ext_with_ima, "extend");
96 
97  image2d<bool> mask;
98  initialize(mask, lena);
99  data::fill(mask, true);
100  data::fill((mask | ima_roi.domain()).rw(), false);
101  mln_VAR(ima_ext, data::transform(lena | (pw::value(mask) != false), saturate_rgb8()));
102  data::paste(ima_ext, lena);
103  data::paste(ima_roi, lena);
104  doc::ppmsave(lena, "extend");
105 
106 }