Shape of a typical Gaussian filter
In electronics and signal processing, a Gaussian filter is a filter whose impulse response is a Gaussian function. Gaussian filters are designed to give no overshoot to a step function input while minimizing the rise and fall time. This behavior is closely connected to the fact that the Gaussian filter has the minimum possible group delay. Mathematically, a Gaussian filter modifies the input signal by convolution with a Gaussian function; this transformation is also known as the Weierstrass transform.
Definition
The one-dimensional Gaussian filter has an impulse response given by
or with the standard deviation as parameter
In two dimensions, it is the product of two such Gaussians, one per direction:
- ^{[1]}^{[2]}^{[3]}
where x is the distance from the origin in the horizontal axis, y is the distance from the origin in the vertical axis, and σ is the standard deviation of the Gaussian distribution.
Digital implementation
The Gaussian function is non-zero for and would theoretically require an infinite window length. However, since it decays rapidly, it is often reasonable to truncate the filter window and implement the filter directly for narrow windows, in effect by using a simple rectangular window function. In other cases, the truncation may introduce significant errors. Better results can be achieved by instead using a different window function; see scale space implementation for details.
Filtering involves convolution. The filter function is said to be the kernel of an integral transform. The Gaussian kernel is continuous. Most commonly, the discrete equivalent is the sampled Gaussian kernel that is produced by sampling points from the continuous Gaussian. An alternate method is to use the discrete Gaussian kernel which has superior characteristics for some purposes. Unlike the sample Gaussian kernel, the discrete Gaussian kernel is the solution to the discrete diffusion equation.
Since the Fourier transform of the Gaussian function yields a Gaussian function, the signal (preferably after being divided into overlapping windowed blocks) can be transformed with a Fast Fourier transform, multiplied with a Gaussian function and transformed back. This is the standard procedure of applying an arbitrary finite impulse response filter, with the only difference that the Fourier transform of the filter window is explicitly known.
Due to the central limit theorem, the Gaussian can be approximated by several runs of a very simple filter such as the moving average. The simple moving average corresponds to convolution with the constant B-spline, and, for example, four iterations of a moving average yields a cubic B-spline as filter window which approximates the Gaussian quite well.
Borrowing the terms from statistics, the standard deviation of a filter can be interpreted as a measure of its size. The cut-off frequency of the filter can be considered as the ratio between the sample rate F_{s} and the standard deviation σ
A simple moving average corresponds to a uniform probability distribution and thus its filter width of size n has standard deviation . Thus m moving averages with sizes yield a standard deviation of
- .
(Note that standard deviations do not sum up, but variances do.)
When applied in two dimensions, this formula produces a Gaussian surface that has a maximum at the origin, whose contours are concentric circles with the origin as center. A two dimensional convolution matrix is precomputed from the formula and convolved with two dimensional data. Each element in the resultant matrix new value is set to a weighted average of that elements neighborhood. The focal element receives the heaviest weight (having the highest Gaussian value) and neighboring elements receive smaller weights as their distance to the focal element increases. In Image processing, each element in the matrix represents a pixel attribute such as brightness or a color intensity, and the overall effect is called Gaussian blur.
The Gaussian filter is non-causal which means the filter window is symmetric about the origin. This is usually of no consequence for most applications. In real-time systems, a delay is incurred because incoming samples need to fill the filter window before the filter can be applied to the signal.
Order
1. gaussian sigma 구하기
- Mask size를 통해서 sigma값을 구한다.
- sigma = (maskSize - 1) * 6.0;
2. gaussian mask를 구한다.
- (1/ (2.0 * pi * sigma * sigma) * exp( -1 * (x * x + y * y)/ (2.0 * sigma * sigma))
3. gaussian mask의 max값을 구한다.
4. gaussian mask(RGB) weight 값을 구한다.
- weight = 255 / max;