Convolution (XForms (Forms Library) - Version 1.2 (Rev. 4) A Graphical User Interface Toolkit for X)

Next: Tint, Up: Simple Image Processing [Contents][Index]

#### 37.7.1 Convolution

Convolution or filtering can be done easily using the following routine

    int flimage_convolve(FL_IMAGE *im, int **kernel,
                         int krow, int kcol);

This function takes a convolution kernel of `krow` by `kcol` and convolves it with the image. The result replaces the input image. The kernel size should be odd. If successful, the function returns a positive integer, otherwise a negative number. The kernel should be allocated by `fl_get_matrix()`. To use a kernel that’s a C 2-dimensional array (cast to a pointer to int), use the following function

    int flimage_convolvea(FL_IMAGE *im, int *kernel,
                          int krow, int kcol);

The difference between these two functions is in their usage syntax:

    int **kernel1 = fl_get_matrix(sizeof **kernel, n, m);
    int kernel2[n][m];
    kernel1[x][y] = z;
    kernel2[x][y] = z;
    flimage_convolve(im, kernel1, n, m);
    flimage_convolvea(im, (int*) kernel2, n, m); /* note the cast */

Two special built-in kernels are designated with the following symbolic constants

`FLIMAGE_SMOOTH`

  indicates a 3 by 3 smoothing kernel

`FLIMAGE_SHARPEN`

  indicates a 3 by 3 sharpening kernel