Interfaces » DIPlib-Vigra interface module

Functions to convert images to and from Vigra.

Contents

The dip_vigra namespace defines the functions needed to convert between Vigra vigra::MultiArray and vigra::MultiArrayView objects and DIPlib dip::Image objects.

The function dip_vigra::VigraToDip encapsulates (maps) a Vigra image in a DIPlib image; dip_vigra::DipToVigra does the opposite, mapping a DIPlib image as a Vigra image.

Vigra supports anything as pixel type, but in order for the code written here to be manageable, these types must be limited. Pixel types are therefore limited to the numeric types supported by DIPlib as well as vectors of arbitrary length of these numeric types. DIPlib tensor images are mapped to Vigra vector images, but the tensor shape is lost. Note that the tensor stride must always be 1. Use dip::Image::ForceNormalStrides to fix the tensor stride for mapping. Alternatively, use dip_vigra::CopyDipToVigra.

Vigra seems to prefer to use the 8-bit unsigned integer type for binary images. These are always converted to dip::DT_UINT8 images, as the code here cannot distinguish between binary and non-binary images. Use dip::Convert to cast the resulting image to binary.

Because Vigra defines image properties through template parameters (data type and dimensionality), it is not possible to write a non-templated function that creates a vigra::MultiArray object. Consequently, a dip::ExternalInterface would be very limited in usefulness, so we don’t define one. The DIPlib-Vigra interface is therefore less easy to use than, for example, the DIPlib-OpenCV interface.

Namespaces

namespace dip_vigra
The dip_vigra namespace contains the interface between Vigra and DIPlib.

Functions

template<unsigned int Dimensionality, typename PixelType, typename StrideTag>
auto dip_vigra::VigraToDip(vigra::MultiArrayView<Dimensionality, PixelType, StrideTag> const& input) -> dip::Image
Creates a DIPlib image around a Vigra vigra::MultiArrayView, without taking ownership of the data.
template<unsigned int Dimensionality, typename PixelType>
auto dip_vigra::DipToVigra(dip::Image const& img) -> vigra::MultiArrayView<Dimensionality, PixelType, vigra::StridedArrayTag>
Creates a Vigra vigra::MultiArrayView object around a DIPlib image, without taking ownership of the data.
template<unsigned int Dimensionality, typename PixelType>
auto dip_vigra::CopyDipToVigra(dip::Image const& img) -> vigra::MultiArray<Dimensionality, PixelType>
Creates a Vigra vigra::MultiArrayView object from a DIPlib image by copy.

Function documentation

template<unsigned int Dimensionality, typename PixelType, typename StrideTag>
dip::Image dip_vigra::VigraToDip(vigra::MultiArrayView<Dimensionality, PixelType, StrideTag> const& input)

Creates a DIPlib image around a Vigra vigra::MultiArrayView, without taking ownership of the data.

This function maps a vigra::MultiArrayView object to a dip::Image object. The dip::Image object will point to the data in the vigra::MultiArrayView, which must continue existing until the dip::Image is deleted or stripped. The output dip::Image is protected to prevent accidental reforging, unprotect it using dip::Image::Protect.

An invalid vigra::MultiArrayView produces a non-forged dip::Image.

The template parameters do not need to be explicitly given, as the input object defines them.

template<unsigned int Dimensionality, typename PixelType>
vigra::MultiArrayView<Dimensionality, PixelType, vigra::StridedArrayTag> dip_vigra::DipToVigra(dip::Image const& img)

Creates a Vigra vigra::MultiArrayView object around a DIPlib image, without taking ownership of the data.

This function maps a dip::Image object to a vigra::MultiArrayView object. The vigra::MultiArrayView object will point to the data in the dip::Image, which must continue existing until the vigra::MultiArrayView is deleted.

A non-forged dip::Image produces an invalid vigra::MultiArrayView.

Note that it is required to set the two template parameters, and that these template parameters must match the the dip::Image object at runtime.

template<unsigned int Dimensionality, typename PixelType>
vigra::MultiArray<Dimensionality, PixelType> dip_vigra::CopyDipToVigra(dip::Image const& img)

Creates a Vigra vigra::MultiArrayView object from a DIPlib image by copy.

A non-forged dip::Image produces an invalid vigra::MultiArrayView.

Use this function if the dip::Image cannot be mapped with dip_vigra::DipToVigra, for example if the data type doesn’t match (or you don’t know in advance what data type the DIPlib image will have) or if the tensor stride is not 1.

Note that it is required to set the two template parameters, and that the Dimensionality must match the dip::Image object at runtime. If the PixelType doesn’t match, the sample values will be converted in the same way that dip::Image::Copy does.