Spatial Filtering Dr. Praveen Sankaran Department of ECE NIT Calicut January 7, 203
Outline 2 Linear Nonlinear 3
Spatial Domain Refers to the image plane itself. Direct manipulation of image pixels. Figure: Spatial Filtering with a 3 3 mask (kernel, template or window)
Spatial Filter
Correlation and Convolution - Representations Correlation w (m, n) g (m, n) = a b s= a t= b w (s, t) g (m + s, y + t) Convolution w (m, n) g (m, n) = a b s= a t= b w (s, t) g (m s, y t)
Generating a Gaussian Mask Creating a lter essentially boils down to specifying the values of mask coecients. Basic form h (x, y) = e x2 +y 2 2σ 2 sample, quantize h (m, n) = e m2 +n 2 2σ 2 Sample the continuous function about its center. w w 2 w 3 h (, ) h (0, ) h (, ) w 4 w 5 w 6 = h (,0) h (0,0) h (,0) w 7 w 8 w 9 h (,) h(0,) h (,)
Outline Linear Nonlinear 2 Linear Nonlinear 3
Averaging Filters Linear Nonlinear Objective Noise reduction by reducing sharp transitions in intensities. We have seen an averaging lter before. These are also referred to as low pass lters. Creating an averaging lter - replace pixel with average intensity in neighborhood Average = 9 9 i= g i = 9 i= 9 g i, 9 9 9 9 9 9 9 9 9 averaging mask Note that we are giving equal weight to the pixel under consideration and the pixel values around it.
Averaging Filters - Weighted Linear Nonlinear Idea replace pixel value under consideration with a weighted average of values in mask region. Multiply pixel values with dierent mask coecients. Done to reduce blurring. 6 2 2 4 2 2 a s= a b t= b w (s, t) g (m ± s, y ± t) i (m, n) = a s= a b t= b w (s, t), m = 0,, M, n = 0,,2, N. Note that we need not worry about our operation being convolution or correlation with these masks.
Filter Size Matters Linear Nonlinear Figure: Eect of varying lter sizes on an Image. Original image with size 500 500. Filter sizes with m = 3, 5, 9, 5, 35
Outline Linear Nonlinear 2 Linear Nonlinear 3
Linear Nonlinear Order-Statistic (Nonlinear) Filters - Median Filter Replace value of a pixel by the median of the pixel values in the mask region or region-of-interest (ROI). Typical application remove salt-&-pepper (?) noise.
Outline 2 Linear Nonlinear 3
First Derivative Must be zero in areas of constant intensity; 2 Must be non-zero at the onset of an intensity step or ramp; 3 Must be non-zero along ramps. = f (x +, y) f (x, y), remember the problem we talked about earlier? 4 f x From Taylor's theorem, f (x ± ξ, y) = f (x, y) + f (x,y) (±ξ ) + 2 f (x,y) x 2! x 2 ξ 2 + Ignoring higher order terms we end up with three dierent scenarios.
Diering Approximations f (x,y) x f (x+ξ,y) f (x,y) ξ 2 f (x,y) x f (x,y) f (x ξ,y) ξ 3 f (x,y) x f (x+ξ,y) f (x ξ,y) 2ξ Substituting ξ =, three separate, corresponding operators can be formed for a digital image. Which one do we choose? g [m +, n] g [m, n] g [m, n] g [m, n] g[m+,n] g[m,n] 2
Second Derivative Must be zero in areas of constant intensity; 2 Must be non-zero at the onset and end of an intensity step or ramp; 3 Must be zero along ramps of constant slope.
The Laplacian Laplacian 2 f (x, y) = 2 f (x,y) x 2 + 2 f (x,y) y 2 From Taylor's theorem, f (x ± ξ, y) = f (x, y) + f (x,y) x (±ξ ) + 2! f (x,y) x f (x+ξ,y) f (x ξ,y) 2ξ, ξ = 2 f x 2 f (x +, y) + f (x, y) 2f (x, y) and, 2 f y 2 f (x, y + ) + f (x, y ) 2f (x, y) 2 f (x,y) x 2 ξ 2 +, and take
The Laplacian Laplacian 2 f (x, y) = 2 f (x,y) x 2 + 2 f (x,y) y 2 From Taylor's theorem, f (x ± ξ, y) = f (x, y) + f (x,y) x (±ξ ) + 2! f (x,y) x f (x+ξ,y) f (x ξ,y) 2ξ, ξ = 2 f x 2 f (x +, y) + f (x, y) 2f (x, y) and, 2 f y 2 f (x, y + ) + f (x, y ) 2f (x, y) 2 f (x,y) x 2 ξ 2 +, and take
The Laplacian (Final Approximated Form) Laplacian Form in digital image 2 g g [m +, n] + g [m, n] + g [m, n + ] + g [m, n ] 4g [m, n]. Mask Values 0 0 4 0 0 Note that any dierent approximation of the Taylor series expansion could have given a dierent form for the Laplacian.
Using Laplacian to Sharpen an Image i (m, n) = g [m, n] + c [ 2 g [m, n] ] Add Laplacian image to the original.
Unsharp Masking and Highboost Filtering Blur the original image; 2 Subtract the blurred image from the original (this forms the mask); 3 Add mask to the original. i mask [m, n] = g [m, n] g avg [m, n], g [m, n] = g [m, n] + k i mask [m, n] If k =, process = unsharp masking. If k >, process = highboost ltering.
First Gradients - Robert's We dene an image j [m, n] = image. ( ) Roberts [965] g = (w m 9 w 5 ), ( ) g = n (w 8 w 6 ) gradient image = [ ] i [m, n] = (w 9 w 5 ) 2 + (w 8 w 6 ) 2 ( )2 ( ) g + g 2 m n gradient w w 2 w 3 w 4 w 5 w 6 w 7 w 8 w 9 [ ] [ ] 0 0 0 0
Sobel Operator Roberts had a mask of even size no center of symmetry. Approximate ( g m ) = (w 7 + 2w 8 + w 9 ) (w + 2w 2 + w 3 ), ( g n ) = (w 3 + 2w 6 + w 9 ) (w + 2w 4 + w 7 ) w w 2 w 3 w 4 w 5 w 6 w 7 w 8 w 9 2 0 0 0 0 2 0 2 2 0
Application of Spatial approach to: Low pass ltering. Sharpening. First gradient, Roberts, Sobel. Second gradient, Laplacian Application of gradient to sharpening.
Questions 3., 3.2, 3.3, 3.4, 3.5 3.6, 3.7, 3. 3.3, 3.4 3.5, 3.6, 3.7,3.8, 3.26, 3.27, 3.28