Gaussian SamplingCognex VisionPro

Use a Gaussian Sampling operator on an image to reduce image noise or produce a less-pixelated image, depending on the needs of your vision application:

ImageProcessing_GaussianFilter_Theory_BeforeAndAfter

See the following sections for more information:

Gaussian Convolution

This section contains the following subsections.

The Gaussian Sampling operator processes an input image with a Gaussian kernel that approximates a two-dimensional Gaussian distribution. By varying the size of this kernel, the effect of the smoothing can be lessened or increased:

ImageProcessing_GaussianFilter_Theory_DifferentKernelSizes

The operator examines the input image for the grey value of each pixel and the pixels surrounding it, takes a fraction of the grey value of each pixel as specified by the kernel, adds these values together, and assigns this new value to the corresponding pixel in the output image:

Image Processing Gaussian Filter Theory Gaussian applying a 3x 3 gaussian kernel

Note: The values shown may not be actual values that the Gaussian Sampling operator uses in a 3x3 kernel.

Choose a smoothing value which corresponds to the size, in pixels, of the features you want to reduce in detail. The output image is always the same size as the input image.

Smoothing and Sampling

The operator allows you to subsample the image after smoothing, producing an output image with fewer pixels. Subsampled images can generally be processed more quickly by other vision tools. The image can be sampled at any rate below the smoothing value without loss of information. In general, Cognex recommends you never specify a subsampling rate equal or greater than the smoothing value.

You can specify independent x- and y-axis sampling factors for the Gaussian Sampling tool.

Enhancing Low-Contrast Images

Enhance low-contrast images by specifying a magnitude shift, which performs a bitwise shift of pixel values in the resulting output image. Valid values range from -7 to 7. Negative values will darken the result by dividing the pixel value results by 2 for each bit specified. Similarly, positive values will brighten by multiplying by 2.

Gaussian Curve

A Gaussian curve is a graph of the following function:

Image Processing Gaussian Filter Theory Gaussian gaussian curve formula

where μ is the mean and σ is the standard deviation. The following figure shows a Gaussian curve:

Image Processing Gaussian Filter Theory Gaussian gaussian curve

The Gaussian Sampling tool uses an approximation of a two-dimensional Gaussian curve, as shown in the following figure:

Image Processing Gaussian Filter Theory Gaussian approximation of a twodimensional gaussian curve

Kernel Sizes

You specify the Gaussian kernel size by providing a smoothness value corresponding to the feature size, in pixels, below which you wish to smooth. The relationship between the smoothing value you specify and the size of the resulting Gaussian curve given by the following formula:

Image Processing Gaussian Filter Theory Gaussian relation between smoothing value and standard dev

where s is the smoothing value and σ is the standard deviation of the resulting curve. The size of the Gaussian kernel itself is then computed using the following formula:

Image Processing Gaussian Filter Theory Gaussian formula for computing size of kernel

where s is the smoothing value.

Note: You can specify independent values for smoothing in the x- and y-directions, so the kernel might not be square.

SmoothingSigma (s)Kernel Width
1.8664
21.4147
31.93610
42.44913
52.95816

In general, you should start with a smoothing value of 1 or 2 and increase it until you obtain the desired smoothing.