How to create a custom convolution filter

This article shows how to create a custom convolution filter by specifying a kernel.

Creating a custom convolution filter

Use the following code example in your application:
static void customConvolutionFilter(IRaster raster)throws Exception{
    //The following code sample sets up a horizontal line detection filter and apply it on a raster
    //create a convolution filter using a custom kernel
    IRasterConvolutionFilter newFilter = new RasterConvolutionFilter();
    double[][] kernel = new double[][]{
             - 1,  - 1,  - 1, 2, 2, 2,  - 1,  - 1,  - 1
    newFilter.setSize(3, 3);

    //apply the filter to the raster
    IPixelOperation pixelOperation = (IPixelOperation)raster;

    //save the result
    ISaveAs saveas = new ISaveAsProxy(raster);
    saveas.saveAs("c:\\temp\\convolution_output.img", null, "IMAGINE Image");

Development licensingDeployment licensing
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop BasicArcGIS for Desktop Basic
Engine Developer KitEngine