1 / 50

Spatial Filtering

Spatial Filtering. CS474/674 - Prof. Bebis Sections 3.4, 3.5, 3.6, 3.7, 3.8. output image. Spatial Filtering Methods. Spatial Filtering (cont’d). The word “filtering” comes from the frequency domain where “filters” are classified as: Low-pass (i.e., preserve low frequencies)

kjon
Download Presentation

Spatial Filtering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Spatial Filtering CS474/674 - Prof. Bebis Sections 3.4, 3.5, 3.6, 3.7, 3.8

  2. output image Spatial Filtering Methods

  3. Spatial Filtering (cont’d) • The word “filtering” comes from the frequency domain where “filters” are classified as: • Low-pass (i.e., preserve low frequencies) • High-pass (i.e., preserve high frequencies) • Band-pass (i.e., preserve frequencies within a band) • Band-reject (i.e., reject frequencies within a band)

  4. output image Spatial Filtering (cont’d) • Need to define: (1) a neighborhood (or mask) (2) an operation

  5. Spatial Filtering – Neighborhood (or Mask) • Typically, the neighborhood is rectangular and its size is much smaller than that of f(x,y) - e.g., 3x3 or 5x5

  6. output image Spatial filtering - Operation • Manipulate the pixel values, e.g., z’5 = 5z1 -3z2+z3-z4-2z5-3z6+z8-z9-9z7 z’5 = max(z1,z2,z3,z4,z5,z6,z7,z8,z9)

  7. output image Linear vs Non-Linear filters • A filter is called linear when its output is a linear combination of the inputs, e.g., z’5 = 5z1 -3z2+z3-z4-2z5-3z6+z8-z9-9z7

  8. output image Linear vs Non-Linear filters (cont’d) • A filter is called non-linearwhen its output is not a linear combination of the inputs, e.g., z’5 = max(z1,z2,z3,z4,z5,z6,z7,z8,z9)

  9. output image Correlation (linear operator) • The output of correlation is a weighted sum of input pixels. Need to define mask weights!

  10. w(i,j) Filtered Image f(i,j) Correlation (cont’d) g(i,j) Filtered image is generated by moving the center of the mask at every location of the input image.

  11. Handling Pixels Close to Boundaries pad with zeroes 0 0 0 ……………………….0 0 0 0 ……………………….0

  12. Correlation (cont’d) Often used in applications where we need to measure the similarity between images or parts of images (e.g., template matching).

  13. Convolution (linear operator) • Similar to correlation except that the mask is first flipped both horizontally and vertically. • If w(i, j) is symmetric (i.e., w(i, j)=w(-i,-j)),then convolution is equivalent to correlation!

  14. Example Correlation: Convolution:

  15. Filter Categories • We will focus on two types of filters: • Smoothing (low-pass) filters • Sharpening (high-pass) filters

  16. Smoothing Filters (low-pass) • Useful for reducing noise and eliminatingsmall details. • The elements of the mask must be positive. • Mask elements sum to 1 (assuming normalization).

  17. Smoothing filters – Example input image smoothed image

  18. Sharpening Filters (high-pass) • Useful for highlighting fine details. • The elements of the mask contain both positive and negative weights. • Mask elements sum to 0.

  19. Sharpening Filters - Example • Useful for highlighting fine details. • e.g., emphasize edges

  20. Sharpening Filters - Example input image sharpened image (for better visualization, the original image has been added to the sharpened image)

  21. Common Smoothing Filters • Averaging • Gaussian • Median filtering (non-linear)

  22. Smoothing Filters: Averaging

  23. Smoothing Filters: Averaging (cont’d) • Mask size determines degree of smoothing (i.e., loss of detail). original 3x3 5x5 7x7 15x15 25x25

  24. Smoothing Filters: Averaging (cont’d) Example: extract largest, brightest objects 15 x 15 averaging image thresholding

  25. Smoothing filters: Gaussian • The weights are samples of a 2D Gaussian function:

  26. Smoothing filters: Gaussian (cont’d) • Mask size depends on σ

  27. Smoothing filters: Gaussian (cont’d) • σ controls the amount of smoothing σ = 3 σ = 1.4

  28. Smoothing filters: Gaussian (cont’d)

  29. Averaging vs Gaussian Smoothing Averaging Gaussian

  30. Smoothing Filters: Median Filtering(non-linear) • Very effective for removing “salt and pepper” noise (i.e., random occurrences of black and white pixels). median filtering averaging

  31. Smoothing Filters: Median Filtering (cont’d) • Replace each pixel by the median in a neighborhood around the pixel. • The size of the neighborhood controls the amount of smoothing.

  32. Common Sharpening Filters • Unsharp masking • High Boost filter • Gradient (1st derivative) • Laplacian (2nd derivative)

  33. Sharpening Filters: Unsharp Masking • Obtain a sharp image by subtracting a lowpass filtered (i.e., smoothed) image from the original image: - = (with contrast enhancement)

  34. Sharpening Filters: High Boost • Image sharpening emphasizes edges but details are lost. • Idea: amplify input image, then subtract a lowpass image. (A-1) + =

  35. Sharpening Filters: High Boost (cont’d) • If A=1, the result is unsharp masking. • If A>1, part of the original image is added back to the high pass filtered image. High boost One way to implement high boost filtering is using the masks below

  36. Sharpening Filters: High Boost (cont’d) A=1.9 A=1.4

  37. Sharpening Filters: Derivatives • The derivative of an image results in a sharpened image. • Image derivatives can be computed using the gradient:

  38. Gradient • The gradient is a vector which has magnitude and direction: (approximation) or

  39. Gradient (cont’d) • Gradient magnitude: provides information about edge strength. • Gradient direction:perpendicular to the direction of the edge.

  40. Δx Gradient Computation • Approximate partial derivatives using finite differences:

  41. Gradient Computation (cont’d) f(x3,y3)-f(x3,y2) sensitive to horizontal edges y3-y2 y2=y3+Dy, y3=y, x3=x, Dy=1 sensitive to vertical edges

  42. Example: visualize partial derivatives

  43. Implement Gradient Using Masks • We can implement and using masks: (x+1/2,y) good approximation at (x+1/2,y) (x,y+1/2) * * good approximation at (x,y+1/2)

  44. Implement Gradient Using Masks (cont’d) • A different approximation of the gradient: good approximation (x+1/2,y+1/2) * • We can implement and using the following masks:

  45. Implement Gradient Using Masks (cont’d) • Other approximations Prewitt Sobel

  46. Example: Gradient Magnitude Image Gradient Magnitude (isotropic)

  47. Laplacian The Laplacian (2nd derivative) is defined as: (dot product) Approximate 2nd derivatives:

  48. Laplacian (cont’d) Laplacian Mask output image input image Edges can be found by detecting the zero-crossings 5 5 5 5 -5 -10 -5 -10 5 10 -10

  49. Example: Laplacian vs Gradient Sobel Laplacian • Laplacian localizes edges better (zero-crossings). • Higher order derivatives more sensitive to noise. • Laplacian is less computational expensive. • Laplacian can provide edge magnitude information • but no information about edge direction.

  50. Quiz 2 • When: Monday, September 30th • What: Spatial Filtering

More Related