User Tools

Site Tools


jvs:cigal:manual:chapter3:convolve

CIGAL Reference Manual, Chapter 3 (Functions): CONVOLVE

CONVOLVE -- Convolve a variable using a kernel matrix

usage: vdst = convolve(vsrc,kernel_matrix,offset,minval,maxval,shift)

A convolution involves calculating a new value for each data element based upon the intensities of the surrounding elements. A 'kernel' matrix determines the way in which the neighboring data contribute to this calculation.

The data in variable VSRC are convolved into the variable VDST. VSRC and VDST must have the same dimensions. In addition, both VSRC and VDST must be two-dimensional variables (eg., type IMAGE or MATRIX) with word sizes that are either BYTE (8-bit) or INTEGER (16-bit). (NOTE: A 2-dimensional subset of a SOLID variable can be thought of as a MATRIX variable.)

KERNEL_MATRIX specifies the matrix to be used as the kernel for the convolution. The kernel is assumed to be an integer matrix (signed 16-bit). Non-integer kernel values are converted automatically to integers before computing the convolution.

The kernel matrix specifies how the value for each data element is computed from the values of its neighbors. The size of the matrix determines how many neighbors will be involved in the computation. The kernel itself represents a weighting function, centered around the data element of interest, where each value represents how much the intensity of the data in that position contributes to the output value in the central position. This calculation has the form:

                V = a K(i,j)*P(i,j)

where V is the new data value, K is the kernel matrix, and P is the region of the original image centered around the new data position. P has the same dimensions as K.

The following are some examples of common kernels:

.     -1 -1 -1          Laplacian - the value of the 8 neighbors is
      -1  8 -1          subtracted from 8 times the value of the center.
      -1 -1 -1          The result is a contrast detector.

      -1 -1 -1          Like the Laplacian, but the central pixel has more
      -1  9 -1          weight.  Results in contrast enhancement.
      -1 -1 -1

      -1 -1 -1 -1       Horizontal line detector.
      -1 -1 -1 -1
       1  1  1  1
       1  1  1  1

The OFFSET value is added to each convolved value, which is then shifted SHIFT bits to the right. Each bit shifted divides the value by 2. If the convolved value is less than MINVAL it will be clipped to MINVAL. If MAXVAL is > 0 then any convolved value greater than MAXVAL will be clipped to MAXVAL. The offset and shift occur before clipping.

NOTE: Most image processors provide hardware features that can greatly reduce the time needed to perform convolutions. These hardware capabilities are limited, however, and will only work for certain combinations of VSRC and VDST, and may or may not be capable of clipping values that are outside the MINVAL-MAXVAL range. In CIGAL, the CONVOLVE command automatically uses the image processor hardware to speed up convolutions whenever possible. However, if the choice of arguments does not fit the hardware restrictions, then the convolution is performed within the computer itself (and will take longer). You can therefore use the same command regardless of where the images are stored. CIGAL will take advantage of the available processing speed whenever possible.

This table lists the default values used for VSRC and VDST and whether the other arguments can be specified and still take advantage of the hardware capabilities, for several image processors. Changing the default values away from these may greatly slow down performance.

    Image Processor    VSRC (Bits)   VDST (Bits)   MINVAL   MAXVAL   SHIFT
     RCI TRAPIX          1  (8)       23  (16)      No       No       Yes
     GRINNELL            1  (8)       2   (8)       Yes      Yes      Yes
     MATROX MVP-AT       0  (8)       21  (16)      Yes      Yes      Yes

See Also:
FILTER(3), SMOOTH(3)

CIGAL Home, CIGAL Manual, Functions List, Manual Help

jvs/cigal/manual/chapter3/convolve.txt · Last modified: 2023/02/23 18:43 (external edit)