#ifndef MLN_CORE_ALGORITHM_TRANSFORM_HPP # define MLN_CORE_ALGORITHM_TRANSFORM_HPP # include /// \file namespace mln { /// \ingroup Algorithms /// \brief Transform the value of an image through a function. /// /// This is equivalent to the following code. /// \code /// mln_iter(vout, out.values()) /// mln_iter(vin, in.values()) /// mln_forall(vin, vout) /// *vout = f(*vin) /// /// \endcode /// /// \tparam InputImage A model of :concept:ref:`forward_image` /// \tparam OutputImage A model of Writable :concept:ref:`forward_image` /// \tparam UnaryFunction A mondel of unary function. /// \param input The input image. /// \param f The unary function. /// \param output The output image. /// \see mln::imtransform template OutputImage& transform(const Image& input, UnaryFunction f, Image& output); /// \overload template OutputImage&& transform(const Image& input, UnaryFunction f, Image&& output); template unary_image_expr lazy_transform(InputImage&& input, UnaryFunction f); /// \overload template mln_ch_value(InputImage, typename std::decay< typename std::result_of::type >::type) transform(const Image& input, UnaryFunction f); /******************************************/ /**** Implementation ****/ /******************************************/ namespace impl { template void transform(const I& input, UnaryFunction f, J& output) { mln_viter(vin, vout, input, output); mln_forall(vin, vout) *vout = f(*vin); } } template OutputImage& transform(const Image& input, UnaryFunction f, Image& output) { OutputImage& out = exact(output); impl::transform(exact(input), f, exact(output)); return out; } template OutputImage&& transform(const Image& input, UnaryFunction f, Image&& output) { mln::transform(input, f, output); return move_exact(output); } template mln_ch_value(InputImage, typename std::decay< typename std::result_of::type >::type) transform(const Image& input, UnaryFunction f) { typedef typename std::decay< typename std::result_of::type >::type T; mln_ch_value(InputImage, T) out; resize(out, input); mln::transform(input, f, out); return out; } template unary_image_expr lazy_transform(InputImage&& input, UnaryFunction f) { return make_unary_image_expr(std::forward(input), f); } } #endif // ! MLN_CORE_ALGORITHM_TRANSFORM_HPP