00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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 
00049 
00050 
00051 namespace mln
00052 {
00053 
00054   namespace morpho
00055   {
00056 
00059     
00060 
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       
00076       util::graph g;
00077 
00078       
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       
00093       
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             
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   } 
00121 
00122 } 
00123 
00124 
00125 #endif // ! MLN_MORPHO_LINE_GRADIENT_HH