# Median Filters

VisionPro supports two types of median filters, which can be an effective noise reduction technique for many types of images. For each pixel in the input image, a median filter picks the middle value from all the pixels of the input image that lie within a boundary specified by a kernel. This middle value becomes the grey value in the output image at the position that corresponds to the center of the kernel. A median filter is very effective in reducing salt-and-pepper noise from an image.

A median filter performs quite differently than an Image Average tool, which computes the mean of all the values defined by the kernel. A median filter can reduce the blurring effect an Image Average tool can have while also retaining sharp edge information. For example, the following figure shows an input image and the two output images it generates using an Image Average tool and a median filter:

The following figure shows the pixel values in a fragment of a grey-scale image and highlights the nine pixels defined by a 3x3 kernel:

The grey values within the kernel, in sorted order, are '115', '119', '120', '123', '124', '125', '126', '127', and '150'. The median value for the output image in a 3x3 kernel is the 5th value, or '124' in this case. In the output image, the value '124' replaces the previous grey value of '150', and the algorithm moves on to the next pixel in the input image.

VisionPro supports a 3x3 median operator and a median NxM operator to specify your own custom-sized kernel. Larger kernels have a greater impact on the output image. A median NxM filter allows you to select which pixels in the kernel are 'Care' and 'Don't Care' values at every position. As the median algorithm operates, kernel positions with a 'Don't Care' value are not considered when generating the new grey value for the output image.