Add a first version of iterative seam carving.
[seam-carving.git] / src / nrg.cc
blobbcb925cbf904d875a429396117647f3d591914a5
1 #include <mln/core/dpoint2d.hh>
2 #include <mln/norm/l2.hh>
4 #include "all.hh"
6 using namespace mln;
8 static inline
9 float
10 get_local_nrg (const image2d<rgb8>& i, const point2d& p)
12 using norm::l2_distance;
13 typedef metal::vec<3u, float> vec_t;
14 vec_t l = i (p + left).to_equiv ();
15 vec_t r = i (p + right).to_equiv ();
16 vec_t u = i (p + up).to_equiv ();
17 vec_t d = i (p + down).to_equiv ();
18 return l2_distance (l, r) + l2_distance (u, d);
21 image2d<float> get_nrg (const image2d<rgb8>& img)
23 image2d<float> nrg (img.domain ());
24 image2d<rgb8>::fwd_piter p (img.domain ());
26 for_all (p)
27 nrg (p) = get_local_nrg (img, p);
28 return nrg;