• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

tuto4_genericity_and_algorithms.cc

00001 // Copyright (C) 2009 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/extract/green.hh>
00038 
00039 #include <mln/accu/stat/max.hh>
00040 
00041 #include <mln/geom/all.hh>
00042 
00043 #include <mln/value/rgb8.hh>
00044 #include <mln/value/label_8.hh>
00045 
00046 #include <mln/opt/at.hh>
00047 
00048 #include <mln/data/fill.hh>
00049 
00050 #include <mln/pw/all.hh>
00051 
00052 #include <mln/binarization/threshold.hh>
00053 
00054 #include <mln/labeling/colorize.hh>
00055 #include <mln/labeling/blobs.hh>
00056 
00057 #include <mln/literal/colors.hh>
00058 #include <mln/literal/max.hh>
00059 
00060 
00061 #include <tests/data.hh>
00062 #include <doc/tools/sample_utils.hh>
00063 
00064 struct keep_specific_colors : public mln::Function_v2b<keep_specific_colors>
00065 {
00066   bool operator()(const mln::value::rgb8& v) const
00067   {
00068     return v.green() < 200u && v.blue() > 100u;
00069   }
00070 };
00071 
00072 int main()
00073 {
00074   using namespace mln;
00075 
00076   // \{
00077   image2d<value::rgb8> lena;
00078   io::ppm::load(lena, MLN_IMG_DIR "/small.ppm");
00079   // \}
00080 
00081 
00082   image2d<value::rgb8> lena_bak = duplicate(lena);
00083   // \{
00084   box2d roi = make::box2d(20, 20, 39, 39);
00085   // \}
00086   // \{
00087   data::fill((lena | roi).rw(), literal::green);
00088   // \}
00089   doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00090 
00091 
00092 
00093 
00094   lena = duplicate(lena_bak);
00095   // \{
00096   p_array<point2d> arr;
00097   for (def::coord row = geom::min_row(lena); row < geom::max_row(lena); ++row)
00098     for (def::coord col = geom::min_row(lena); col < geom::max_col(lena); ++col)
00099       if (((row + col) % 2) == 0)
00100         arr.append(point2d(row, col));
00101   // \}
00102   // \{
00103   for (def::coord row = geom::min_row(lena); row < geom::max_row(lena); ++row)
00104     for (def::coord col = geom::min_row(lena); col < geom::max_col(lena); ++col)
00105       if (((row + col) % 2) == 0)
00106         opt::at(lena, row, col) = literal::green;
00107   // \}
00108   // \{
00109   data::fill((lena | fun::p2b::chess()).rw(), literal::green);
00110   // \}
00111   doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00112 
00113 
00114 
00115 
00116   lena = duplicate(lena_bak);
00117   // \{
00118   image2d<bool> mask;
00119   initialize(mask, lena);
00120   data::fill(mask, false);
00121   data::fill((mask | make::box2d(10, 10, 14, 14)).rw(), true);
00122   data::fill((mask | make::box2d(25, 15, 29, 18)).rw(), true);
00123   data::fill((mask | make::box2d(50, 50, 54, 54)).rw(), true);
00124   // \}
00125   doc::pbmsave(mask, "tuto4_genericity_and_algorithms");
00126   // \{
00127   data::fill((lena | pw::value(mask)).rw(), literal::green);
00128   // \}
00129   doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00130 
00131 
00132 
00133 
00134   lena = duplicate(lena_bak);
00135   // \{
00136   image2d<bool> lena_bw = binarization::binarization(lena, keep_specific_colors());
00137   value::label_8 nlabels;
00138   image2d<value::label_8> label = labeling::blobs(lena_bw, c8(), nlabels);
00139   // \}
00140   doc::ppmsave(labeling::colorize(value::rgb8(), label, nlabels), "tuto4_genericity_and_algorithms");
00141 
00142   // \{
00143   data::fill((lena | (pw::value(label) == pw::cst(0u))).rw(), literal::blue);
00144   // \}
00145   doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00146 
00147 
00148 
00149 
00150 // Disabled until thru_image/fun_image provide working read/write access.
00151 //
00152 //  lena = duplicate(lena_bak);
00153 //  // \{
00154 //  data::fill(extract::green(lena).rw(), literal::max);
00155 //  // \}
00156 //  //FIXME: we would like to save the green component in rgb8.
00157 //  doc::pgmsave(extract::green(lena), "tuto4_genericity_and_algorithms");
00158 //  doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00159 //
00160 //
00161 //
00162 //
00163 //  lena = duplicate(lena_bak);
00164 //  // \{
00165 //  mln_VAR(object, pw::value(label) == pw::cst(0u));
00166 //  data::fill((extract::green(lena).rw() | object).rw(), literal::max);
00167 //  // \}
00168 //  //FIXME: how to display an image which is not defined on a box!?
00170 //  doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
00171 
00172 }

Generated on Tue Oct 4 2011 15:24:45 for Milena (Olena) by  doxygen 1.7.1