# Fixed ConvolutionImageFilter

Cory Quammen
2011-09-27
In convolution, the kernel is effectively flipped and swept across an image, and at each pixel the dot product between the kernel centered at the pixel and the image to convolve is computed and stored. Previously, the ConvolutionImageFilter was not performing the flip, and the existing tests were incorrect. This patch makes the ConvolutionImageFilter produce the correct output according to the predominant definition of the convolution operation, and the tests and test data have been modified accordingly.

In addition, the method SetImageKernelInput() has been renamed to SetKernelImage() to be consistent with other filters such as MaskImageFilter and the registration classes.

typedef itk::ConvolutionImage< ImageType > ConvolutionFilterType; ConvolutionFilterType::Pointer convolutionFilter = ConvolutionFilterType::New(); convolutionFilter->SetInput( inputImage ); convolutionFilter->SetImageKernelInput( kernelImage ); convolutionFilter->Update();
#include <itkFlipImageFilter.h>

// If you're existing code produced desired results, then you will need // to flip the kernel prior to setting it as the kernel image in the // convolution filter (assuming the kernel is not symmetric about each axis). typedef FlipImageFilter< TImage > FlipperType; typename FlipperType::Pointer flipper = FlipperType::New(); typename FlipperType::FlipAxesArrayType axesArray; axesArray.Fill( true ); flipper->SetFlipAxes( axesArray ); flipper->SetInput( kernelImage );

typedef itk::ConvolutionImage< ImageType > ConvolutionFilterType; ConvolutionFilterType::Pointer convolutionFilter = ConvolutionFilterType::New(); convolutionFilter->SetInput( inputImage ); convolutionFilter->SetKernelImage( kernelImage ); convolutionFilter->Update();
I689d3e4a627b2017f52d9b74998a1befae1e9fe7
Modules/Filtering/Convolution/include/itkConvolutionImageFilter.hxx Modules/Filtering/Convolution/test/Baseline/itkConvolutionImageFilterTestSobelX.nrrd.md5 Modules/Filtering/Convolution/test/Baseline/itkConvolutionImageFilterTestSobelY.nrrd.md5 Modules/Filtering/Convolution/test/CMakeLists.txt Modules/Filtering/Convolution/test/itkConvolutionImageFilterDeltaFunctionTest.cxx