Boost logo

Boost :

From: Lubomir Bourdev (lbourdev_at_[hidden])
Date: 2006-10-17 23:10:32


To demonstrate how GIL can be integrated with other imaging libraries, we decided to create two wrappers of imaging algorithms of another library and invoke them from GIL.
We picked Vigra as a test case.

Here is the full sample file:
http://opensource.adobe.com/gil/vigra_integration.cpp

Synopsis:

The first step is to provide metafunctions that map GIL view types to Vigra view types, as much as compatibility allows.
Then provide functions that create Vigra views from GIL views:

template <typename View> .
.. vigra_src_view(const View& view) {...}

template <typename View>
... vigra_dst_view(const View& view) {...}

Then provide wrappers of Vigra algorithms:

////////////////////////////////////////////
/// Vigra Algorithm wrappers
////////////////////////////////////////////

template <typename SrcView, typename DstView, typename GradValue, typename DestValue>
void canny_edge(const SrcView& src_view, const DstView& dst_view,
                double scale, GradValue gradient_threshold, DestValue edge_marker) {
    vigra::cannyEdgeImage(vigra_src_view(src_view), vigra_dst_view(dst_view), scale, gradient_threshold, edge_marker);
}

template <typename SrcView, typename DstView>
void gaussian_convolve_x(const SrcView& src_view, const DstView& dst_view, double std_dev) {
    vigra::Kernel1D<double> gauss;
    gauss.initGaussian(std_dev);
    separableConvolveX(vigra_src_view(src_view), vigra_dst_view(dst_view), kernel1d(gauss));
}

Finally this is how to invoke Vigra from GIL:

////////////////////////////////////////////
/// main
////////////////////////////////////////////

using namespace gil;

typedef gray8_image_t image_t;

int main() {

    image_t im_gray;
    jpeg_read_and_convert_image("test.jpg",im_gray);

    image_t result(get_dimensions(im_gray));

    image_t::pixel_t gray(channel_convert<image_t::view_t::channel_t>(0.5f));
    fill_pixels(view(result),gray);
    canny_edge(const_view(im_gray), view(result), 3.0, 5.0, 0);

    gaussian_convolve_x(const_view(result), view(result), 10);

    jpeg_write_view("test_out.jpg",color_converted_view<gray8_pixel_t>(view(result)));
    return 0;
}

/////////////////////////////////////////

Things work well only for 8-bit grayscale values. 16-bit gray sort of works ok, perhaps the only difference is the need to use different settings.
If I use RGB values, however, canny_edge does not compile, and the Gaussian convolution returns the result in grayscale.
Other color spaces, channel depths and planar images I am not sure how to set up.

Perhaps I am not using Vigra properly. Prof. Köthe could you take a look at my source file (link above) and let me know if it looks OK?

Thanks,
Lubomir


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk