---
.../mln/inpainting/metric/mean_gradient_error.hh | 75 ++++++++++++++++++++
milena/mln/inpainting/metric/mean_l1_error.hh | 57 +++++++++++++++
milena/mln/inpainting/metric/{psnr.hh => mse.hh} | 23 ++----
milena/mln/inpainting/metric/psnr.hh | 29 +-------
4 files changed, 144 insertions(+), 40 deletions(-)
create mode 100644 milena/mln/inpainting/metric/mean_gradient_error.hh
create mode 100644 milena/mln/inpainting/metric/mean_l1_error.hh
copy milena/mln/inpainting/metric/{psnr.hh => mse.hh} (60%)
diff --git a/milena/mln/inpainting/metric/mean_gradient_error.hh
b/milena/mln/inpainting/metric/mean_gradient_error.hh
new file mode 100644
index 0000000..05e1b2c
--- /dev/null
+++ b/milena/mln/inpainting/metric/mean_gradient_error.hh
@@ -0,0 +1,75 @@
+#ifndef MEAN_GRADIENT_ERROR_HH_
+# define MEAN_GRADIENT_ERROR_HH_
+
+# include <mln/core/concept/image.hh>
+# include <mln/norm/l1.hh>
+# include <mln/trait/value_.hh>
+# include <mln/algebra/vec.hh>
+# include <mln/linear/gaussian.hh>
+
+#include <mln/core/image/dmorph/image_if.hh>
+#include <mln/pw/value.hh>
+
+# include <mln/data/compute.hh>
+# include <mln/data/transform.hh>
+# include <mln/fun/vv2v/diff_abs.hh>
+# include <mln/accu/math/sum.hh>
+
+# include <mln/inpainting/tv.hh>
+
+namespace mln
+{
+ namespace inpainting
+ {
+ namespace metric
+ {
+ template <typename I, typename M>
+ float mean_gradient_error(const Image<I>& original_,
+ const Image<I>& altered_,
+ const Image<M>& mask_)
+ {
+ I original_dx;
+ I original_dy;
+ I altered_dx;
+ I altered_dy;
+
+ initialize(original_dx, exact(original_));
+ initialize(original_dy, exact(original_));
+ initialize(altered_dx, exact(original_));
+ initialize(altered_dy, exact(original_));
+
+ internal::convolve(exact(original_), original_dx, make_dx_kernel<float>());
+ internal::convolve(exact(altered_), altered_dx, make_dx_kernel<float>());
+ internal::convolve(exact(original_), original_dy, make_dy_kernel<float>());
+ internal::convolve(exact(altered_), altered_dy, make_dy_kernel<float>());
+
+ unsigned card = 0;
+
+ mln_piter(I) p( original_dx.domain() );
+
+ float error = 0;
+
+ const M& mask = exact(mask_);
+
+ for_all(p)
+ {
+ if (mask(p))
+ {
+ const mln_value(I) diff = original_dx(p) + original_dy(p)
+ - (altered_dx(p) + altered_dy(p));
+
+ for (unsigned i = 0; i < mln_dim(mln_value(I)); ++i)
+ error += std::abs(diff[i]);
+
+ ++card;
+ }
+ }
+
+ return error / (card * mln_dim(mln_value(I)));
+ }
+ }
+ }
+}
+
+
+#endif
diff --git a/milena/mln/inpainting/metric/mean_l1_error.hh
b/milena/mln/inpainting/metric/mean_l1_error.hh
new file mode 100644
index 0000000..f5caa90
--- /dev/null
+++ b/milena/mln/inpainting/metric/mean_l1_error.hh
@@ -0,0 +1,57 @@
+#ifndef MEAN_L1_ERROR_HH_
+# define MEAN_L1_ERROR_HH_
+
+# include <mln/core/concept/image.hh>
+# include <mln/norm/l1.hh>
+# include <mln/trait/value_.hh>
+# include <mln/algebra/vec.hh>
+
+# include <mln/data/compute.hh>
+# include <mln/accu/math/sum.hh>
+
+#include <mln/core/image/dmorph/image_if.hh>
+#include <mln/pw/value.hh>
+
+namespace mln
+{
+ namespace inpainting
+ {
+ namespace metric
+ {
+ template <typename I, typename M>
+ float mean_l1_error(const Image<I>& original_,
+ const Image<I>& altered_,
+ const Image<M>& mask_)
+ {
+ const I& original = exact(original_);
+ const I& altered = exact(altered_);
+ const M& mask = exact(mask_);
+
+ mln_piter(I) p( original.domain() );
+
+ unsigned card = 0;
+
+ float error = 0;
+
+ for_all(p)
+ {
+ if (mask(p))
+ {
+ const mln_value(I) diff = original(p) - altered(p);
+
+ for (unsigned i = 0; i < mln_dim(mln_value(I)); ++i)
+ {
+ error += std::abs(diff[i]);
+ }
+
+ ++card;
+ }
+ }
+
+ return error / (card * mln_dim(mln_value(I)));
+ }
+ }
+ }
+}
+
+#endif
diff --git a/milena/mln/inpainting/metric/psnr.hh b/milena/mln/inpainting/metric/mse.hh
similarity index 60%
copy from milena/mln/inpainting/metric/psnr.hh
copy to milena/mln/inpainting/metric/mse.hh
index 5dd8fdd..0c09252 100644
--- a/milena/mln/inpainting/metric/psnr.hh
+++ b/milena/mln/inpainting/metric/mse.hh
@@ -1,7 +1,5 @@
-#ifndef MLN_INPAINTING_METRIC_PSNR_HH
-# define MLN_INPAINTING_METRIC_PSNR_HH
-
-# include <cmath>
+#ifndef MSE_HH_
+# define MSE_HH_
# include <mln/core/concept/image.hh>
# include <mln/norm/l1.hh>
@@ -15,7 +13,7 @@ namespace mln
namespace metric
{
template <typename I, typename I2>
- double psnr(const Image<I>& original_,
+ double mse(const Image<I>& original_,
const Image<I2>& altered_)
{
const I& original = exact(original_);
@@ -32,21 +30,16 @@ namespace mln
for_all(p)
{
const mln_sum(mln_value(I)) diff = original(p) - altered(p);
-
- if (dim == 1)
- mse += diff * diff;
- else
- for (unsigned i = 0; i < dim; ++i)
- mse += diff[i] * diff[i];
+
+ for (unsigned i = 0; i < dim; ++i)
+ mse += diff[i] * diff[i];
++nelements;
}
- mse /= ( nelements * dim);
-
- const unsigned max = pow(2, mln_nbits(mln_value(I)) / dim) - 1;
+ mse /= (nelements * dim);
- return 20 * log10( max ) - 10 * log10(mse);
+ return mse;
}
}
}
diff --git a/milena/mln/inpainting/metric/psnr.hh b/milena/mln/inpainting/metric/psnr.hh
index 5dd8fdd..3a97fb0 100644
--- a/milena/mln/inpainting/metric/psnr.hh
+++ b/milena/mln/inpainting/metric/psnr.hh
@@ -4,9 +4,10 @@
# include <cmath>
# include <mln/core/concept/image.hh>
-# include <mln/norm/l1.hh>
+
+# include <mln/inpainting/metric/mse.hh>
+
# include <mln/trait/value_.hh>
-# include <mln/algebra/vec.hh>
namespace mln
{
@@ -18,32 +19,10 @@ namespace mln
double psnr(const Image<I>& original_,
const Image<I2>& altered_)
{
- const I& original = exact(original_);
- const I2& altered = exact(altered_);
-
- mln_piter(I) p( altered.domain() );
-
- double mse = 0;
+ double mse = metric::mse(original_, altered_);
const unsigned dim = mln_dim(mln_value(I));
-
- unsigned nelements = 0;
-
- for_all(p)
- {
- const mln_sum(mln_value(I)) diff = original(p) - altered(p);
-
- if (dim == 1)
- mse += diff * diff;
- else
- for (unsigned i = 0; i < dim; ++i)
- mse += diff[i] * diff[i];
-
- ++nelements;
- }
- mse /= ( nelements * dim);
-
const unsigned max = pow(2, mln_nbits(mln_value(I)) / dim) - 1;
return 20 * log10( max ) - 10 * log10(mse);
--
1.7.2.5
Show replies by date