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

crest.hh

00001 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
00002 // (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_TOPO_SKELETON_CREST_HH
00028 # define MLN_TOPO_SKELETON_CREST_HH
00029 
00033 
00034 # include <mln/core/concept/image.hh>
00035 # include <mln/core/concept/neighborhood.hh>
00036 # include <mln/data/fill.hh>
00037 
00038 
00039 namespace mln
00040 {
00041 
00042   namespace topo
00043   {
00044 
00045     namespace skeleton
00046     {
00047 
00048 
00060       //
00090       template <typename I, typename D, typename N>
00091       mln_concrete(I)
00092       crest(const Image<I>& input, const Image<D>& dist_map,
00093             const Neighborhood<N>& nbh, unsigned psi_threshold);
00094 
00097       template <typename I, typename D, typename N>
00098       mln_concrete(I)
00099       crest(const Image<I>& input, const Image<D>& dist_map,
00100             const Neighborhood<N>& nbh);
00101 
00102 
00103 
00104 # ifndef MLN_INCLUDE_ONLY
00105 
00106 
00107       template <typename I, typename D, typename N>
00108       mln_concrete(I)
00109       crest(const Image<I>& input_, const Image<D>& dist_map_,
00110             const Neighborhood<N>& nbh_, unsigned psi_threshold)
00111       {
00112         trace::entering("topo::skeleton::crest");
00113         const I& input = exact(input_);
00114         const D& dist_map = exact(dist_map_);
00115         const N& nbh = exact(nbh_);
00116 
00117         mlc_equal(mln_value(I), bool)::check();
00118         mln_precondition(input.is_valid());
00119         mln_precondition(dist_map.is_valid());
00120         mln_precondition(nbh.is_valid());
00121 
00122         mln_concrete(I) is_crest;
00123         initialize(is_crest, input);
00124         data::fill(is_crest, false);
00125 
00126         mln_piter(I) p(input.domain());
00127         mln_niter(N) n(nbh, p);
00128         for_all(p)
00129         {
00130           if (!input(p) || dist_map(p) < static_cast<mln_value(D)>(0))
00131             continue;
00132 
00133           unsigned nb_eq = 0;
00134           unsigned nb_lt = 0;
00135           for_all(n)
00136             if (input.domain().has(n)
00137                 // We want to only consider sites which are part of
00138                 // the skeleton. If this test is removed, sometimes
00139                 // edge sites are considered as sites with a high PSI
00140                 // which is wrong.
00141               && dist_map(n) > static_cast<mln_value(D)>(0))
00142             {
00143               if (dist_map(n) == dist_map(p))
00144                 ++nb_eq;
00145               else if (dist_map(n) < dist_map(p))
00146                 ++nb_lt;
00147             }
00148 
00149           if ((nb_lt + nb_eq) >= psi_threshold) // Pixel Superiority index
00150             is_crest(p) = true;
00151         }
00152 
00153         trace::exiting("topo::skeleton::crest");
00154         return is_crest;
00155       }
00156 
00157 
00158       template <typename I, typename D, typename N>
00159       mln_concrete(I)
00160       crest(const Image<I>& input, const Image<D>& dist_map,
00161             const Neighborhood<N>& nbh)
00162       {
00163         return crest(input, dist_map, nbh, 6);
00164       }
00165 
00166 # endif // ! MLN_INCLUDE_ONLY
00167 
00168 
00169     } // end of namespace mln::topo::skeleton
00170 
00171   } // end of namespace mln::topo
00172 
00173 } // end of namespace mln
00174 
00175 #endif // ! MLN_TOPO_SKELETON_CREST_HH

Generated on Fri Oct 19 2012 04:15:43 for Milena (Olena) by  doxygen 1.7.1