Sample source code

This article is accompanied by a sample source code Visual Studio project which is available for download here.

Using the Sample Application

The concepts explored in this article can be easily replicated by making use of the Sample Application, which forms part of the associated sample source code accompanying this article.

When using the Difference Of Gaussians sample application you can specify a input/source image by clicking the Load Image button. The dropdown combobox towards the bottom middle part of the screen relates the various edge detection methods discussed.

If desired a user can save the resulting edge detection image to the local file system by clicking the Save Image button.

The following image is screenshot of the Difference Of Gaussians sample application in action:

In imaging science, Difference of Gaussians is a feature enhancement algorithm that involves the subtraction of one blurred version of an original image from another, less blurred version of the original. In the simple case of grayscale images, the blurred images are obtained by convolving the original grayscale images with Gaussian kernels having differing standard deviations. Blurring an image using a Gaussiankernel suppresses only high-frequency spatial information. Subtracting one image from the other preserves spatial information that lies between the range of frequencies that are preserved in the two blurred images. Thus, the difference of Gaussians is a band-pass filter that discards all but a handful of spatial frequencies that are present in the original grayscale image.

In the sample source code accompanying this articleGaussianimage blurring is applied by invoking the ConvolutionFilter method. This method accepts a two dimensional array of type double representing the convolutionmatrix/kernel. This method is also capable of first converting source images to grayscale, which can be specified as a method parameter. Resulting images sometimes tend to be very dark, which can be corrected by specifying a suitable bias value.

The following code snippet provides the implementation of the ConvolutionFilter method:

The Gaussian Matrix

The sample source code defines three Gaussianmatrix/kernel values, a 3×3matrix and two slightly different 5×5 matrices. The Gaussian3x3matrix requires a factor of 1 / 16, the Gaussian5x5Type1matrix a factor of 1 / 159 and the factor required by the Gaussian5x5Type2 equates to 1 / 256.