Operations: Linear raster filter

From ILWIS
Jump to: navigation, search
Main Page Arrow.png Operations
Linear raster filter
Linear raster filter

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")


Figure 1, Linear raster filter operation form




To start the Linear raster filter operation from ILWIS main window:

Mar.jpg
  • Click the Operation tab on toolbar tabs
  • From the opened operation list select Linear raster filter


Once the Linear raster filter operation is selected from the list, an operation form will be opened in which you can set parameters required for that operation including input(s), output(s), memory location and data format (Figure 1).

To successfully execute this operation, you need to complete the form with proper inputs data. The inputs data must be dragged from the catalog and dropped in their corresponding fields in the form or typed in.

input raster coverage: Select an input raster coverage to be filtered.
filter definition: Select an existing standard filter from the dropdown list.
output raster coverage: Type a name for the output raster map that will contain results of the filtering operation.
Output format: Select a format to save the output raster map. The default format is Memory; if you select it, the output will be temporally saved in the internal catalog and will be removed when you exit the program. If you select other format, the output will be saved in the active catalog.
Execute: Click the Execute button to run this operation.


In ILWIS, number of standard filters are available to be used including linear and non-linear filters. Detailed information of filtering and the available filter are given in: Basic concept: Filters