Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 473/573 Computer Vision and Image Processing (CVIP) Ifeoma Nwogu Lecture 7 – Linear Filters 1.

Similar presentations


Presentation on theme: "CSE 473/573 Computer Vision and Image Processing (CVIP) Ifeoma Nwogu Lecture 7 – Linear Filters 1."— Presentation transcript:

1 CSE 473/573 Computer Vision and Image Processing (CVIP) Ifeoma Nwogu inwogu@buffalo.edu Lecture 7 – Linear Filters 1

2 Schedule Last class – Color Today – Linear filters and convolution Readings for today: Szeliski 3.2; Forsyth and Ponce 4.1-4.6(optional). 2

3 Slide Credits Rob Fergus – NYU Darell Trevor – UC Berkeley Fei Fei Li - Stanford Svetlana Lazebnik – UIUC David A. Forsyth - UIUC 3

4 Image Filters Smooth/Sharpen Images... Find edges... Find waldo… 4

5 Overview Images as functions Linear filters Convolution and correlation 5

6 Overview Images as functions Linear filters Convolution and correlation 6

7 Images as functions We can think of an image as a function, f, from R 2 to R : f( x, y ) gives the intensity at position ( x, y ) Realistically, we expect the image only to be defined over a rectangle, with a finite range: –f: [a,b] x [c,d]  [0, 1.0] A color image is just three functions pasted together. We can write this as a “vector-valued” function: Source: S. Seitz 7

8 Images as functions An image contains discrete number of pixels, e.g. – “grayscale” (or “intensity”): [0,255] Source: F.F Lei 8

9 Images as functions An image contains discrete number of pixels, e.g. – “grayscale” (or “intensity”): [0,255] – Color RGB: [R, G, B] Lab: [L, a, b] HSV: [H, S, V] Source: F.F Lei 9

10 Images as discrete functions 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. 1D 2D 10

11 Images as discrete functions Cartesian coordinates 11

12 Overview Images as functions Linear filters Convolution and correlation 12

13 Motivation Filtering: – Form a new image whose pixels are a combination original pixel values Goals: – Extract useful information from the images Features (edges, corners, blobs…) – Modify or enhance image properties: super-­resolution; in-painting; de­‐noising 13

14 Source: F.F. Li 14

15 Motivation: noise reduction We can measure noise in multiple images of the same static scene. How could we reduce the noise, i.e., give an estimate of the true intensities? What if there’s only one image? 15

16 Common types of noise – Salt and pepper noise: random occurrences of black and white pixels – Impulse noise: random occurrences of white pixels – Gaussian noise: variations in intensity drawn from a Gaussian normal distribution Source: S. Seitz 16

17 Gaussian noise Fig: M. Hebert >> noise = randn(size(im)).*sigma; >> output = im + noise; 17

18 Effect of sigma on Gaussian noise: Image shows the noise values themselves. 18

19 Effect of sigma on Gaussian noise: Image shows the noise values themselves. 19

20 Effect of sigma on Gaussian noise: Image shows the noise values themselves. 20

21 sigma=1 Effect of sigma on Gaussian noise: This shows the noise values added to the raw intensities of an image. 21

22 sigma=16 Effect of sigma on Gaussian noise This shows the noise values added to the raw intensities of an image. 22

23 First attempt at a solution Let’s 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 23

24 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 24

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

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

27 Moving Average In 2D 0000000000 0000000000 00090 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 0 0000000000 0000000000 000 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 Source: S. Seitz 27

28 Moving Average In 2D 0000000000 0000000000 00090 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 010 0000000000 0000000000 00090 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 Source: S. Seitz 28

29 Moving Average In 2D 0000000000 0000000000 00090 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 01020 0000000000 0000000000 00090 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 Source: S. Seitz 29

30 Moving Average In 2D 0000000000 0000000000 00090 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 0102030 0000000000 0000000000 00090 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 Source: S. Seitz 30

31 Moving Average In 2D 0102030 0000000000 0000000000 00090 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 Source: S. Seitz 31

32 Moving Average In 2D 0000000000 0000000000 00090 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 0102030 2010 0204060 4020 0306090 6030 0 5080 906030 0 5080 906030 0203050 604020 102030 2010 00000 Source: S. Seitz 32

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

34 Correlation filtering 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. This is called cross-correlation, denoted 34

35 Averaging filter What values belong in the kernel H for the moving average example? 0102030 0000000000 0000000000 00090 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 111 111 111 “box filter” ? 35

36 Smoothing by averaging depicts box filter original filtered 36

37 Gaussian filter 0000000000 0000000000 00090 00 000 00 000 00 000 0 00 000 00 0000000000 00 0000000 0000000000 121 242 121 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 37

38 Smoothing with a Gaussian 38

39 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 39

40 Gaussian filters What parameters matter here? Variance of Gaussian: determines extent of smoothing σ = 2 with 30 x 30 kernel σ = 5 with 30 x 30 kernel 40

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

42 Boundary issues What is the size of the output? MATLAB: filter2(g, f, shape) – 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 difference of sizes of f and g f gg gg f gg g g f gg gg full samevalid Source: S. Lazebnik 42

