Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of Spatial Filtering

Similar presentations


Presentation on theme: "Fundamentals of Spatial Filtering"— Presentation transcript:

1 Fundamentals of Spatial Filtering
D. Veton Kepuska based on Digital Image processing by r.C. Gonzalez and R.W. Woods

2 Fundamentals of Spatial Filtering
In this chapter we will discuss the use of spatial filters for image processing. Spatial filtering is used in a broad spectrum of image processing applications, so a solid understanding of filtering principles is important. The filtering examples in this section deal mostly with image enhancement. The name filter is borrowed from frequency domain processing and it refers to passing, modifying, or rejecting specified frequency components of an image. Example: Filter that passes low frequencies is called a lowpass filter. The effect of applying lowpass filter in the image is to smooth it and consequently blurring the image. We can accomplish this filtering effects similar to smoothing directly on the image itself by using spatial filters. Spatial filtering modifies an image by replacing the value of each pixels by function of the values of the pixels and its neighbors. If the operation performed on the image pixels is linear, then the filter is called a linear spatial filter. Otherwise the filter is a nonlinear spatial filter.

3 Linear Spatial Filtering
A linear spatial filter performs a sum-of-products operation between an image 𝑓 and a filter kernel, 𝑤. The kernel is an array whose size defines the neighborhood of operation, and whose coefficients determine the nature of the filter. Other terms used to refer to a spatial filter kernel are mask, template, and window. Filter kernel or simply kernel will be used. Figure 3.24 illustrates the mechanics of linear spatial filtering using a 3x3 kenel. At any point (x,y) in the image, the response, 𝒈(𝒙,𝒚). Of the filter is the sum of products of the kernel coefficients and the image pixels encompassed by the kernel. 𝑔 𝑥,𝑦 = 𝑤 −1,−1 𝑓 𝑥−1,𝑦−1 +𝑤 −1,0 𝑓 𝑥−1,𝑦 +⋯ 𝑤 0,0 𝑓 𝑥,𝑦 +⋯ 𝑤 1,0 𝑓 𝑥+1,𝑦 +𝑤 1,1 𝑓(𝑥+1,𝑦+1) (3-40) As coordinates of 𝑥,𝑦 are varied, the center of the kernel moves from pixel to pixel, generating the filtered image, 𝑔, in the process

4 Linear Spatial Filtering
Kernel coefficient 𝑤(0,0) align with the pixel at location (𝑥,𝑦). For kernel of size 𝑚x𝑛, we assume that 𝑚=2𝑎+1 and 𝑛=2𝑏+1, where a and b are nonnegative integers. Kernels are of odd sizes in both coordinate directions (why?). Filtering operation of an image of size 𝑴x𝑵 with a kernel of size 𝒎x𝒏 is given by the expression: 𝑔 𝑥,𝑦 = 𝑠=−𝑎 𝑎 𝑡=−𝑏 𝑏 𝑤 𝑠,𝑡 𝑓 𝑥+𝑠,𝑦+𝑡 (3-40) where 𝑥 and 𝑦 are varied so that the center (origin) of the center of the kernel visits every pixel in 𝑓 once. For a fixed value of (x,y), Eq.(3-40) implements the sum of products of the form shown in in Eq. (3-39) This equation representes a central tool in linear filtering operation.

5 Spatial Correlation and Convolution

6 Spatial Correlation and Convolution
Spatial correlation is illustrated graphically in the Fig. 3.34, presented here for convenience. This process is described by the Eq. (3-40) algebraically. Correlation consist of moving the center of a kernel over an image, and computing the sum of products at each location. The mechanics of spatial convolution are the same, except that the correlation kernel is rotated by If values of a kernel are symmetric about its center, correlation and convolution yield the same result.

7 Example of Correlation vs. Convolution
1-D example of correlation by applying the Eq. (3-40): 𝑔 𝑥 = 𝑠=−𝑎 +𝑎 𝑤 𝑠 𝑓(𝑥+𝑠) (3-41) Figure 3.35(a) shows a 1-D function, f, and a correlation kernel, w; {1,2,4,2,8} Figure 3.35(i) shows the same 1-D function, f, and a convolution kernel, w; {8,2,4,2,1} First thing to notice is edge effects where the kernel w lies outside f, so the summation is undefined in that area. Solution: Padding function f with enough 0’s on either side, or a first value of the data array, or reflected values of the actual data. For the kernel of size 1xm, we need (m-1)/2 zeros (depending of the approach we take) on either side of f in order to handle the beginning and ending configurations of w with respect to f. Figure 3.35(c) shows a properly padded function. In this starting configuration, all coefficients of the kernel overlap valid values.

8 Example of Correlation vs. Convolution
Correlation computation Initial application of Eq. (3-41) with 𝑥=0: 𝑔 0 = 𝑠=−2 +2 𝑤 𝑠 𝑓 𝑠+0 =0 To obtain the second value 𝑔(1) we need to shift the relative position of 𝑤 and 𝑓 one pixel location to the right, i.e., 𝑥 = 1, and compute sum of product once again, etc. The result of this, as indicated in the right side, is: x=1 & 𝑔 1 =8, x=2 & 𝑔 2 =2, 𝑥= 3 & 𝑔 3 =4, etc.


Download ppt "Fundamentals of Spatial Filtering"

Similar presentations


Ads by Google