Image Builder

Image Builder Objects

image builders follow the Named parameter Idiom and provides additional init parameters. Note that it may fail to fulfill the requirements, so a status code may be queried to check if everything succeeded.

struct image_build_params

Structure holding build parameters It is composed of two fields, a border value and an initialization value.

Public Members

int border = -1

Border value (-1 for non requested)

std::any init_value

Initialization value (can be empty)

template<class I, class From>
class image_builder : protected mln::details::image_builder_base

Provides advanced image initialization facilities.

An image builder objects is created when calling the concretize() or ch_value<T>() method of images (or the corresponding free functions mln::imconcretize and mln::imchvalue() ).

Public Functions

image_builder(const From &from)

Create a builder initializing from from.

image_builder(const From &from, const image_build_params &params)

Create a builder initializing from from, overrided by params.

inline image_builder &set_params(const image_build_params &params)

Override the initialization parameters with those from params.

inline image_builder &set_border(int border)

Override the initialization border parameter with border.

template<class SE>
inline image_builder &adjust(const SE &nbh)

Override the initialization border parameter to be at least the radial extent of nbh. If the radial extent is less than the current border initialization parameter, it has no effet.

inline image_builder &set_init_value(image_value_t<I> v)

Override the initialization value parameter with v.

inline image_builder &get_status(image_build_error_code *err)

Retrieve the error code in the variable pointed by err. If build() encounters an error, it will be set according to the error type.

I build() const

Build and return the new image.

inline operator I() const

Conversion operator. Alias for build() .

template<class To, class From>
class image_resizer : protected mln::details::image_builder_base

Provides advanced image resizing facilities.

See image_builder.

Public Functions

image_resizer(To &to, const From &from)

Create a builder initializing to from from.

image_resizer(To &to, const From &from, const image_build_params &params)

Create a builder initializing to from from, overrided by params.

inline image_resizer &set_params(const image_build_params &params)

Override the initialization parameters with those from params.

inline image_resizer &set_border(int border)

Override the initialization border parameter with border.

template<class SE>
inline image_resizer &adjust(const SE &nbh)

Override the initialization border parameter to be at least the radial extent of nbh. If the radial extent is less than the current border initialization parameter, it has no effet.

inline image_resizer &set_init_value(image_value_t<To> v)

Override the initialization value parameter with v.

inline image_resizer &get_status(image_build_error_code *err)

Retrieve the error code in the variable pointed by err. If build() encounters an error, it will be set according to the error type.

void resize() const

Resize the image.

inline ~image_resizer()

Resizing operator. Alias for resize() .

enum mln::image_build_error_code

Error code returned by image_builder or image_resizer.

Values:

enumerator IMAGE_BUILD_OK
enumerator IMAGE_BUILD_NO_BORDER
enumerator IMAGE_BUILD_UNSUPPORTED_SE

Free functions

template<class I>
auto mln::imconcretize(const I &ref)

Return an image builder for a concrete version of ref. This is an alias for ref.concretize().

template<typename V, class I>
auto mln::imchvalue(const I &ref)

Return an image builder for concrete version of ref able to store values of type V. This is an alias for ref.template ch_value<V>().

template<class To, class From>
image_resizer<To, From> mln::resize(To &to, const From &from)

Returns an image builder to resize the image to based on parameters of from.

Usage

This example shows how to create a temporary image with sufficient border to perform a stencil pattern (accessing the neighbors of a point).

auto myfunction(I f)
{
    // Try to adjust the border of the image to hold `nbh`
    // and initialize this image with the value `42`
    mln::image_build_error_code st;
    mln::concrete_t<I> g = imconcretize(f).adjust(nbh).set_init_value(42).get_status(st);
    if (st == mln::IMAGE_BUILD_OK)
    {
        mln_foreach(auto p, g.pixels())
            for (auto nx : nbh(px))
                // Process safely nx
    }
    else
    {
        // `g` has not a border large enough to hold the neighborhood.
        // You have to check that the access is valid when accessing the neighbors
        // of a point.
    }
}