Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
tuto4_genericity_and_algorithms.cc
1 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
27 
28 #include <mln/core/image/image2d.hh>
29 #include <mln/core/image/dmorph/image_if.hh>
30 #include <mln/core/routine/duplicate.hh>
31 #include <mln/core/site_set/p_array.hh>
32 #include <mln/core/var.hh>
33 #include <mln/core/alias/neighb2d.hh>
34 
35 #include <mln/fun/p2b/chess.hh>
36 
37 #include <mln/extract/green.hh>
38 
39 #include <mln/accu/stat/max.hh>
40 
41 #include <mln/geom/all.hh>
42 
43 #include <mln/value/rgb8.hh>
44 #include <mln/value/label_8.hh>
45 
46 #include <mln/opt/at.hh>
47 
48 #include <mln/data/fill.hh>
49 
50 #include <mln/pw/all.hh>
51 
52 #include <mln/binarization/threshold.hh>
53 
54 #include <mln/labeling/colorize.hh>
55 #include <mln/labeling/blobs.hh>
56 
57 #include <mln/literal/colors.hh>
58 #include <mln/literal/max.hh>
59 
60 
61 #include <tests/data.hh>
62 #include <doc/tools/sample_utils.hh>
63 
64 struct keep_specific_colors : public mln::Function_v2b<keep_specific_colors>
65 {
66  bool operator()(const mln::value::rgb8& v) const
67  {
68  return v.green() < 200u && v.blue() > 100u;
69  }
70 };
71 
72 int main()
73 {
74  using namespace mln;
75 
76  // \{
78  io::ppm::load(lena, MLN_IMG_DIR "/small.ppm");
79  // \}
80 
81 
82  image2d<value::rgb8> lena_bak = duplicate(lena);
83  // \{
84  box2d roi = make::box2d(20, 20, 39, 39);
85  // \}
86  // \{
87  data::fill((lena | roi).rw(), literal::green);
88  // \}
89  doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
90 
91 
92 
93 
94  lena = duplicate(lena_bak);
95  // \{
96  p_array<point2d> arr;
97  for (def::coord row = geom::min_row(lena); row < geom::max_row(lena); ++row)
98  for (def::coord col = geom::min_row(lena); col < geom::max_col(lena); ++col)
99  if (((row + col) % 2) == 0)
100  arr.append(point2d(row, col));
101  // \}
102  // \{
103  for (def::coord row = geom::min_row(lena); row < geom::max_row(lena); ++row)
104  for (def::coord col = geom::min_row(lena); col < geom::max_col(lena); ++col)
105  if (((row + col) % 2) == 0)
106  opt::at(lena, row, col) = literal::green;
107  // \}
108  // \{
109  data::fill((lena | fun::p2b::chess()).rw(), literal::green);
110  // \}
111  doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
112 
113 
114 
115 
116  lena = duplicate(lena_bak);
117  // \{
118  image2d<bool> mask;
119  initialize(mask, lena);
120  data::fill(mask, false);
121  data::fill((mask | make::box2d(10, 10, 14, 14)).rw(), true);
122  data::fill((mask | make::box2d(25, 15, 29, 18)).rw(), true);
123  data::fill((mask | make::box2d(50, 50, 54, 54)).rw(), true);
124  // \}
125  doc::pbmsave(mask, "tuto4_genericity_and_algorithms");
126  // \{
127  data::fill((lena | pw::value(mask)).rw(), literal::green);
128  // \}
129  doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
130 
131 
132 
133 
134  lena = duplicate(lena_bak);
135  // \{
136  image2d<bool> lena_bw = binarization::binarization(lena, keep_specific_colors());
137  value::label_8 nlabels;
138  image2d<value::label_8> label = labeling::blobs(lena_bw, c8(), nlabels);
139  // \}
140  doc::ppmsave(labeling::colorize(value::rgb8(), label, nlabels), "tuto4_genericity_and_algorithms");
141 
142  // \{
143  data::fill((lena | (pw::value(label) == pw::cst(0u))).rw(), literal::blue);
144  // \}
145  doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
146 
147 
148 
149 
150 // Disabled until thru_image/fun_image provide working read/write access.
151 //
152 // lena = duplicate(lena_bak);
153 // // \{
154 // data::fill(extract::green(lena).rw(), literal::max);
155 // // \}
156 // //FIXME: we would like to save the green component in rgb8.
157 // doc::pgmsave(extract::green(lena), "tuto4_genericity_and_algorithms");
158 // doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
159 //
160 //
161 //
162 //
163 // lena = duplicate(lena_bak);
164 // // \{
165 // mln_VAR(object, pw::value(label) == pw::cst(0u));
166 // data::fill((extract::green(lena).rw() | object).rw(), literal::max);
167 // // \}
168 // //FIXME: how to display an image which is not defined on a box!?
170 // doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
171 
172 }