Linear (convolution) filters consist of a matrix with values and a gain factor. When considering a linear filter of size 3x3, the 9 matrix values are multiplied with 9 pixel values in the input raster map, this is summed and then multiplied with the gain factor. The result is assigned to the center pixel in the output map. The convolution filters are used for sharpening, blurring, enhancing edges and detecting lines within an image. The available standard linear filter in ILWIS are: average, edgeenhancment, laplace3x3, shadownw, dfdx, dfdy, dfddn, dfdup, d2fdx2, d2fdy2, d2fdxdy. Standard filters can be found in the ILWIS\SYSTEM directory. ILWIS also supports user-defined linear filters and provide tools to create, edit and store. In general, when you create or define your own filters, any odd sized matrix is allowed (3 x3, 5 x 1, 7 x 5); however, at the moment only linear filters of 3 by 3 kernel is possible.
The ILWIS Linear raster filter operation can be used for a number of purposes:
- to enhance 'sharpness' of a satellite image for better visual interpretation
- to reduce noise in an image
- to detect line features or edges in a satellite image
- to calculate steepness, direction (aspect), and shape (concave, convex) of slopes in a DEM,
- to replace pixels with unknown value with value calculated from its surrounding
- morphologic filtering on bit maps, etc.
The Linear raster filter operation can be applied either via ILWIS-Python editor or via ILWIS Main window, Toolbar and the Operatins tab. The required Python syntax is:
name of the output raster coverage = ilwis.Engine.do(name of the operation, name of the input raster coverage, ‘filter definition’)
Then, the Python syntax for the above mentioned operation is:
output raster = ilwis.Engine.do("linearrasterfilter", “file:///C:/my director/my raster coverage", "average")
In the example above, the ILWIS standard linear filter average is used to replace the filter definition . in case of user defined filter, the user can enter filter values in the field of filter definition as it is shown in the flowing example with a user defined gradient filter:
output raster = ilwis.Engine.do('linearrasterfilter','file:///C:/my director/my raster coverage','"code=0, -1, -2, 1, 0, 1, 2, 1, 0"')
Note that the exact quotation and spacing has to be used to enter the syntax for filter definition; meaning single quotation outside and double quotation inside and no space between = and 0 (e.g., code= 0; is not good) as it is demonstrated in the above example.
In general, the URL used in the Python syntax can be replaced with variable name created using Python. For example: you can open a feature coverage as a variable and give it a name as the following example:
rc = ilwis.RasterCoverage("file:///C:/my director/ my raster.mpr")
Once the variable is created, then it can be used directly in Python syntax without quotation mark and the path as the following:
output raster = ilwis.Engine.do("linearrasterfilter", rc, "average")