deegree 2.3 (2010/04/09 10:10 build-4-official)

org.deegree.processing.raster.filter
Class Convolve

java.lang.Object
  extended by org.deegree.processing.raster.filter.Convolve

public class Convolve
extends Object

This class offeres some convenience methods for convolving a data matrix.
Convolution filtering is often used to reduce the effects of noise in images or to sharpen the detail in rasters. Convolution filtering is a form of spatial filtering that computes each output sample by multiplying elements of a kernel with the samples surrounding a particular source sample.
Convolution filtering operates on a group of input values surrounding a center pixel. The adjoining values provide important information about values trends in the area of the values being processed.
Convolution filtering moves across the source raster, cell by cell, placing resulting values into the destination raster. The resulting value of each source cell depends on the group of values surrounding the source cell. Using the cell values of the source cell's neighbors, the convolution process calculates the spatial frequency activity in the area, making it possible to filter the values based on the spatial frequency of the area.
Convolution filtering uses a convolve kernel, containing an array of convolution coefficient values, called key elements. The array is not restricted to any particular size, and does not even have to be square. The kernel can be 1 x 1, 3 x 3, 5 x 5, M x N, and so on. A larger kernel size affords a more precise filtering operation by increasing the number of neighboring cells used in the calculation. However, the kernel cannot be bigger in any dimension than the source data. Also, the larger the kernel, the more computations that are required to be performed. For example, given a 640 x 480 raster and a 3 x 3 kernel, the convolve operation requires over five million total multiplications and additions.
The convolution filtering operation computes each output sample by multiplying the key elements of the kernel with the samples surrounding a particular source cell. For each destination cell, the kernel is rotated 180 degrees and its key element is placed over the source pixel corresponding with the destination pixel. The key elements are multiplied with the source cell value under them, and the resulting products are summed together to produce the destination sample value.
The selection of the weights for the key elements determines the nature of the filtering action, such as high-pass or low-pass. If the values of the key elements are the reciprocal of the number of key elements in the kernel (for example, 1/9 for a 3 x 3 kernel), the result is a conventional low-pass averaging process. If the weights are altered, certain cells in the kernel will have an increased or decreased influence in the average.
(modified from JAI documentation)

Since:
2.0
Version:
$Revision: 18195 $, 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
Author:
Andreas Poth, last edited by: $Author: mschneider $

Constructor Summary
Convolve()
           
 
Method Summary
static float[][] perform(float[][] source, float[][] kernel)
          convolves the passed float matrix by applying the passed kernel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Convolve

public Convolve()
Method Detail

perform

public static float[][] perform(float[][] source,
                                float[][] kernel)
                         throws RasterFilterException
convolves the passed float matrix by applying the passed kernel. A kernel for lowpass filtering may looks like:
  float[][] kernel = new float[5][5];
  for ( int i = 0; i < kernel.length; i++ ) {
       for ( int j = 0; j < kernel[i].length; j++ ) {
           kernel[i][j] = 1;
       }
   }
 <pre>
 which results in a strong smoothing of the raster.
 
A kernel for highpass filtering may looks like: <pre> float[][] kernel = new float[3][3]; for ( int i = 0; i < kernel.length; i++ ) { for ( int j = 0; j < kernel[i].length; j++ ) { kernel[i][j] = -1; } } kernel[kernel.length/2][kernel[0].length/2] = 2; </pre> Notice that the sum of all kernel values does not must be == 1! Correct weighting will be done by this method.

Parameters:
source - to apply the kernel to.
kernel - to apply
Returns:
the raster after applying the given kernel.
Throws:
RasterFilterException - if the kernel does not have an odd number of cells.

deegree 2.3 (2010/04/09 10:10 build-4-official)

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org