1 / 95

Spatial Filtering

Spatial Filtering. Dan Witzner Hansen. R ecap. Exercises??? Feedback Last lectures?. Digital images. In computer vision we operate on digital (discrete) images: Sample the 2D space on a regular grid Quantize each sample (round to nearest integer)

carlow
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 Dan Witzner Hansen

  2. Recap • Exercises??? • Feedback • Last lectures?

  3. Digital images • In computer vision we operate on digital (discrete) images: • Sample the 2D space on a regular grid • Quantize each sample (round to nearest integer) • Image thus represented as a matrix of integer values. 2D 1D Adapted from S. Seitz

  4. What is point processing? • Only one pixel in the input has an effect on the output • For example: • Changing the brightness, thresholding, histogram stretching Input Output

  5. Image neighborhoods • Q: What happens if we reshuffle all pixels within the images? • A: Its histogram won’t change. Point-wise processing unaffected. • Need to measure properties relative to small neighborhoods of pixels

  6. Why use proximity • Noise reduction • Smoothing • Feature detection • Correlation

  7. What are they good for? • Improve Search • Search over translations • Classic coarse-to-fine strategy • Search over scale • Template matching • E.g. find a face at different scales • Precomputation • Need to access image at different blur levels • Useful for texture mapping at different resolutions (called mip-mapping) • Image Processing • Editing frequency bands separately • E.g. image blending…

  8. Motivation: noise reduction

  9. Common types of noise • Salt and pepper noise: random occurrences of black and white pixels • Impulse noise: random occurrences of white pixels • Gaussian (additive) noise: variations in intensity drawn from a Gaussian normal distribution Source: S. Seitz

  10. Gaussian noise Ideal Image Noise process >> noise = randn(size(im)).*sigma; >> output = im + noise; Fig: M. Hebert

  11. Changing Sigma and zero mean

  12. First attempt at a solution Replace each pixel with an average of all the values in its neighborhood Assumptions: • Expect pixels to be like their neighbors • Expect noise processes to be independent from pixel to pixel

  13. First attempt at a solution • Let’s replace each pixel with an average of all the values in its neighborhood • Moving average in 1D: Source: S. Marschner

  14. Weighted Moving Average • Can add weights to our moving average • Weights [1, 1, 1, 1, 1] / 5 Source: S. Marschner

  15. Weighted Moving Average • Non-uniform weights [1, 4, 6, 4, 1] / 16 Source: S. Marschner

  16. Neighborhood processing Several pixels in the input has an effect on the output Input Output

  17. Moving Average In 2D Source: S. Seitz

  18. Moving Average In 2D Source: S. Seitz

  19. Moving Average In 2D Source: S. Seitz

  20. Moving Average In 2D Source: S. Seitz

  21. Moving Average In 2D Source: S. Seitz

  22. Moving Average In 2D Source: S. Seitz

  23. Correlation filtering Say the averaging window size is 2k+1 x 2k+1: Attribute uniform weight to each pixel Loop over all pixels in neighborhood around image pixel F[i,j] Now generalize to allow different weights depending on neighboring pixel’s relative position: Non-uniform weights

  24. Correlation filtering This is called cross-correlation, denoted Filtering an image: replace each pixel with a linear combination of its neighbors. The filter “kernel” or “mask” H[u,v] is the prescription for the weights in the linear combination. Assume the kernel H has weights 0 ‘outside’ the finite region

  25. 1 1 1 1 1 1 1 1 1 Averaging filter What values belong in the kernel H for the moving average example? ? “box filter”

  26. Smoothing by averaging depicts box filter: white = high value, black = low value filtered original

  27. Gaussian filter What if we want nearest neighboring pixels to have the most influence on the output? This kernel is an approximation of a Gaussian function: Source: S. Seitz

  28. Smoothing with a Gaussian

  29. Gaussian filters What parameters matter here? Size of kernel or mask • Note, Gaussian function has infinite support, but discrete filters use finite kernels σ = 5 with 10 x 10 kernel σ = 5 with 30 x 30 kernel

  30. Gaussian filters Variance of Gaussian: determines extent of smoothing σ = 2 with 30 x 30 kernel σ = 5 with 30 x 30 kernel

  31. Matlab >> hsize = 10; >> sigma = 5; >> h = fspecial(‘gaussian’ hsize, sigma); >> mesh(h); >> imagesc(h); >> outim = imfilter(im, h); >> imshow(outim);

  32. The effect of smoothing and noise Wider smoothing kernel  More noise 

  33. Boundary issues • What is the size of the output? • MATLAB: filter2(g, f, shape) / conv2 • shape = ‘full’: output size is sum of sizes of f and g • shape = ‘same’: output size is same as f • shape = ‘valid’: output size is the difference of sizes of f and g full same valid g g g g f f g f g g g g g Source: S. Lazebnik g g

  34. Boundary issues • What about near the edge? • the filter window falls off the boundaries of the image • methods: clip filter (black) wrap around copy edge reflect across edge Source: S. Marschner

  35. Boundary issues in Matlab clip filter (black): imfilter(f, g, 0) wrap around:imfilter(f, g, ‘circular’) copy edge: imfilter(f, g, ‘replicate’) reflect across edge: imfilter(f, g, ‘symmetric’) Source: S. Marschner

  36. Filtering an impulse signal What is the result of filtering the impulse signal (image) F with the arbitrary kernel H? ?

  37. Convolution • Convolution: • Flip the filter in both dimensions (bottom to top, right to left) • Then apply correlation F H Notation for convolution operator

  38. Convolution vs. correlation Convolution Cross-correlation

  39. Shift invariant linear system • Shift invariant: Operator behaves the same everywhere, i.e. the value of the output depends on the pattern in the image neighborhood, not the position of the neighborhood. • Linear: Superposition: h * (f1 + f2) = (h * f1) + (h * f2) Scaling: h * (kf) = k (h * f)

  40. Properties of convolution • Linear & shift invariant • Commutative: f* g = g * f • Associative (f * g) * h = f * (g * h) • Identity: unit impulse e = […, 0, 0, 1, 0, 0, …]. f* e = f • Differentiation:

  41. How to do color blurring?

  42. 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 2 0 1 1 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0 1 Predict the filtered outputs = ? = ? * * - = ? *

  43. 0 0 0 0 1 0 0 0 0 Practice with linear filters ? Original Source: D. Lowe

  44. 0 0 0 0 1 0 0 0 0 Practice with linear filters Original Filtered (no change) Source: D. Lowe

  45. 0 0 0 0 0 1 0 0 0 Practice with linear filters ? Original Source: D. Lowe

  46. 0 0 0 0 0 1 0 0 0 Practice with linear filters Original Shifted left by 1 pixel with correlation Source: D. Lowe

  47. 1 1 1 1 1 1 1 1 1 Practice with linear filters ? Original Source: D. Lowe

  48. 1 1 1 1 1 1 1 1 1 Practice with linear filters Original Blur (with a box filter) Source: D. Lowe

  49. 0 1 0 1 1 0 1 0 1 2 1 0 1 0 1 0 1 0 Practice with linear filters - ? Original Source: D. Lowe

  50. 0 1 0 1 1 0 1 0 1 2 1 0 1 0 1 0 1 0 Practice with linear filters - Original • Sharpening filter • Accentuates differences with local average Source: D. Lowe

More Related