Digital Image Processing Lecture 5 Neighborhood Processing Spatial
Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai
Spatial Filtering n n n Definition: a process that moves a subimage from point to point in an image, with the response at each image point predefined. The subimage: filter, mask, kernel, template or window. The values in a filter subimage are called coefficients, not pixels. The process is also named convolution. Convolution of 2 D function and is denoted or 2
Illustration y origin W(-1, -1) W(-1, 0) W(-1, 1) mask W(0, -1) W(0, 0) W(0, 1) W(1, -1) W(1, 0) W(1, 1) f(x-1, y-1) f(x-1, y+1) f(x, y-1) f(x, y+1) Mask coefficients x f(x+1, y-1) f(x+1, y+1) Image section under mask 3
Example 1: Averaging n One simple example is smoothing using a 3 x 3 mask. f(x-1, y-1) f(x-1, y+1) f(x, y-1) f(x, y+1) f(x+1, y-1) f(x+1, y+1) 1/9 1/9 1/9 4
Example 2: Delta/Impulse Funciton n An ideal impulse is defined using the Dirac distribution n To visualize in 1 D, picture a rectangular pulse from to with a height of. As , the width tends to 0 and the height tends to infinity as the total area remains constant at 1. 1 5
(cont) n Sifting property: It provides the value of f(x, y) at the point (a, b) n Delta function as the mask. q q When moving across an image, it “copies” the value of image intensity. 6
General Formulation n 2 D Continuous space: n 2 D discrete space: n In digital image processing, we only deal with discrete space with a mask effective locally. Convolution is commutative, associative and distributive. n Convolution kernel/mask 7
What happens at the borders? n n The mask falls outside the edge. Solutions? q Ignore the edges n q The resultant image is smaller than the original Pad with zeros n Introducing unwanted artifacts 8
Values Outside the Range n n Linear filtering might bring the intensity outside the display range. Solutions? q Clip values q Scaling transformation New min New max Transform values in [g. L, g. H] to [0, 255] 9
Separable Filters n Some filters can be implemented by successive application of two simpler filters. n Separability results in great time saving. By how much? n q For a mask of size nxn, for each image pixel n n Originally, n 2 multiplications and n 2 -1 additions After separation, 2 n multiplications and 2 n-2 additions 10
Some terminology on Frequency… n n n Frequencies: a measure of the amount by which gray values change with distance. High/low-frequency components: large/small changes in gray values over small distances. High/low-pass filter: passing high/low components, and reducing or eliminating low/high-frequency filter. 11
Low-Pass Filter n Mostly for noise reduction/removal and smoothing q q 3 x 3 averaging filter to blur edges Gaussian filter, n n n based on Gaussian probability distribution function a popular filter for smoothing more later when we discuss image restoration In 1 D: 12
High-Pass Filter n The Laplacian, , is a high-pass filter, or n n Sum of coefficients is zero Insight: in areas where the gray values are similar (low-frequency), application of the filter makes the gray values close to zero. 13
Laplacian Operator n Laplacian is a derivative operator – 2 nd order derivative n Highlighting graylevel discontinuities. An edge detector isotropic in x- and y-direction. n n 14
Laplacian Operator (con’d) n We may add the diagonal terms too => isotropic results for increments of or n There are other variations/approximations: Separable filter 15
Laplacian Filter: Demo Original Laplacian-filtered 16
Laplacian: Application n n Laplacian highlights discontinuities, and turn featureless regions into dark background. How can we make good use of the property? q One example is edge enhancement original Laplacian enhanced 17
More Filters … n What feature does each mask highlight? 18
Edge Sharping n n To make edges slightly sharper and crisper. This operation is referred to as edge enhancement, edge crispening or unsharp masking. A very popular practice in industry. Subtracting a blurred version of an image from the image itself. Blurred image Sharpened image Original image 19
Unsharp Masking: Why it works f(x, y) blurred image Sharpened 20
Filter for Unsharp Masking n Combining filtering and subtracting in one filter. n Schematically, Subtract Original Blur with low-pass filter Scale with A<1 Scale for display 21
High-Boost Filtering n Generalization of unsharp masking n n Here A is called boost coefficient, and We rewrite the equation as n Applicable to any sharpening operation q q can be The filter for fhb becomes 22
High-Boost Filtering: Demo n By varying A, better overall brightness can be improved. original A=1 A=0 A=1. 7, much brighter 23
Nonlinear Filters n n Will discuss some of them in more detail later for the purpose of image restoration. Maximum filter: the output the maximum value under the mask Minimum filter: the output the minimum value under the mask Rank-order filter: q q q Elements under the mask are ordered, and a particular value is returned. Both maximum and minimum filter are instances of rankorder Another popular instance is median filter 24
More Nonlinear Filters n Alpha-trimmed mean filter: q q q Order the values under the mask Trim off elements at either end of the ordered list Take the mean of the remainder E. g. assuming a 3 x 3 mask and the ordered list Trimming of two elements at either end, the result of the filter is 25
Summary n n We introduced the concept of convolution We briefly discussed spatial filters of q q q n Low-pass filter for smoothing High-pass filter for edge sharpening Nonlinear We’ll come back to most of the filters under the appropriate topics. 26
27
- Slides: 27