Average filter
The average filter is one of the simplest filters enabling removing noise and distortion. Unfortunately, it also introduces changes in the areas that have originally been noise and distortion free.
Let us assume that we construct a filter operating on the window \( {N} \times {N}\). In this case, the resulting value of the pixel is the average value of all the pixels contained within the current analysis window of the source image
$$\begin{aligned} m_{\theta }=\frac{1}{{N} \times {N}} \times \sum \limits _{(x,y) \in \theta } \varphi \big (f(x,y)\big ) \end{aligned}$$
(1)
where:
-
f is the source image function,
-
f(x,y) is the value of the pixel at coordinates (x, y),
-
\(\varphi \) is a function calculating the value of a particular pixel. This function can take different values depending on the color space, the format or the depth of the image,
-
\({{N} \times {N}}\) is the number of pixels in the current window,
-
\(\theta \) represents the collection of pixels in the current window.
Some of the largest disadvantages of the average filter are blurring noise and significant modification of correct pixels.
Median filter
The concept of the median filter is very similar to that shown above. The only difference is that all elements in the current filter window have to be sorted and ordered in an ascending sequence. The resulting value is the value of the item in the exact middle point of the ordered sequence (position \(\frac{{N} \times {N}}{2}\) for \({N} \times {N}\) window).
With the use of this filter, one can very effectively remove any local noise, without blurring the noise to larger areas, which was a major disadvantage of the average filter.
Adaptive median filter
The adaptive median filter, as its name suggests, is a modification of the median filter. This modification consists in allowing a situation where the window size is not constant, but changes dynamically according to the context. If you select too small a window, the median filter could not handle all the noises, while too large a window results in dissolving the smaller but desired image detail.
The adaptive median filter algorithm has the following form:
Step 1 For each pixel \(\textit{f}\,\,(\textit{x},\textit{y}) \) of the image f, we determine the list of neighbors in \(\textit{N} \times \textit{N}\) window. Among these elements, we calculate the minimum, middle (median) and the maximum value and denote these values as \(f_\mathrm{min}\), \(f_\mathrm{med}\) and \(f_\mathrm{max}\), respectively.
Step 2 If \(f_\mathrm{min}=f_\mathrm{med}\) or \(f_\mathrm{med}=f_\mathrm{max}\), then the size of filter window is increasing and the actions done in the previous step for the new window have to be repeated. Otherwise, go to the next step.
For obvious reasons, there must exist the maximum allowable window size. If it is not possible to further increase the filter window size, then the output pixel is set to the neighbors list middle value determined in the previous step (\(f_\mathrm{med}\)).
Step 3 If \(f_\mathrm{min}<f(x,y)\) and \(f(x,y)<f_\mathrm{max}\), then the output pixel takes the value of f(x, y), which means that item is not modified. Otherwise, the output pixel is set to the neighbors list middle value determined in the first step (\(f_\mathrm{med}\)).
This filter is able to reduce even a large noise. Unfortunately, the high computational complexity of this filter is quite a serious disadvantage. In addition, if the maximum window size is set to too small a value, we can get unsatisfactory results. However, too large a window size may cause very unsatisfactory execution time.
Kuwahara filter
Because the contour plays a very important role in the process of image analysis [4, 9], it is very important to ensure that the image smoothing does not affect the sharpness of contours. This could cause serious problems later, during segmentation. The Kuwahara filter [1] is an example of a filter which meets these requirements. This filter can be constructed for any window size. For readability, the algorithm will be described for the window of size of \(3\times 3\).
The filter window should be divided into four areas. Let us denote them as \(\theta _{k}\) where \(k\in \{0,1,2,3\}\). These four areas are highlighted in Fig. 1. The center pixel is marked with black color. If a square filter window consists of \((2\times n+1)\times (2\times n+1)\) elements, then each area will contain exactly \((n+1)\times (n+1)\) elements. In the described case, the filter window size is \(3\times 3\), so each area will consist of four elements. Then, for each of these areas, the values of average \(m_{k}\) and variance \(\delta _{k}^{2}\) are calculated. The average and variance are calculated according to the formula:
$$\begin{aligned} m_{k}= & {} \frac{1}{(n+1)\times (n+1)} \times \sum \limits _{(x,y) \in \theta _{k}} \varphi \big (f(x,y)\big ) \end{aligned}$$
(2)
$$\begin{aligned} \delta _{k}^{2}= & {} \frac{1}{(n+1)\times (n+1)} \times \sum \limits _{(x,y) \in \theta _{k}} \Big [ \varphi \big (f(x,y)\big ) - m_{k} \Big ]^2\nonumber \\ \end{aligned}$$
(3)
where:
-
\(k \in \{0,1,2,3\}\),
-
f is the source image function,
-
f(x, y) is the value of the pixel at coordinates (x, y),
-
\(\varphi \) is a function calculating the value of a particular pixel,
-
\(\frac{1}{(n+1)\times (n+1)}\) is the number of pixels in the current area,
-
n is the value obtained directly from the filter window size.
Finally, we compare the variance of all four areas and look for an index of the area for which the variance is the smallest.
$$\begin{aligned} \delta _\mathrm{min}^{2} = \min _{k \in \{1,2,3,4\}} \big ( \delta _{k}^{2} \big ) \end{aligned}$$
(4)
The resulting value of the center pixel is the average value of the area for which the variance was the smallest.
The result of increasing the size of the filter windows will be better noise reduction, but it can cause blurring of small details in the analyzed image.