Transform
Include <mln/core/algorithm/transform.hpp>
-
void transform(InputImage in, OutputImage out, std::UnaryFunction f)
-
void transform(InputImage in, OutputImage out, std::UnaryFunction f)
-
image_ch_value_t<InputImage, R> transform(InputImage in, std::UnaryFunction f)
Applies the function f to every value of in and stores the result in out.
Same as (1), but out is deduced from input with
R = std::decay_t<std::invoke_result_t<UnaryFunction, image_reference_t<InputImage>>>
.
This is equivalent to the following code:
for (auto&& [vin, vout] : ranges::zip(in.values(), out.values()) vout = f(vin);
This function has a parallel implementation, see following section for an example.
- Parameters:
in – The input image.
out – The output image.
f – The function to apply on values.
- Template Parameters:
InputImage – A model of
InputImage
OutputImage – A model of
OutputImage
Preconditions
in.domain() == out.domain()
(1)
Note
This function is intended for out-of-place computation. For in-place transformation, see
mln::for_each()
.
-
image_ch_value_t<InputImage, R> transform(InputImage in, std::UnaryFunction f)
Examples
Add one to the values of an image:
mln::image2d<uint8_t> ima = { {1, 2, 3}, {4, 5, 6} }; auto out = mln::transform(ima, [](uint8_t x) -> uint8_t { return x + 1; });
Get the first channel of a bi-band image:
using V = std::pair<uint8_t, uint8_t>; mln::image2d<V> ima = {{{1, 0}, {2, 0}, {3, 0}}, {{4, 0}, {5, 0}, {6, 0}}}; mln::image2d<uint8_t> out = mln::transform(ima, &V::first);
Using parallel transform to add one to the values of an image:
mln::image2d<uint8_t> ima = { {1, 2, 3}, {4, 5, 6} }; auto out = mln::parallel::transform(ima, [](uint8_t x) -> uint8_t { return x + 1; });
Complexity
Linear in the number of pixels.