Download Spatial Filtering-Digital Image Processing-Lecture 07 Slides Slides-Electrical and Computer Engineering and more Slides Digital Image Processing in PDF only on Docsity!
Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-
Computer Vision &
Digital Image Processing
Spatial Filtering
Spatial filtering
- Use of spatial masks for filtering is called spatial filtering
- May be linear or nonlinear
- Linear filters
- Lowpass : attenuate (or eliminate) high frequency components such as characterized by edges and sharp details in an image - Net effect is image blurring
- Highpass : attenuate (or eliminate) low frequency components such as slowly varying characteristics - Net effect is a sharpening of edges and other details
- Bandpass : attenuate (or eliminate) a given frequency range
- Used primarily for image restoration (are of little interest for image enhancement)
Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-
Spatial filters (examples)
- Filters in the frequency domain and corresponding spatial filters
- Basic approach is to sum products between mask coefficients and pixel values - R = w 1 z 1 + w 2 z 2 +.... + w 9 z 9
Spatial filter masks
w 1 w 2 w 3 w 4 w 5 w 6 w 7 w 8 w 9
- If the center of the mask is at (x,y), then the pixel value at (x,y) is replaced by R
- This continues until all pixels in the image are covered
- For pixels near the boundary of the image, R may be computed using partial neighborhoods or by padding the input appropriately
- Usual practice is to create a new image with the values of R ( as opposed to modifying pixels in the original image)
Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-
Averaging filter example
Smoothing filter examples
Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-
Smoothing filters (continued)
- One problem with the lowpass filter is it blurs edges and other sharp details
- If the intent is to achieve noise reduction, one approach can be to use median filtering - The value of each pixel is replaced by the median pixel value in the neighborhood (as opposed to the average) - Particularly effective when the noise consists of strong, spike like components and edge sharpness is to be preserved - The median m of a set of values is such that half of the values are greater than m and half are less than m - To implement, sort the pixel values in the neighborhood, choose the median and assign this value to the pixel of interest - Forces pixels with distinct intensities to be more like their neighbors
Median filtering example
Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-
Highpass filter example
Sharpening filters (continued)
- A highpass filter may be computed as: Highpass = Original - Lowpass
- Multiplying the original by an amplification factor yields a highboost or high-frequency-emphasis filter - If A>1, part of the original image is added to the highpass result (partially restoring low frequency components) - Result looks more like the original image with a relative degree of edge enhancement that depends on the value of A - May be implemented with the center coefficient value w=9A-1 (Aโฅ1)
A Original Highpass
A Original Original Lowpass
Highboost AOriginal Lowpass
= โ +
= โ + โ
= โ
( 1 )( )
( 1 )( )
( )
Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-
Highboost filter example
A=1.
A=1.15 A=1.
Derivative Functions
โข A basic first-order derivative of a 1-D function, f ( x ),
is the difference
โข The second-order derivative of f ( x ) is the difference
f ( x 1 ) f ( x ) x
f = + โ โ
2 (^1 ) (^1 )^2 (^ )
2 f x f x f x x
f = + + โ โ โ
โ
Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-
Derivative filters (continued)
- The magnitude of the gradient at z 5 can be approximated in a number of ways
- The simplest is to use the difference (z 5 -z8 ) in the x direction and (z 5 -z 6 ) in the y direction
- or approximated as
z 1 z 2 z (^3) z 4 z 5 z (^6) z 7 z 8 z (^9)
21 / 2 5 6
2
โ f =[( z 5 โ z 8 ) +( z โ z ) ]
โ f โ| z 5 โ z 8 |+| z 5 โ z 6 |
Derivative filters (continued)
- A cross difference may also be used to approximate the magnitude of the gradient
- This can be implemented by taking the absolute value of the response of the following two masks (the Roberts cross- gradient operators ) and summing the results
21 / 2 6 8
2
โ f =[( z 5 โ z 9 ) +( z โ z ) ]
โ f โ| z 5 โ z 9 |+| z 6 โ z 8 |
Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-
Derivative filters (continued)
- Extension to a 3x3 mask yields the following
- The difference between the first and third rows approximates the derivative in the x direction
- The difference between the first and third columns approximates the derivative in the y direction
- The Prewitt operator masks may be used to implement the above approximation
โ f โ| ( z 7 + z 8 + z 9 )โ( z 1 + z 2 + z 3 )|+|( z 3 + z 6 + z 9 )โ( z 1 + z 4 + z 7 ) |
Derivative filters (continued)
- The Sobel operator masks may also be used to implement the derivative approximation
- The Sobel operators are widely used for edge detection (will be discussed in more detail later)
- NOTE: All the mask coefficients for all the derivative filters sum to zero, indicating a 0 response in a constant area (as expected of a derivative operator)
Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-
Derivative filter example (continued)
g=derivativefilter(f,'Sobel',15, 'horiz',0);
g=derivativefilter(f,'Sobel',10, 'vert',0);
Derivative filter example (continued)
g=derivativefilter(f,'Sobel',10,'max',0); g=derivativefilter(f,'Sobel',10,'max',1);