An image filter transforms pixels in a digital image from values in a local neighbourhood. A filter suppresses or strengthens selected image detail.
Filter Kernel
Also known as mask, template or window. A kernel is a grid of coefficients centred on the pixel being processed.
For a linear filter:
- input image intensity
- filtered output intensity
- kernel coefficient at offset
The kernel moves over every pixel. The weighted sum becomes the output pixel.
Correlation and Convolution
Correlation places the kernel over the image without reversing it.
Convolution reverses the kernel by before taking the weighted sum. The filter-kernel equation above is convolution.
Symmetric kernels give the same result for both operations. A non-symmetric kernel gives the correlation result of its rotation under convolution.
Both operations are linear:
Convolution is commutative, associative and distributive over addition. A cascade of linear filters, such as Gaussian smoothing followed by a Laplacian, remains a linear operation.
Image Boundaries
The full neighbourhood is unavailable at an image boundary. A filtering implementation must choose a boundary rule.
- Replication
Repeat the nearest edge row or column outside the image. - Wrapping
Take missing pixels from the opposite edge. Suitable for periodic images. - Reduced support
Change the kernel shape or its normalization near the boundary.
Kernel Properties
- Normalized kernel
Coefficients sum to . Constant-intensity regions retain their intensity. - Symmetric kernel
The kernel gives equal weight to opposite offsets. Correlation and convolution produce the same result. - Separable kernel
A 2-D kernel factors into two 1-D kernels. Filter rows, then columns, with fewer operations.
Kernel Classification
For a linear kernel, first add all coefficients:
On a constant-intensity region with value , every covered pixel is . The filter output is .
Constant intensity passes unchanged. The kernel preserves the zero-frequency component.
Constant intensity becomes . The kernel rejects the zero-frequency component.
Constant intensity changes. The kernel scales or inverts the zero-frequency component.
Low-Pass Kernels
A low-pass kernel usually has these features:
- All or nearly all coefficients are positive
- The greatest coefficient is at the centre
- Coefficients decrease with distance from the centre
- Coefficients sum to
The mean and Gaussian kernels have this pattern. They average a neighbourhood, so neighbouring differences cancel.
High-Pass Kernels
A high-pass kernel usually has these features:
- Positive and negative coefficients
- Coefficients that sum to
- A positive centre surrounded by negative coefficients, or the reverse
The kernel returns on constant regions. It produces a large magnitude where neighbouring pixels differ.
Derivative Kernels
A derivative kernel has opposite signs on opposite sides of the pivot. It detects change in one direction.
The first kernel responds to horizontal intensity change. The second responds to vertical intensity change.
Sharpening Kernels
A sharpening kernel often has a positive centre and negative neighbours, but its coefficients sum to . It preserves constant intensity while adding a high-pass response to the original image.
It is not a pure high-pass filter, since constant regions remain visible.
Exact Classification
Coefficient patterns give a quick classification. The exact result comes from the frequency response:
A low-pass filter has a large magnitude near and a small magnitude near the highest frequencies. A high-pass filter has the reverse. A band-pass filter suppresses both regions and keeps an intermediate frequency band.
Low-Pass Filters
A low-pass filter keeps slowly varying intensity and attenuates rapid change. It smooths noise and fine detail.
Used before downsampling to prevent aliasing. It also reduces noise before feature extraction or lossy coding.
Mean Filter
The mean filter assigns equal weight to every pixel in its neighbourhood:
It strongly blurs edges. Use it for zero-mean random noise when edge preservation is not important.
Gaussian Filter
The Gaussian filter gives the greatest weight to the pivot pixel. Weights decrease smoothly with distance:
controls the blur width. Larger spreads weight farther from the pivot and removes more high-frequency detail.
Kernel Construction
The continuous function must be sampled to make a finite kernel. For a kernel, use the offsets .
Choose , then calculate the unnormalized 1-D weights:
Normalize them so their sum is :
For , the unnormalized weights are approximately:
Their normalized values are approximately:
Form the 2-D kernel by multiplying 1 horizontal weight by 1 vertical weight:
The centre coefficient is largest. Corner coefficients are smallest.
Binomial Approximation
A common integer approximation for is:
The numerator coefficients sum to , so division by normalizes the 1-D kernel. Its outer product forms the 2-D kernel:
The top-left corner coefficient is . The coefficients sum to . Apply horizontally, then vertically. This is equivalent to convolution with .
At each output pixel, multiply every value in the covered neighbourhood by the matching coefficient, then sum the products.
Use the Gaussian filter before downsampling, in Gaussian pyramids and to smooth noise before differentiation.
High-Pass Filters
A high-pass filter attenuates slowly varying intensity and preserves rapid change. It strengthens edges and fine detail.
A simple high-pass kernel is:
Its response is near in constant regions and large at intensity transitions. High-pass filters also amplify noise.
Non-Linear Filters
Non-linear filters do not form a weighted sum. The median filter replaces the pivot with the median neighbourhood intensity.
A median filter has no numeric kernel. It uses a neighbourhood window, commonly . The window identifies the values to sort. No coefficient is multiplied by a pixel value.
It removes isolated salt-and-pepper noise while preserving edges better than mean or Gaussian filtering.
Worked Examples
Classifying Kernels
Classify the following kernels.
Solution Reveal Hide
has only positive, equal weights. It is a mean low-pass filter.
rejects constant regions. It is a high-pass Laplacian kernel.
preserves constant regions and strengthens differences from the pivot. It is a sharpening kernel.
Median Filter
Apply a median filter to the neighbourhood below.
Solution Reveal Hide
The filter does not multiply values by kernel coefficients. Sort the neighbourhood values:
The middle value is . The filtered pivot value is .