43 Boundary issues What about near the edge? – the filter window falls off the edge of the image – need to extrapolate – methods: clip filter (black) wrap around copy edge reflect across edge Source: S. Marschner 43

44 Boundary issues What about near the edge? – the filter window falls off the edge of the image – need to extrapolate – methods (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 44

45 Filtering an impulse signal 0000000 0000000 0000000 0001000 0000000 0000000 0000000 abc def ghi What is the result of filtering the impulse signal (image) F with the arbitrary kernel H? ? 45

46 0000000 0000000 0000000 0001000 0000000 0000000 0000000 Filtering an impulse signal (correlation) 0000000 0000000 0000000 0001000 0000000 0000000 0000000 abc def ghi What is the result of filtering the impulse signal (image) F with the arbitrary kernel H? ihg fed cba 46

47 0000000 0000000 0000000 0001000 0000000 0000000 0000000 Filtering an impulse signal (convolution) 0000000 0000000 0000000 0001000 0000000 0000000 0000000 abc def ghi What is the result of filtering the impulse signal (image) F with the arbitrary kernel H? abc def ghi 47

48 Convolution Convolution: – Flip the filter in both dimensions (bottom to top, right to left) – Then apply cross-correlation Notation for convolution operator F H 48

49 Convolution vs. correlation Convolution Cross-correlation For a Gaussian or box filter, how will the outputs differ? If the input is an impulse signal, how will the outputs differ? 49

50 Convolution Convolution: – Flip the filter in both dimensions (bottom to top, right to left) – Then apply cross-correlation Notation for convolution operator F H 50

51 Smoothing with a Gaussian for sigma=1:3:10 h = fspecial('gaussian‘, fsize, sigma); out = imfilter(im, h); imshow(out); pause; end … Parameter σ is the “scale” / “width” / “spread” of the Gaussian kernel, and controls the amount of smoothing. 51

52 Convolving with linear filters 000 010 000 Original ? Source: D. Lowe 52

53 Convolving with linear filters 000 010 000 Original Source: D. Lowe Filtered (no change) 53

54 Convolving with linear filters 000 100 000 ? Source: D. Lowe Original 54

55 Convolving with linear filters 000 100 000 Source: D. Lowe OriginalShifted left by 1 pixel with correlation 55

56 Practice with linear filters ? 111 111 111 Source: D. Lowe Original 56

57 Practice with linear filters ? 111 111 111 Source: D. Lowe OriginalBlur (with a box filter) 57

58 Practice with linear filters 111 111 111 000 020 000 - ? Source: D. Lowe Original 58

59 Practice with linear filters 111 111 111 000 020 000 - ? Source: D. Lowe Original Sharpening filter - Accentuates differences with local average 59

60 What does blurring remove? Now let’s add it back…… 60

61 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 * (k f) = k (h * f) 61

62 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: 62

63 Separability In some cases, filter is separable, and we can factor into two steps: – Convolve all rows – Convolve all columns 63

64 Separability In some cases, filter is separable, and we can factor into two steps: e.g., What is the computational complexity advantage for a separable filter of size k x k, in terms of number of operations per output pixel? f * (g * h) = (f * g) * h g h f 64

65 Median filter No new pixel values introduced Removes spikes: good for impulse, salt & pepper noise 65

66 Median filter Salt and pepper noise Median filtered Source: M. Hebert Plots of a row of the image 66

67 Median filter Median filter is edge preserving 67

68 Filters for features Previously, thinking of filtering as a way to remove or reduce noise Now, consider how filters will allow us to abstract higher-level “features”. – Map raw pixels to an intermediate representation that will be used for subsequent processing – Goal: reduce amount of data, discard redundancy, preserve what’s useful 68

69 Template matching Filters as templates: Note that filters look like the effects they are intended to find --- “matched filters” Use normalized cross-correlation score to find a given pattern (template) in the image. – Szeliski Eq. 8.11 Normalization needed to control for relative brightnesses. 69

70 Template matching Scene Template (mask) A toy example 70

71 Template matching Template Detected template 71

72 Template matching Detected templateCorrelation map 72

73 Where’s Waldo? Scene Template 73

74 Where’s Waldo? Scene Template 74

75 Where’s Waldo? Detected templateCorrelation map 75

76 Template matching Scene Template What if the template is not identical to some subimage in the scene? 76

77 Template matching Detected template Template Match can be meaningful, if scale, orientation, and general appearance is right. 77

78 Filters and Convolution - Crucial Points A filter is a pattern of weights (<< ||image||) Convolution applies the filter to the image Output measures similarity between filter and image patch – only a rough estimate Normalized correlation gives improved pattern detection 78

79 Next class Pyramids and scale space Readings for next lecture: – Forsyth and Ponce 4.7; Szeliski 3.5 (optional) Readings for today: – Szeliski 3.2, Forsyth and Ponce 4.1- 4.6(optional). 79

80 Questions 80


Download ppt "CSE 473/573 Computer Vision and Image Processing (CVIP) Ifeoma Nwogu Lecture 7 – Linear Filters 1."

Similar presentations


Ads by Google