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

blobs.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development
00002 // Laboratory (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_LABELING_BLOBS_HH
00028 # define MLN_LABELING_BLOBS_HH
00029 
00038 
00039 # include <mln/core/concept/image.hh>
00040 # include <mln/core/concept/neighborhood.hh>
00041 # include <mln/data/fill.hh>
00042 # include <mln/core/site_set/p_queue_fast.hh>
00043 
00044 
00045 
00046 namespace mln
00047 {
00048 
00049   namespace labeling
00050   {
00051 
00066     template <typename I, typename N, typename L>
00067     mln_ch_value(I, L)
00068     blobs(const Image<I>& input, const Neighborhood<N>& nbh,
00069           L& nlabels);
00070 
00071 
00072 # ifndef MLN_INCLUDE_ONLY
00073 
00074     namespace impl
00075     {
00076 
00077       namespace generic
00078       {
00079 
00080         template <typename I, typename N, typename L>
00081         mln_ch_value(I, L)
00082           blobs_(const I& input, const N& nbh, L& nlabels)
00083         {
00084           typedef mln_psite(I) P;
00085 
00086           P cur;
00087           mln_niter(N) n(nbh, cur);
00088           p_queue_fast<P> qu;
00089           const L zero = literal::zero;
00090 
00091           // Initialization.
00092           nlabels = literal::zero;
00093           mln_ch_value(I, L) output;
00094           initialize(output, input);
00095           data::fill(output, zero);
00096 
00097           // Loop.
00098           mln_piter(I) p(input.domain());
00099           for_all(p)
00100             if (input(p) && output(p) == zero) // Object point, not labeled yet.
00101               {
00102                 // Label this point component.
00103                 if (nlabels == mln_max(L))
00104                   {
00105                     trace::warning("labeling aborted! Too many labels \
00106 for this label type: nlabels > max(label_type).");
00107 
00108                     return output;
00109                   }
00110                 ++nlabels;
00111                 mln_invariant(qu.is_empty());
00112                 qu.push(p);
00113                 output(p) = nlabels;
00114                 do
00115                   {
00116                     cur = qu.front();
00117                     qu.pop();
00118                     for_all(n) if (input.has(n))
00119                       if (input(n) && output(n) == zero)
00120                         {
00121                           mln_invariant(! qu.compute_has(n));
00122                           qu.push(n);
00123                           output(n) = nlabels;
00124                         }
00125                   }
00126                 while (! qu.is_empty());
00127               }
00128 
00129           return output;
00130         }
00131 
00132       } // end of namespace mln::labeling::impl::generic
00133 
00134 
00135       template <typename I, typename N, typename L>
00136       mln_ch_value(I, L)
00137         blobs_(const I& input, const N& nbh, L& nlabels)
00138       {
00139         // The only implementation is the generic one.
00140         return generic::blobs_(input, nbh, nlabels);
00141       }
00142 
00143     } // end of namespace mln::labeling::impl
00144 
00145 
00146     // Facade.
00147 
00148     template <typename I, typename N, typename L>
00149     inline
00150     mln_ch_value(I, L)
00151     blobs(const Image<I>& input_, const Neighborhood<N>& nbh_,
00152           L& nlabels)
00153     {
00154       trace::entering("labeling::blobs");
00155       mlc_equal(mln_trait_image_kind(I),
00156                 mln::trait::image::kind::binary)::check();
00157       const I& input = exact(input_);
00158       const N& nbh = exact(nbh_);
00159       mln_precondition(input.is_valid());
00160 
00161       mln_ch_value(I, L) output = impl::blobs_(input, nbh, nlabels);
00162 
00163       trace::exiting("labeling::blobs");
00164       return output;
00165     }
00166 
00167 # endif // ! MLN_INCLUDE_ONLY
00168 
00169   } // end of namespace mln::labeling
00170 
00171 } // end of namespace mln
00172 
00173 
00174 #endif // ! MLN_LABELING_BLOBS_HH

Generated on Thu Sep 8 2011 18:31:33 for Milena (Olena) by  doxygen 1.7.1