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

erosion_tolerant.hh

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 
00026 #ifndef MLN_MORPHO_EROSION_TOLERANT_HH
00027 # define MLN_MORPHO_EROSION_TOLERANT_HH
00028 
00035 
00036 # include <mln/accu/count_value.hh>
00037 # include <mln/accu/logic/land.hh>
00038 # include <mln/accu/logic/land_basic.hh>
00039 # include <mln/accu/stat/min.hh>
00040 # include <mln/accu/stat/min_h.hh>
00041 # include <mln/accu/transform.hh>
00042 # include <mln/morpho/general.hh>
00043 # include <mln/morpho/includes.hh>
00044 # include <mln/morpho/erosion.hh>
00045 
00046 namespace mln
00047 {
00048 
00049   namespace morpho
00050   {
00051 
00053     template <typename I, typename W>
00054     mln_concrete(I)
00055     erosion_tolerant(const Image<I>& input, const Window<W>& win,
00056                      unsigned rank);
00057 
00058 
00059 # ifndef MLN_INCLUDE_ONLY
00060 
00061 
00062     // Implementation
00063 
00064     namespace impl
00065     {
00066 
00067       template <typename I, typename W>
00068       mln_concrete(I)
00069       erosion_tolerant_on_set(const Image<I>& input_,
00070                               const Window<W>& win_,
00071                               unsigned rank)
00072       {
00073         trace::entering("morpho::impl::erosion_tolerant_on_set");
00074 
00075         typedef mln_concrete(I) O;
00076         const I& input = exact(input_);
00077         const W& win = exact(win_);
00078 
00079         extension::adjust_fill(input, win, true);
00080 
00081         mln_ch_value(I, unsigned)
00082           tmp = accu::transform(input,
00083                                 accu::count_value<mln_value(I)>(false),
00084                                 win);
00085 
00086         O output;
00087         output = duplicate(input);
00088 
00089         mln_piter(I) p(input.domain());
00090         for_all(p)
00091           if (input(p) == true && tmp(p) >= rank)
00092             output(p) = false;
00093 
00094         trace::exiting("morpho::impl::erosion_tolerant_on_set");
00095         return output;
00096       }
00097 
00098 
00099 
00100       template <typename I, typename W>
00101       mln_concrete(I)
00102       erosion_tolerant_on_set_fastest(const Image<I>& input_,
00103                                       const Window<W>& win_,
00104                                       unsigned rank)
00105       {
00106         trace::entering("morpho::impl::erosion_tolerant_on_set_fastest");
00107 
00108         typedef mln_concrete(I) O;
00109         const I& input = exact(input_);
00110         const W& win = exact(win_);
00111 
00112         extension::adjust_fill(input, win, true);
00113 
00114         typedef mln_ch_value(I, unsigned) tmp_t;
00115         tmp_t tmp = accu::transform(input,
00116                                     accu::count_value<mln_value(I)>(false),
00117                                     win);
00118 
00119         O output;
00120         output = duplicate(input);
00121 
00122         mln_pixter(const I) p(input);
00123         for_all(p)
00124           if (p.val() == true)
00125             if (tmp.element(p.offset()) >= rank)
00126               output.element(p.offset()) = false;
00127 
00128         trace::exiting("morpho::impl::erosion_tolerant_on_set_fastest");
00129         return output;
00130       }
00131 
00132     } // end of namespace morpho::impl
00133 
00134 
00135 
00136 
00137     // Dispatch
00138 
00139     namespace internal
00140     {
00141 
00142       template <typename I, typename W>
00143       mln_concrete(I)
00144       erosion_tolerant_dispatch(trait::image::kind::any,
00145                                 trait::image::speed::any,
00146                                 const I& input, const W& win, unsigned rank)
00147       {
00148         mlc_abort(I)::check();
00149 
00150         typedef mln_concrete(I) output_t;
00151         return output_t();
00152       }
00153 
00154 
00155       template <typename I, typename W>
00156       mln_concrete(I)
00157       erosion_tolerant_dispatch(trait::image::kind::logic,
00158                                 trait::image::speed::any,
00159                                 const I& input, const W& win, unsigned rank)
00160       {
00161         return impl::erosion_tolerant_on_set(input,
00162                                              win,
00163                                              rank);
00164       }
00165 
00166       template <typename I, typename W>
00167       mln_concrete(I)
00168       erosion_tolerant_dispatch(trait::image::kind::logic,    // On sets.
00169                                 trait::image::speed::fastest, // Fastest.
00170                                 const I& input, const W& win, unsigned rank)
00171       {
00172         return impl::erosion_tolerant_on_set_fastest(input,
00173                                                      win,
00174                                                      rank);
00175       }
00176 
00177 
00178       template <typename I, typename W>
00179       inline
00180       mln_concrete(I)
00181       erosion_tolerant_dispatch(const Image<I>& input,
00182                                 const Window<W>& win,
00183                                 unsigned rank)
00184       {
00185         return erosion_tolerant_dispatch(mln_trait_image_kind(I)(),
00186                                          mln_trait_image_speed(I)(),
00187                                          exact(input), exact(win), rank);
00188       }
00189 
00190     } // end of namespace mln::morpho::internal
00191 
00192 
00193 
00194 
00195     // Facade
00196 
00197     template <typename I, typename W>
00198     inline
00199     mln_concrete(I)
00200     erosion_tolerant(const Image<I>& input, const Window<W>& win,
00201                      unsigned rank)
00202     {
00203       trace::entering("morpho::erosion_tolerant");
00204       mln_precondition(exact(input).is_valid());
00205       mln_precondition(exact(win).is_valid());
00206 
00207       mln_concrete(I)
00208         output = internal::erosion_tolerant_dispatch(input, win, rank);
00209 
00210       trace::exiting("morpho::erosion_tolerant");
00211       return output;
00212     }
00213 
00214 # endif // ! MLN_INCLUDE_ONLY
00215 
00216   } // end of namespace mln::morpho
00217 
00218 } // end of namespace mln
00219 
00220 
00221 #endif // ! MLN_MORPHO_EROSION_TOLERANT_HH

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