
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2008-03-19 Caroline Vigouroux <vigour_c@epita.fr> rms. * moyenne.cc: rms. --- moyenne.cc | 79 ++++++++++++++++++------------------------------------------- 1 file changed, 24 insertions(+), 55 deletions(-) Index: trunk/milena/sandbox/vigouroux/moyenne.cc =================================================================== --- trunk/milena/sandbox/vigouroux/moyenne.cc (revision 1788) +++ trunk/milena/sandbox/vigouroux/moyenne.cc (revision 1789) @@ -1,5 +1,3 @@ -#include <mln/core/image2d.hh> -#include <mln/value/int_u8.hh> #include "color/my_hsi.hh" #include "color/rgb_to_hsi.hh" #include <mln/display/save_and_show.hh> @@ -11,68 +9,36 @@ #include <mln/math/round.hh> #include <mln/level/transform.hh> -#include <mln/core/w_window2d_float.hh> -#include <mln/border/thickness.hh> -#include <mln/linear/convolve.hh> - -# include <mln/display/save.hh> -# include <mln/display/show.hh> - #include <mln/core/image2d.hh> -#include <mln/win/rectangle2d.hh> -#include <mln/make/pixel.hh> #include <cmath> #include <iostream> -// template <typename I, typename O, typename W> -// float moyenne (I& ima, O& out, W& win) -// { -// mln::value::rgb8 c2; -// mln_piter(I) p(out.domain()); -// mln_qixter(I, W) q(ima, win, p); -// for_all(p) -// { -// for_all(q) -// { -// q.val() -// } -// out(p) = c2; -// } - -// return (); -// } - -template <typename I, typename O, typename W> -float moyenne (I& ima, O& out, W& win) +template <typename I, typename O> +float rms (const I& ima, O& out) { - mln::value::hsi_3x8 c_hsi; + mln::value::rgb8 c1; mln::value::rgb8 c2; float distred = 0; float distgreen = 0; float distblue = 0; float sum = 0; - float nb_ct = 0; + float nb = 0; float moy = 0; mln_piter(I) p(out.domain()); - mln_qixter(I, W) q(ima, win, p); for_all(p) { - for_all(q) - { - c_hsi = mln::fun::v2v::f_rgb_to_hsi_3x8(q.val()); - c2 = mln::fun::v2v::f_hsi_to_rgb_3x8(c_hsi); - distred = c2.red() - q.val().red(); - distgreen = c2.green() - q.val().green(); - distblue = c2.blue() - q.val().blue(); - } - nb_ct += 3; + c1 = ima(p); + c2 = out(p); + distred = c2.red() - c1.red(); + distgreen = c2.green() - c1.green(); + distblue = c2.blue() - c1.blue(); + + ++nb; sum += distred * distred + distblue * distblue + distgreen * distgreen; - out(p) = c2; } - moy = sqrt(sum / nb_ct); - std::cout << "nb_point: " << nb_ct / 3 << std::endl; + moy = std::sqrt(sum / nb); return (moy); } @@ -80,18 +46,21 @@ { using namespace mln; using value::int_u8; - image2d<mln::value::rgb8> lena; + image2d<value::rgb8> lena; io::ppm::load(lena, "../../img/lena.ppm"); - image2d<mln::value::hsi_3x8> inter(lena.domain()); - image2d<mln::value::rgb8> out(lena.domain()); - const image2d<mln::value::rgb8> input = exact(lena); - float lol; - win::rectangle2d rect(3, 3); - lol = moyenne(input, out, rect); + image2d<value::hsi_3x8> lena_hsi = level::transform(lena, + fun::v2v::f_rgb_to_hsi_3x8); + + image2d<value::rgb8> lena_rgb = level::transform(lena_hsi, + fun::v2v::f_hsi_to_rgb_3x8); + + + float err = rms(lena, lena_rgb); - std::cout << "moyenne: " << lol << std::endl; + std::cout << "err: " << err << std::endl; - display::save_and_show (out, "display", 50); + display::save_and_show (lena_rgb, "display", 50); + return (0); }
participants (1)
-
Caroline Vigouroux