
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Fix conversion problems in linear::gaussian. * tests/linear/gaussian.cc: Update tests. * mln/linear/gaussian.hh: Fix conversion issues. * doc/tutorial/design/include/imagetours.tex: Update documentation. doc/tutorial/design/include/imagetours.tex | 17 +++----- mln/linear/gaussian.hh | 61 +++++++++++++++++++++++++---- tests/linear/gaussian.cc | 7 +++ 3 files changed, 68 insertions(+), 17 deletions(-) Index: tests/linear/gaussian.cc --- tests/linear/gaussian.cc (revision 2840) +++ tests/linear/gaussian.cc (working copy) @@ -38,6 +38,7 @@ #include <mln/io/pgm/save.hh> #include <mln/level/transform.hh> +#include <mln/level/paste.hh> #include <mln/math/round.hh> #include <mln/linear/gaussian.hh> @@ -57,4 +58,10 @@ image2d<value::int_u8> out = linear::gaussian(lena, 5.1f); io::pgm::save(out, "out.pgm"); + + + image2d<float> lenaf(lena.domain()); + level::paste(lena, lenaf); + + image2d<float> outf = linear::gaussian(lenaf, 5.1f); } Index: doc/tutorial/design/include/imagetours.tex --- doc/tutorial/design/include/imagetours.tex (revision 2840) +++ doc/tutorial/design/include/imagetours.tex (working copy) @@ -34,16 +34,15 @@ In the Milena library, an image can be seen as an application $site$ to $value$. A $site$ is a localized object in space. -Points in $1D$, $2D$ or $3D$, are the sites objects commonly used in the +Points $1D$, $2D$ or $3D$ are the sites objects commonly used in the library. -However, the $site$ concept allows Milena to deal with complicated image type -(for instance see the \verb+graph_image+ type). +%%However, the $site$ concept allows Milena to deal with complicated image type +%%(for instance see the \verb+graph_image+ type). -So, an image is composed by a set of localized objects, $sites$, that -compose the definition domain of the image. +An image is composed by a set of localized objects ($sites$): the definition domain of the image. A value is associated to each site of the image. This is the destination domain of the image. -To access to a value of an image named $ima$ localized at the point p, we +To access to a value localized at the site p in an image named $ima$, we just use the mathematics notation: \verb+ima(p)+. Obviously, every image types of Milena provide an access $site$ to $value$, @@ -65,11 +64,11 @@ In this document, we will used the following naming convention for the image types parameters: \begin{itemize} -\item{\verb+T+:} represents an image value type. -\item{\verb+S+:} represents a type of a $sites$ set. +\item{\verb+T+:} represents an image $value$ type. +\item{\verb+S+:} represents a type of a $sites$ $set$ type. \item{\verb+F+:} is a type of a function $site$ to $value$. \item{\verb+P+:} represents a $site$ type. -\item{\verb+I+:} represents an image type. +\item{\verb+I+:} represents an $image$ type. \end{itemize} \subsection{Primary images} Index: mln/linear/gaussian.hh --- mln/linear/gaussian.hh (revision 2840) +++ mln/linear/gaussian.hh (working copy) @@ -470,7 +470,7 @@ template <class I, class F, class O> inline void - generic_filter_common_(trait::value::nature::scalar, + generic_filter_common_(trait::value::nature::floating, const Image<I>& in, const F& coef, float sigma, @@ -487,15 +487,14 @@ generic_filter_(mln_trait_image_dimension(I)(), work_img, coef, i); - // FIXME deal with overflow problem - // for instance, when we paste a float image into a int_u8 images. + // We don't need to convert work_img level::paste(work_img, out); } template <class I, class F, class O> inline void - generic_filter_common_(trait::value::nature::scalar, + generic_filter_common_(trait::value::nature::floating, const Image<I>& in, const F& coef, float sigma, @@ -512,12 +511,60 @@ generic_filter_(mln_trait_image_dimension(I)(), work_img, coef, dir); - // FIXME deal with overflow problem - // for instance, when we paste a float image into a int_u8 images. + // We don't need to convert work_img level::paste(work_img, out); } + template <class I, class F, class O> + inline + void + generic_filter_common_(trait::value::nature::scalar, + const Image<I>& in, + const F& coef, + float sigma, + Image<O>& out) + { + mln_ch_value(O, float) work_img(exact(in).domain()); + level::paste(in, work_img); + extension::adjust_fill(work_img, 4, 0); + + // On tiny sigma, Derich algorithm doesn't work. + // It is the same thing that to convolve with a Dirac. + if (sigma > 0.006) + for (int i = 0; i < I::site::dim; ++i) + generic_filter_(mln_trait_image_dimension(I)(), + work_img, coef, i); + + // Convert work_img into result type + level::paste(level::stretch(mln_value(I)(), work_img), out); + } + + template <class I, class F, class O> + inline + void + generic_filter_common_(trait::value::nature::scalar, + const Image<I>& in, + const F& coef, + float sigma, + Image<O>& out, + int dir) + { + mln_ch_value(O, float) work_img(exact(in).domain()); + level::paste(in, work_img); + extension::adjust_fill(work_img, 4, 0); + + // On tiny sigma, Derich algorithm doesn't work. + // It is the same thing that to convolve with a Dirac. + if (sigma > 0.006) + generic_filter_(mln_trait_image_dimension(I)(), + work_img, coef, dir); + + // Convert work_img into result type + level::paste(level::stretch(mln_value(I)(), work_img), out); + } + + template <class I, class F, class O> inline @@ -565,10 +612,8 @@ } // end of namespace mln::linear::impl - // Facade. - /*! Apply an approximated gaussian filter of \p sigma on \p input. * on a specific direction \p dir * if \p dir = 0, the filter is applied on the first image dimension.