
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-09-12 Simon Nivault <simon.nivault@lrde.epita.fr> Add approx median for disk and octogon * mln/level/approx/median.hh: Update. * tests/level_approx_median.cc: Update. --- mln/level/approx/median.hh | 87 +++++++++++++++++++++++++++++++++++++++---- tests/level_approx_median.cc | 5 +- 2 files changed, 84 insertions(+), 8 deletions(-) Index: trunk/milena/tests/level_approx_median.cc =================================================================== --- trunk/milena/tests/level_approx_median.cc (revision 1104) +++ trunk/milena/tests/level_approx_median.cc (revision 1105) @@ -32,6 +32,7 @@ #include <mln/core/image2d_b.hh> #include <mln/core/win/rectangle2d.hh> +#include <mln/core/win/octagon2d.hh> #include <mln/io/pgm/load.hh> #include <mln/io/pgm/save.hh> @@ -48,12 +49,14 @@ using value::int_u8; win::rectangle2d rect(51, 51); + win::octagon2d oct(13); border::thickness = 52; image2d_b<int_u8> lena = io::pgm::load("../img/lena.pgm"), out(lena.domain()); - level::approx::median(lena, rect, out); +// level::approx::median(lena, rect, out); + level::approx::median(lena, oct, out); io::pgm::save(out, "out.pgm"); } Index: trunk/milena/mln/level/approx/median.hh =================================================================== --- trunk/milena/mln/level/approx/median.hh (revision 1104) +++ trunk/milena/mln/level/approx/median.hh (revision 1105) @@ -35,7 +35,12 @@ # include <mln/level/median.hh> # include <mln/core/win/rectangle2d.hh> - +# include <mln/core/win/disk2d.hh> +# include <mln/core/win/octagon2d.hh> +# include <mln/core/win/hline2d.hh> +# include <mln/core/win/vline2d.hh> +# include <mln/core/win/diag2d.hh> +# include <mln/core/win/backdiag2d.hh> namespace mln { @@ -62,9 +67,66 @@ void median(const Image<I>& input, const win::rectangle2d& win, Image<O>& output); + /*! Compute in \p output an approximate of the median filter of + * image \p input by the 2D disk \p win. + * + * \param[in] input The image to be filtered. + * \param[in] win The disk. + * \param[in,out] output The output image. + * + * The approximation is based on a vertical median and + * an horizontal median an two diagonal median. + * + * \pre \p input and \p output have to be initialized. + */ + template <typename I, typename O> + void median(const Image<I>& input, const win::disk2d& win, + Image<O>& output); + + /*! Compute in \p output an approximate of the median filter of + * image \p input by the 2D octagon \p win. + * + * \param[in] input The image to be filtered. + * \param[in] win The octagon. + * \param[in,out] output The output image. + * + * The approximation is based on a vertical median and + * an horizontal median an two diagonal median. + * + * \pre \p input and \p output have to be initialized. + */ + template <typename I, typename O> + void median(const Image<I>& input, const win::octagon2d& win, + Image<O>& output); + # ifndef MLN_INCLUDE_ONLY + namespace impl + { + + template <typename I, typename O> + void median_(const I& input, const unsigned length, + O& output) + { + const unsigned len = length / 3 + 1; + + O + tmp1(output.domain()), + tmp2(output.domain()); + + level::median(input, win::hline2d(len), tmp1); + level::median(tmp1, win::vline2d(len), tmp2); + level::median(tmp2, win::diag2d(len), tmp1); + level::median(tmp1, win::backdiag2d(len), output); + + } + + } // end of namespace mln::level::approx::impl + + + // Facades. + template <typename I, typename O> void median(const Image<I>& input_, const win::rectangle2d& win, Image<O>& output_) @@ -78,12 +140,23 @@ level::median(tmp, win::vline2d(win.height()), output); } -// template <typename I, typename O> -// void median(const Image<I>& input_, const win::disk2d& win, -// Image<O>& output_) -// { -// // todo simon -// } + template <typename I, typename O> + void median(const Image<I>& input, const win::disk2d& win, + Image<O>& output) + { + mln_assertion(exact(output).domain() == exact(input).domain()); + + impl::median_(exact(input), win.length(), exact(output)); + } + + template <typename I, typename O> + void median(const Image<I>& input, const win::octagon2d& win, + Image<O>& output) + { + mln_assertion(exact(output).domain() == exact(input).domain()); + + impl::median_(exact(input), win.length(), exact(output)); + } # endif // ! MLN_INCLUDE_ONLY