Unit III
Spatial Filtering
- Image processing technique to reject certain frequency components.
- Involves usage of filter mask which traverses through the image pixels.
- Advantage over frequency filters can also be used in non-linear domain.
- Types
- Smoothening spatial filter
- Sharpening spatial filter
Response of Linear Filter
- weight of mask/filter
- corresponding image pixel
- After operation, (center of mask) is replaced with with response.
NOTE
On the edges of an image, the row and/or column is mirrored appropriately to ensure proper filter operation. Defaulting it to 0
negatively affects the response on the edges.
Smoothening Spatial Filter
- Used in blurring and noise reduction. This process removes small, insignificant details from the image.
Average Filter
Takes the average of image matrix under the mask.
Weighted Average Filter
Takes the weighted average of the image matrix under the mask. This gives us flexibility to give maximum weightage to the pixel being replaced i.e. center of the mask, and reduce weightage as we move away from the center.
Weighted average produces smoother output on detailed images with a lot of variation in vibrance region-to-region.
Median Filter
Takes the median of values under the mask.
Maximum Filter
Takes the maximum of values under the mask.
Minimum Filter
Takes the minimum of values under the mask.
Geometric Mean Filter
Takes the geometric mean of values under the mask.
Harmonic Mean Filter
Takes the harmonic mean of values under the mask.
Sharpening Spatial Filter
- Used in sharpening, highlighting, and edge detection. This process highlights the sudden changes in
H/S/V
which usually happens at the edges of an object. - Since we are dealing with sudden change in
H/S/V
, concept of derivative (rate of change) is very useful in sharpening filters. - Since the values in an image are finite, the maximum change possible is to along adjacent pixels.
- In context of an image matrix
- current pixel
- next pixel
- previous pixel
First Order Derivative Filter
Characteristics of first order derivatives
- Must be zero in flat segments
- Must be non-zero at onset of gray level ramp/change
- Must be non-zero along ramp
Second Order Derivate Filter
Characteristics of second order derivatives
- Must be zero in flat area
- Must be non-zero at onset of gray level ramp/change
- Must be zero along ramp
Image Profile
- Edges are excluded because
f′′
becomes undefined because there is no 'previous pixel'. - The calculated derivatives follow the characteristics.
Conclusions from Image Profile
- highlights thicker edges as it has non-zero response to ramps
- highlights finer details as it has strong response to isolated points
Laplacian Filter
- Works on principle of second order derivative filter.
- Since we'll use it on a mask, and not on a linear image profile, we have to modify the definition to include both and .
Mathematical Laplacian Mask
Modified Laplacian Mask
Continuous Laplacian Mask
NOTE
In context of image processing, we want to give more weightage to the center pixel of the mask.
The mathematically derived Laplacian filter gives negative weightage to the center pixel, which is undesired. Therefore we multiply the mask by -1
to make it more suitable for digital image processing.
Highboost Filtering
- Sharpening by subtracting blurred image from original image.
// Highboost filter
sharpImage(x, y) = originalImage(x, y) - blurredImage(x, y)
Sample Problem
Solved ExampleImage Enhancement in Frequency Domain
- Spatial domain (input) frequency domain (processing) spatial domain (output).
- Removes high or low frequencies.
- Change (function) is applied to entire image at once. There are no masks involved.
Fourier Transform
- Spatial domain frequency domain | DFT
- Frequency domain spatial domain | IDFT
- In context of DIP, we have to take two-dimensional Fourier transform
f(x, y) ⇌ F(u, v)
Steps for Filtering in Frequency Domain
- Preprocessing
// Input
f(x, y)
// Preprocessed input
f(x, y) * (-1)^(x + y)
- Fourier transform
// Fourier transform using 2D DFT
F(u, v) = FourierTransform(f(x, y))
- Filter in frequency domain
// Filter function
H(u, v)
// Apply filter function on image
G(u, v) = H(u, v) * F(u, v)
- Inverse Fourier transform
// Inverse Fourier transform using 2D IDFT
g(x, y) = InverseFourierTransform(G(u, v))
- Postprocessing
// Output
g(x, y)
// Postprocessed output
g(x, y) * (-1)^(x + y)
Filter Parameters
D₀
non-negative constant to adjust the filter levelD(u, v)
distance from point(u, v)
n
is the sharpness of the filter. Ifn $\longrightarrow$ ∞
, the filter becomes ideal.
// Distance function for an MxN image
D(u, v) = sqrt[ (u - M / 2)^2 + (v - N / 2)^2 ]
Notes on Usage of Frequency Filters
- Ideal filters blur the edges of image.
- Butterworth filters provide a smooth gradient at low sharpness
n
resulting in well defined edges. - Gaussian filters remove high/low frequency noise.
Smoothening Frequency Filter
- Utilizes lowpass filter to smoothen the image by removing the high frequency signals from the image.
- High frequency is basically noise and sudden changes in the image.
Ideal Lowpass Filter
// Filter function
H(u, v) = | 1 $\longrightarrow$ D(u, v) ≤ D₀
| 0 $\longrightarrow$ D(u, v) > D₀
Butterworth Lowpass Filter
// Filter function
H(u, v) = { 1 + [D(u, v) / D₀]^2n }^(-1)
Gaussian Lowpass Filter
// Filter function
H(u, v) = e ^ { -D²(u, v) / (2 * D₀²) }
Summary
Sharpening Frequency Filter
- Utilizes highpass filter to sharpen the image by removing the low frequency signals from the image.
- Low frequency is basically continuity in the image. Continuity breaks at edges of an object.
Ideal Highpass Filter
// Filter function
H(u, v) = | 0 $\longrightarrow$ D(u, v) ≤ D₀
| 1 $\longrightarrow$ D(u, v) > D₀
Butterworth Highpass Filter
// Filter function
H(u, v) = { 1 + [D₀ / D(u, v)]^2n }^(-1)
Gaussian Highpass Filter
// Filter function
H(u, v) = 1 - e ^ { -D²(u, v) / (2 * D₀²) }