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

line_gradient.hh

00001 // Copyright (C) 2008, 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_LINE_GRADIENT_HH
00027 # define MLN_MORPHO_LINE_GRADIENT_HH
00028 
00032 
00033 # include <functional>
00034 
00035 # include <map>
00036 # include <vector>
00037 
00038 # include <mln/math/abs.hh>
00039 
00040 # include <mln/core/image/image2d.hh>
00041 # include <mln/core/image/edge_image.hh>
00042 # include <mln/core/alias/window2d.hh>
00043 
00044 # include <mln/util/graph.hh>
00045 # include <mln/util/site_pair.hh>
00046 
00047 
00048 // FIXME: Generalize to other (input) images as well (image1d,
00049 // image3d, etc.).
00050 
00051 namespace mln
00052 {
00053 
00054   namespace morpho
00055   {
00056 
00059     /* FIXME: Currently, the adjacency is set to 4-c and cannot be
00060        changed.  */
00061     template <typename V>
00062     edge_image<util::site_pair<point2d>, V, util::graph>
00063     line_gradient(const mln::image2d<V>& ima);
00064 
00065 
00066 # ifndef MLN_INCLUDE_ONLY
00067 
00068     template <typename V>
00069     edge_image<util::site_pair<point2d>, V, util::graph>
00070     line_gradient(const mln::image2d<V>& ima)
00071     {
00072       trace::entering("morpho::line_gradient");
00073       mln_precondition(ima.is_valid());
00074 
00075       // FIXME: Precondition: Ensure the image is scalar.
00076       util::graph g;
00077 
00078       // Vertices.
00079       image2d<unsigned> vpsite(ima.domain());
00080       fun::i2v::array<point2d> fv2p(ima.domain().nsites());
00081       fun::i2v::array<V> vertex_values(ima.domain().nsites());
00082 
00083       mln_fwd_piter(image2d<V>) p(ima.domain());
00084       for_all (p)
00085       {
00086         g.add_vertex();
00087         unsigned id = g.v_nmax() - 1;
00088         vpsite(p) = id;
00089         fv2p(id) = p;
00090       }
00091 
00092       // Edges.
00093       // FIXME: The creation of this window should be generic.
00094       window2d next_c4_win;
00095       next_c4_win.insert(0, 1).insert(1, 0);
00096       typedef fun::i2v::array<V> edge_values_t;
00097       typedef fun::i2v::array< util::site_pair<point2d> > edge_sites_t;
00098       edge_values_t edge_values;
00099       edge_sites_t edge_sites;
00100       mln_fwd_qiter_(window2d) q(next_c4_win, p);
00101       for_all (p)
00102         for_all (q)
00103         if (ima.domain().has(q))
00104           {
00105             g.add_edge(vpsite(p), vpsite(q));
00106             // The computed value is a norm of the gradient between P and Q.
00107             edge_values.append(math::abs(ima(p) - ima(q)));
00108             edge_sites.append(util::site_pair<point2d>(p, q));
00109           }
00110 
00111       edge_image<util::site_pair<point2d>, V, util::graph>
00112         lg_ima(g, edge_sites, edge_values);
00113 
00114       trace::exiting("morpho::line_gradient");
00115       return lg_ima;
00116     }
00117 
00118 # endif // ! MLN_INCLUDE_ONLY
00119 
00120   } // end of namespace mln::morpho
00121 
00122 } // end of namespace mln
00123 
00124 
00125 #endif // ! MLN_MORPHO_LINE_GRADIENT_HH

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