Milena (Olena)  User documentation 2.0a Id
tuto4_genericity_and_algorithms.cc
00001 // Copyright (C) 2009, 2012 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00027 
00028 #include <mln/core/image/image2d.hh>
00029 #include <mln/core/image/dmorph/image_if.hh>
00030 #include <mln/core/routine/duplicate.hh>
00031 #include <mln/core/site_set/p_array.hh>
00032 #include <mln/core/var.hh>
00033 #include <mln/core/alias/neighb2d.hh>
00034 
00035 #include <mln/fun/p2b/chess.hh>
00036 
00037 #include <mln/accu/stat/max.hh>
00038 
00039 #include <mln/geom/all.hh>
00040 
00041 #include <mln/value/rgb8.hh>
00042 #include <mln/value/label_8.hh>
00043 
00044 #include <mln/opt/at.hh>
00045 
00046 #include <mln/data/fill.hh>
00047 
00048 #include <mln/pw/all.hh>
00049 
00050 #include <mln/binarization/threshold.hh>
00051 
00052 #include <mln/labeling/colorize.hh>
00053 #include <mln/labeling/blobs.hh>
00054 
00055 #include <mln/literal/colors.hh>
00056 #include <mln/literal/max.hh>
00057 
00058 
00059 #include <tests/data.hh>
00060 #include <doc/tools/sample_utils.hh>
00061 
00062 struct keep_specific_colors : public mln::Function_v2b<keep_specific_colors>
00063 {
00064   bool operator()(const mln::value::rgb8& v) const
00065   {
00066     return v.green() < 200u && v.blue() > 100u;
00067   }
00068 };
00069 
00070 int main()
00071 {
00072   using namespace mln;
00073 
00074   // \{
00075   image2d<value::rgb8> lena;
00076   io::ppm::load(lena, MLN_IMG_DIR "/small.ppm");
00077   // \}
00078 
00079 
00080   image2d<value::rgb8> lena_bak = duplicate(lena);
00081   // \{
00082   box2d roi = make::box2d(20, 20, 39, 39);
00083   // \}
00084   // \{
00085   data::fill((lena | roi).rw(), literal::green);
00086   // \}
00087   doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00088 
00089 
00090 
00091 
00092   lena = duplicate(lena_bak);
00093   // \{
00094   p_array<point2d> arr;
00095   for (def::coord row = geom::min_row(lena); row < geom::max_row(lena); ++row)
00096     for (def::coord col = geom::min_row(lena); col < geom::max_col(lena); ++col)
00097       if (((row + col) % 2) == 0)
00098         arr.append(point2d(row, col));
00099   // \}
00100   // \{
00101   for (def::coord row = geom::min_row(lena); row < geom::max_row(lena); ++row)
00102     for (def::coord col = geom::min_row(lena); col < geom::max_col(lena); ++col)
00103       if (((row + col) % 2) == 0)
00104         opt::at(lena, row, col) = literal::green;
00105   // \}
00106   // \{
00107   data::fill((lena | fun::p2b::chess()).rw(), literal::green);
00108   // \}
00109   doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00110 
00111 
00112 
00113 
00114   lena = duplicate(lena_bak);
00115   // \{
00116   image2d<bool> mask;
00117   initialize(mask, lena);
00118   data::fill(mask, false);
00119   data::fill((mask | make::box2d(10, 10, 14, 14)).rw(), true);
00120   data::fill((mask | make::box2d(25, 15, 29, 18)).rw(), true);
00121   data::fill((mask | make::box2d(50, 50, 54, 54)).rw(), true);
00122   // \}
00123   doc::pbmsave(mask, "tuto4_genericity_and_algorithms");
00124   // \{
00125   data::fill((lena | pw::value(mask)).rw(), literal::green);
00126   // \}
00127   doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00128 
00129 
00130 
00131 
00132   lena = duplicate(lena_bak);
00133   // \{
00134   image2d<bool> lena_bw = binarization::binarization(lena, keep_specific_colors());
00135   value::label_8 nlabels;
00136   image2d<value::label_8> label = labeling::blobs(lena_bw, c8(), nlabels);
00137   // \}
00138   doc::ppmsave(labeling::colorize(value::rgb8(), label, nlabels), "tuto4_genericity_and_algorithms");
00139 
00140   // \{
00141   data::fill((lena | (pw::value(label) == pw::cst(0u))).rw(), literal::blue);
00142   // \}
00143   doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00144 
00145 
00146 
00147 
00148 // Disabled until thru_image/fun_image provide working read/write access.
00149 //
00150 //  lena = duplicate(lena_bak);
00151 //  // \{
00152 //  data::fill(extract::green(lena).rw(), literal::max);
00153 //  // \}
00154 //  //FIXME: we would like to save the green component in rgb8.
00155 //  doc::pgmsave(extract::green(lena), "tuto4_genericity_and_algorithms");
00156 //  doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00157 //
00158 //
00159 //
00160 //
00161 //  lena = duplicate(lena_bak);
00162 //  // \{
00163 //  mln_VAR(object, pw::value(label) == pw::cst(0u));
00164 //  data::fill((extract::green(lena).rw() | object).rw(), literal::max);
00165 //  // \}
00166 //  //FIXME: how to display an image which is not defined on a box!?
00168 //  doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00169 
00170 }
 All Classes Namespaces Functions Variables Typedefs Enumerator