Fundamentals of Spatial Filtering

In this chapter, only image enhancement spatial filtering is done.

Spatial filtering is done by modifying all the pixels of an image by a function. There are linear and nonlinear spatial filtering.

Convolution of an image

The convolution of an image $f(x,y)$ of size $M \times N$ using a kernel $w$ of size $m \times n$ is defined as -

$ (w*f) (x,y) = \sum\limits_{s = -a}^a \sum\limits_{t = -b}^b w(s,t) f(x-s, y-t) $

where

$a = \frac{m-1}{2} $

$b = \frac{n-1}{2} $

$ w(s,t) $ one element of the kernel and

$ f(x+s, y+t) $ is one pixel of the image

Multiple sequential convolution with different filters

If an image $f$ is filterd with a kernel $w_1$, the result filtered with kernel $w_2$, and so on, for Q stages, then because of the cumulative property of convolution, this multistage filtering can be done in a single filtering operation $w*f$, where $w=w_1 * w_2 * w_3 * .... * w_q$

If all the kernels are of size $M \times N$, then the resulted image size will be $W_v\times W_h$ where

$W_v = Q \times (m-1) + m $

$W_h = Q \times (n-1) + n $

Smoothing (Lowpass) Spatial Filters

Used to reduce random noise, irrelevant detai, smoothing the false contours

Box Filter Kernels

Lowpass Gaussian Filter Kernels

Gaussian kernel

$ w(s, t) = G(s, t) = Ke ^{-\frac{s^2 + t^2}{2 \sigma ^2}} $

Here, $\sigma $ is the standard deviation, controls the spread of the Gaussian function

Limitation of box filter kernel

  1. Box filters are poor approximations to the blurring characteristics of lenses.

  2. Box filters favor blurring along perpendicular directions. In applications involving images with a high level of detail, or with strong geometrical components, the directionality of box filters often produces undesirable results

For a Gaussian kernel, kernel size greater than $ \lceil 6 \sigma \rceil \times \lceil 6 \sigma \rceil $ does not improve the performance

Here, for $\sigma = 8$, we tried $49 \times 49$ and $99 \times 99 $. The max difference between two resultant image is -

Comparison between Box Kernel and Gaussian Kernel

Comparatively larger Gaussian kernel is necessary to get a close result of a Box kernel. However, box filters favor blurring along perpendicular directions. In applications involving images with a high level of detail, or with strong geometrical components, the directionality of box filters often produces undesirable results.

Difference between zero padding and mirror padding

Zero padding introduces dark borders in the filtered image. So, mirror padding is more applicable when the areas near the border contains image details.

Shortcomings of linear filters

Linear filters cannot cope with the nonlinearities of the image formation model and cannot take into account the nonlinearities of human vision. Furthermore, human vision is very sensitive to high-frequency information. Image edges and image details (e.g. corners and lines) have highfrequency content and carry very important information for visual perception. Filters having good edge and image detail preservation properties are highly suitable for digital image filtering. Most of the classical linear digital image filters have low-pass characteristics. They tend to blur edges and to destroy lines, edges, and other fine image details. These reasons have led researchers to the use of nonlinear filtering techniques.

Order-Statistics (Nonlinear) Filter

Order Statistic Filters are filters which rank neighboring pixels in an attempt to remove low frequency effects while retaining edges. There are different types of nonlinear filter such as median filter, max filter, min filter, midpoint filter, etc.

Advantages of Median Filter

  1. It works well for various noise types, with less blurring than linear filters of similar size
  2. Odd sized neighborhoods and efficient sorts yield a computationally efficient implementation

Advantages of Min Filter

Advantages of Max Filter

Max filters are Useful for finding the brightest points in an image

Advantages of Mid-point Filter

Mid-Point filters are very useful for removing randomly distributed noise like Gaussian noise

Sharpening (Highpass) Spatial Filters

Unsharp Masking

Subtracting an unsharp (smoothed) version of an image from the original image to sharpen images is called unsharp masking

Steps -

  1. Blur the original image --> $ \bar f (x,y) $
  2. Subtract the blurred image from the original --> $ g_{mask} = f(x,y) - \bar f (x,y) $
  3. Add the mask to original --> $ g(x,y) = f(x,y) + g_{mask} (x,y) $