---
milena/mln/inpainting/derivative_kernels.hh | 41 +++++++++++++++++++
milena/mln/inpainting/metric/tv_l2_norm.hh | 57 +++++++++++++++++++++++++++
milena/mln/inpainting/tv.hh | 35 ++--------------
3 files changed, 102 insertions(+), 31 deletions(-)
create mode 100644 milena/mln/inpainting/metric/tv_l2_norm.hh
diff --git a/milena/mln/inpainting/derivative_kernels.hh
b/milena/mln/inpainting/derivative_kernels.hh
index 04e1535..3e7bf63 100644
--- a/milena/mln/inpainting/derivative_kernels.hh
+++ b/milena/mln/inpainting/derivative_kernels.hh
@@ -1,6 +1,11 @@
#ifndef DERIVATIVE_KERNELS_HH_
# define DERIVATIVE_KERNELS_HH_
+#include <mln/core/alias/window2d.hh>
+#include <mln/core/concept/iterator.hh>
+#include <mln/convert/from_to.hh>
+#include <mln/literal/zero.hh>
+
namespace mln
{
namespace inpainting
@@ -97,7 +102,43 @@ namespace mln
return ws;
}
+
+ namespace internal
+ {
+ template <typename I>
+ void convolve(const I& src,
+ I& ima,
+ const float* kernel)
+ {
+ static window2d full3x3;
+ static const bool vals[] = { 1, 1, 1,
+ 1, 1, 1,
+ 1, 1, 1 };
+
+ convert::from_to(vals, full3x3);
+
+ mln_pixter(I) o(ima);
+ mln_pixter(const I) p(src);
+ mln_qixter(const I, const window2d) q(p, full3x3);
+
+ for_all_2 (p, o)
+ {
+ mln_value(I) accu = literal::zero;
+
+ unsigned k = 0;
+ for_all (q)
+ {
+ accu += q.val() * kernel[k];
+ ++k;
+ }
+
+ o.val() = accu;
+ }
+ }
+
+ }
}
}
+
#endif
diff --git a/milena/mln/inpainting/metric/tv_l2_norm.hh
b/milena/mln/inpainting/metric/tv_l2_norm.hh
new file mode 100644
index 0000000..17df267
--- /dev/null
+++ b/milena/mln/inpainting/metric/tv_l2_norm.hh
@@ -0,0 +1,57 @@
+#ifndef TV_L2_NORM_HH_
+# define TV_L2_NORM_HH_
+
+# include <mln/core/concept/image.hh>
+# include <mln/trait/value_.hh>
+# include <mln/algebra/vec.hh>
+
+# include <mln/inpainting/derivative_kernels.hh>
+
+namespace mln
+{
+ namespace inpainting
+ {
+ namespace metric
+ {
+ template <typename I, typename M>
+ double tv_l2_norm(const Image<I>& ima_,
+ const Image<M>& mask_)
+ {
+ I dx;
+ I dy;
+
+ const I& ima = exact(ima_);
+
+ initialize(dx, ima);
+ initialize(dy, ima);
+
+ internal::convolve(ima, dx, make_dx_kernel<float>());
+ internal::convolve(ima, dy, make_dy_kernel<float>());
+
+ mln_piter(I) p( dx.domain() );
+
+ double sum = 0;
+
+ const M& mask = exact(mask_);
+
+ for_all(p)
+ {
+ if (mask(p))
+ {
+ for (unsigned i = 0; i < mln_dim(mln_value(I)); ++i)
+ {
+ const float& a = dx(p)[i];
+ const float& b = dy(p)[i];
+
+ sum += std::sqrt(a * a + b * b);
+ }
+ }
+ }
+
+ return sum;
+ }
+ }
+ }
+}
+
+#endif
diff --git a/milena/mln/inpainting/tv.hh b/milena/mln/inpainting/tv.hh
index 3b38270..8c8066b 100644
--- a/milena/mln/inpainting/tv.hh
+++ b/milena/mln/inpainting/tv.hh
@@ -7,6 +7,7 @@
#include <mln/convert/from_to.hh>
#include <mln/norm/l1.hh>
#include <mln/norm/l2.hh>
+#include <mln/inpainting/metric/tv_l2_norm.hh>
#include <mln/inpainting/derivative_kernels.hh>
#include <mln/extension/adjust_duplicate.hh>
@@ -78,37 +79,6 @@ namespace mln
}
}
- template <typename I>
- void convolve(const I& src,
- I& ima,
- const float* kernel)
- {
- static window2d full3x3;
- static const bool vals[] = { 1, 1, 1,
- 1, 1, 1,
- 1, 1, 1 };
-
- convert::from_to(vals, full3x3);
-
- mln_pixter(I) o(ima);
- mln_pixter(const I) p(src);
- mln_qixter(const I, const window2d) q(p, full3x3);
-
- for_all_2 (p, o)
- {
- mln_value(I) accu = literal::zero;
-
- unsigned k = 0;
- for_all (q)
- {
- accu += q.val() * kernel[k];
- ++k;
- }
-
- o.val() = accu;
- }
- }
-
// debug
template <typename I, typename M>
void print_first_value(const I& src, const M& mask)
@@ -233,6 +203,9 @@ namespace mln
data::paste(u, old);
+ std::cout << iterations << "\t"
+ << metric::tv_l2_norm(u, mask) << std::endl;
+
++iterations;
}
--
1.7.2.5