Lecture

Spatial Filtering

It is a technique for modifying/enhancing images by manipulating the value of each pixel based on its own value and the values of surrounding neighbors.

In terms of digital image processing, a filter is a predefined matrix known as a kernel/mask/template/window.

NOTE: the matrix will determine how to integrate a pixel w/ its neighbors to generate a new pixel value.

Depending on the intended effect of an image, filters will vary in size, shape, and the values that they contain.

Types of filters:

  1. Linear - applying a linear operation
  2. Non-linear - utilzie operators that are not linear combos of input pixel.

For linear spatial filtering, we perform the sum-of-products between an image f and a filter kernel w.

NOTE: basically, for each coefficient in w, we multiply it with each coefficient found in w. Once the sum-of-products is performed, then replace the value that is being performed (typically the center value) with the sum-of-products.

The generalized kernel size (m x n) is given in the form: $m = 2a + 1$ and $n = 2b + 1$

NOTE: The form 2n + 1 is given to be a odd number. Therefore, m and n will always be odd for any integer a and b. This will grab the center pixel of an image. KERNEL SIZE MUST ALWAYS BE ODD

Handling Pixels Close to Boundaries

In order to deal with pixels that are close to boundaries, we use padding. There are two types of padding:

  1. Zero Padding - have the surrounding pixels of the center pixel be set to 0 (only applicable if its out of bounds–leave pixels that have a value be left alone).
  2. Replica Padding - have the surrounding pixels of the center pixel be set to the same value as the center pixel (only applicable if its out of bounds–leave pixels that have a value be left alone.)

Spatial Correlation and Convolution

There are two types of spatial operations:

  1. Convolution - is a mathematical operation to apply filters to images in the spatial domain. must flip kernel both horizontally and vertically before application.
  2. Correlation - it measures the similarity between an image and a kernel. flipping the kernel is not needed.

NOTE: To flip the kernel, first flip numbers that are found horizontally, then after applying the horizontal bit, then flip numbers in the vertical.

Separable Filter Kernels

A 2D Function $G(x,y)$ is said to be separable if it can be written as a product of two 1D functions: $G(x, y) = G_1(x) * G_2(y)$

A separable kernel of size $m * n$ can be expressed as the outer product of two vectors $v$ and $w$: $w = vw^t$ where $v$ and $w$ are vectors of size mx1 and nx1 respectively.

NOTE: if a square kernel with dimensions mxm, then it will be w = vv^t

The computational advantage of a kernel is represented as: $C = \frac{mn}{m+n}$

Reading

Summary