Image Filtering and Image Frequencies Various slides from previous - - PowerPoint PPT Presentation

image filtering and image frequencies
SMART_READER_LITE
LIVE PREVIEW

Image Filtering and Image Frequencies Various slides from previous - - PowerPoint PPT Presentation

CS4501: Introduction to Computer Vision Image Filtering and Image Frequencies Various slides from previous courses by: D.A. Forsyth (Berkeley / UIUC), I. Kokkinos (Ecole Centrale / UCL). S. Lazebnik (UNC / UIUC), S. Seitz (MSR / Facebook), J.


slide-1
SLIDE 1

CS4501: Introduction to Computer Vision

Image Filtering and Image Frequencies

Various slides from previous courses by: D.A. Forsyth (Berkeley / UIUC), I. Kokkinos (Ecole Centrale / UCL). S. Lazebnik (UNC / UIUC), S. Seitz (MSR / Facebook), J. Hays (Brown / Georgia Tech), A. Berg (Stony Brook / UNC), D. Samaras (Stony Brook) . J. M. Frahm (UNC), V. Ordonez (UVA).

slide-2
SLIDE 2
  • The Human Eye as a Camera
  • Images as Matrices
  • Images as Functions
  • Image Processing
  • Image Filtering

Last Class

slide-3
SLIDE 3
  • Image Filtering: Mean Filter
  • Image Blurring
  • Image Gradients: The Sobel Operator
  • Image Frequencies

Today’s Class

slide-4
SLIDE 4

Image Processing & Image Filtering

slide-5
SLIDE 5

Basic Image Processing

! "!

" > 1

slide-6
SLIDE 6

Basic Image Processing

! "!

0 < " < 1

slide-7
SLIDE 7

Color Images as Tensors

!ℎ#$$%& ' ℎ%()ℎ* ' +(,*ℎ Channels are usually RGB: Red, Green, and Blue Other color spaces: HSV, HSL, LUV, XYZ, Lab, CMYK, etc

slide-8
SLIDE 8

Image filtering

slide-9
SLIDE 9

Image filtering

Image Credit: http://what-when-how.com/introduction-to-video-and-image-processing/neighborhood-processing-introduction-to-video-and-image-processing-part-1/

slide-10
SLIDE 10

Image filtering: e.g. Mean Filter

slide-11
SLIDE 11

Image filtering: e.g. Mean Filter

slide-12
SLIDE 12

Image filtering: e.g. Median Filter

Image Credit: http://what-when-how.com/introduction-to-video-and-image-processing/neighborhood-processing-introduction-to-video-and-image-processing-part-1/

slide-13
SLIDE 13

Image filtering: Convolution operator

Image Credit: http://what-when-how.com/introduction-to-video-and-image-processing/neighborhood-processing-introduction-to-video-and-image-processing-part-1/

!(#, %) ' #, % = )

*

)

+

! ,, - .(# − ,, % − -)

slide-14
SLIDE 14

http://www.cs.virginia.edu/~vicente/recognition/animation.gif (filter, kernel)

slide-15
SLIDE 15

Image filtering: Convolution operator e.g. mean filter

Image Credit: http://what-when-how.com/introduction-to-video-and-image-processing/neighborhood-processing-introduction-to-video-and-image-processing-part-1/

!(#, %)

!(#, %) =

1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9

slide-16
SLIDE 16

Image filtering: Convolution operator e.g. mean filter

Image Credit: http://what-when-how.com/introduction-to-video-and-image-processing/neighborhood-processing-introduction-to-video-and-image-processing-part-1/

!(#, %)

!(#, %) =

1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9

slide-17
SLIDE 17

1 1 1 1 1 1 1 1 1

Slide credit: David Lowe (UBC)

] , [ g × ×

  • aka. box filter
slide-18
SLIDE 18

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90

Credit: S. Seitz

] , [ ] , [ ] , [

,

l n k m f l k g n m h

l k

+ + =å

[.,.] h [.,.] f

Image filtering

1 1 1 1 1 1 1 1 1

] , [ g × ×

slide-19
SLIDE 19

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 10 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90

[.,.] h [.,.] f

Image filtering

1 1 1 1 1 1 1 1 1

] , [ g × ×

Credit: S. Seitz

] , [ ] , [ ] , [

,

l n k m f l k g n m h

l k

+ + =å

slide-20
SLIDE 20

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 10 20 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90

[.,.] h [.,.] f

Image filtering

1 1 1 1 1 1 1 1 1

] , [ g × ×

Credit: S. Seitz

] , [ ] , [ ] , [

,

l n k m f l k g n m h

l k

+ + =å

slide-21
SLIDE 21

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 10 20 30 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90

[.,.] h [.,.] f

Image filtering

1 1 1 1 1 1 1 1 1

] , [ g × ×

Credit: S. Seitz

] , [ ] , [ ] , [

,

l n k m f l k g n m h

l k

+ + =å

slide-22
SLIDE 22

10 20 30 30 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90

[.,.] h [.,.] f

Image filtering

1 1 1 1 1 1 1 1 1

] , [ g × ×

Credit: S. Seitz

] , [ ] , [ ] , [

,

l n k m f l k g n m h

l k

+ + =å

slide-23
SLIDE 23

10 20 30 30 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90

[.,.] h [.,.] f

Image filtering

1 1 1 1 1 1 1 1 1

] , [ g × ×

Credit: S. Seitz

?

] , [ ] , [ ] , [

,

l n k m f l k g n m h

l k

+ + =å

slide-24
SLIDE 24

10 20 30 30 50 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90

[.,.] h [.,.] f

Image filtering

1 1 1 1 1 1 1 1 1

] , [ g × ×

Credit: S. Seitz

?

] , [ ] , [ ] , [

,

l n k m f l k g n m h

l k

+ + =å

slide-25
SLIDE 25

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 10 20 30 30 30 20 10 20 40 60 60 60 40 20 30 60 90 90 90 60 30 30 50 80 80 90 60 30 30 50 80 80 90 60 30 20 30 50 50 60 40 20 10 20 30 30 30 30 20 10 10 10 10

[.,.] h [.,.] f

Image filtering

1 1 1 1 1 1 1 1 1

] , [ g × ×

Credit: S. Seitz

] , [ ] , [ ] , [

,

l n k m f l k g n m h

l k

+ + =å

slide-26
SLIDE 26

What does it do?

  • Replaces each pixel with

an average of its neighborhood

  • Achieve smoothing effect

(remove sharp features)

1 1 1 1 1 1 1 1 1

Slide credit: David Lowe (UBC)

] , [ g × ×

Box Filter

slide-27
SLIDE 27

Image filtering: e.g. Mean Filter

slide-28
SLIDE 28

Image filtering: Convolution operator Important filter: gaussian filter (gaussian blur)

Image Credit: http://what-when-how.com/introduction-to-video-and-image-processing/neighborhood-processing-introduction-to-video-and-image-processing-part-1/

!(#, %)

!(#, %) =

1/16 1/8 1/16 1/8 1/4 1/8 1/16 1/8 1/16

slide-29
SLIDE 29
  • Weight contributions of neighboring pixels by nearness

0.003 0.013 0.022 0.013 0.003 0.013 0.059 0.097 0.059 0.013 0.022 0.097 0.159 0.097 0.022 0.013 0.059 0.097 0.059 0.013 0.003 0.013 0.022 0.013 0.003

5 x 5, s = 1

Slide credit: Christopher Rasmussen

Important filter: Gaussian

slide-30
SLIDE 30

Image filtering: Convolution operator e.g. gaussian filter (gaussian blur)

Image Credit: http://what-when-how.com/introduction-to-video-and-image-processing/neighborhood-processing-introduction-to-video-and-image-processing-part-1/

slide-31
SLIDE 31

Practical matters

  • 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

slide-32
SLIDE 32

Practice with linear filters

1 Original

?

Source: D. Lowe

slide-33
SLIDE 33

Practice with linear filters

1 Original Filtered (no change)

Source: D. Lowe

slide-34
SLIDE 34

Practice with linear filters

1 Original

?

Source: D. Lowe

slide-35
SLIDE 35

Practice with linear filters

1 Original Shifted left By 1 pixel

Source: D. Lowe

slide-36
SLIDE 36

Practice with linear filters

Original 1 1 1 1 1 1 1 1 1 2

  • ?

(Note that filter sums to 1)

Source: D. Lowe

slide-37
SLIDE 37

Practice with linear filters

Original 1 1 1 1 1 1 1 1 1 2

  • Sharpening filter
  • Accentuates differences

with local average

Source: D. Lowe

slide-38
SLIDE 38

Sharpening

Source: D. Lowe

slide-39
SLIDE 39

Key properties of linear filters

Linearity:

imfilter(I, f1 + f2) = imfilter(I,f1) + imfilter(I,f2)

Shift invariance: same behavior regardless of pixel location

imfilter(I,shift(f)) = shift(imfilter(I,f))

Any linear, shift-invariant operator can be represented as a convolution

Source: S. Lazebnik

slide-40
SLIDE 40

– Enhance images

  • Denoise, resize, increase contrast, etc.

– Extract information from images

  • Texture, edges, distinctive points, etc.

– Detect patterns

  • Template matching

– Deep Convolutional Networks

Image filtering: Convolution operator

slide-41
SLIDE 41

Image filtering: Convolution operator Important Filter: Sobel operator

Image Credit: http://what-when-how.com/introduction-to-video-and-image-processing/neighborhood-processing-introduction-to-video-and-image-processing-part-1/

!(#, %)

!(#, %) =

1

  • 1

2

  • 2

1

  • 1
slide-42
SLIDE 42

Other filters

  • 1

1

  • 2

2

  • 1

1 Vertical Edge (absolute value)

Sobel

Slide by James Hays

slide-43
SLIDE 43

Other filters

  • 1
  • 2
  • 1

1 2 1 Horizontal Edge (absolute value)

Sobel

Slide by James Hays

slide-44
SLIDE 44

Sobel operators are equivalent to 2D partial derivatives of the image

  • Vertical sobel operator – Partial derivative in X (width)
  • Horizontal sobel operator – Partial derivative in Y (height)
  • Can compute magnitude and phase at each location.
  • Useful for detecting edges
slide-45
SLIDE 45

https://en.wikipedia.org/wiki/Sobel_operator

slide-46
SLIDE 46

Sobel filters are (approximate) partial derivatives

  • f the image

!"($, &) !$ = lim

,→.

" $ + ℎ, & − "($, &) ℎ "($, &) be your input image, then the partial derivative is: Let !"($, &) !$ = lim

,→.

" $ + ℎ, & − "($ − ℎ, &) 2ℎ Also:

slide-47
SLIDE 47

But digital images are not continuous, they are discrete

Δ"#[%, '] = #[% + 1, '] − #[%, '] #[%, '] be your input image, then the partial derivative is: Let Δ"#[%, '] = #[% + 1, '] − #[% − 1, '] Also:

slide-48
SLIDE 48

But digital images are not continuous, they are discrete

Δ"#[%, '] = #[% + 1, '] − #[%, '] #[%, '] be your input image, then the partial derivative is: Let Δ"#[%, '] = #[% + 1, '] − #[% − 1, '] Also:

  • 1

1

  • 1

1

k(x, y) = k(x, y) =

slide-49
SLIDE 49

Sobel Operators Smooth in Y and then Differentiate in X

1

  • 1

k(x, y) =

1 2 1

* =

1

  • 1

2

  • 2

1

  • 1

Similarly to differentiate in Y

For a detailed analysis of why it is a good idea to smooth in other direction first, see Chapter 10 in the book on Digital Image Processing by Gonzalez & Woods http://web.ipac.caltech.edu/staff/fmasci/home/astro_refs/Digital_Image_Processing_2ndEd.pdf

slide-50
SLIDE 50

Variations

1

  • 1

1

  • 1

1

  • 1

Prewitt

  • 1
  • 1
  • 1

1 1 1

Roberts

  • 1

1

  • 1

1 1

  • 1

2

  • 2

1

  • 1

Frei-Chen

  • 1
  • 2
  • 1

1 2 1

slide-51
SLIDE 51

Frequency

Figure by National Instruments

slide-52
SLIDE 52

Any function can be approximated by a polynomial function

…if you let your polynomial have a high degree …AND you can compute the derivatives of the original function easily. Taylor Series expansion

slide-53
SLIDE 53
slide-54
SLIDE 54

Difficult in practice

https://brilliant.org/wiki/taylor-series-approximation/

slide-55
SLIDE 55

Jean Baptiste Joseph Fourier (1768-1830)

had crazy idea (1807):

Any univariate function can be rewritten as a weighted sum of sines and cosines of different frequencies.

  • Don’t believe it?

– Neither did Lagrange, Laplace, Poisson and

  • ther big wigs

– Not translated into English until 1878!

  • But it’s (mostly) true!

– called Fourier Series – there are some subtle restrictions

...the manner in which the author arrives at these equations is not exempt of difficulties and...his analysis to integrate them still leaves something to be desired on the score of generality and even rigour. Laplace Lagrange Legendre

Slide by James Hays

slide-56
SLIDE 56

Example

Slide by Emmanuel Agu

slide-57
SLIDE 57

Discrete Fourier Transform

! " = $

%&' ()*

+ , cos −22 ," 3 + 5 sin −22 ," 3

slide-58
SLIDE 58

Keep in mind Euler’s Equation

!"# = cos ( + * sin (

We can compute the real and the imaginary part of the complex number.

slide-59
SLIDE 59

Discrete Fourier Transform

! " = $

%&' ()*

+ , exp −223 ," 4 ! " = $

%&' ()*

+ , cos −22 ," 4 + 3 sin −22 ," 4

slide-60
SLIDE 60

Inverse Discrete Fourier Transform

! " = $

%&' ()*

+ , exp −223 ," 4 + , = 1 4 $

6&' ()*

! " exp 223 ," 4

Discrete Fourier Transform

slide-61
SLIDE 61

More generally for images (2D DFT and iDFT)

! ", $ = &

'() *+,

&

  • ()

.+,

/ 0, 1 exp −278 0" 9 + 1$ ; / 0, 1 = 1 9; &

=() *+,

&

>() .+,

! ", $ exp 278 0" 9 + 1$ ;

slide-62
SLIDE 62

Discrete Fourier Transform - Visualization

Slide by A. Zisserman

slide-63
SLIDE 63

Fourier Transform

  • Fourier transform stores the magnitude and phase at each frequency
  • Magnitude encodes how much signal there is at a particular frequency
  • Phase encodes spatial information (indirectly)
  • For mathematical convenience, this is often notated in terms of real and complex numbers

2 2

) ( ) ( w w I R A + ± = ) ( ) ( tan 1 w w f R I

  • =

Amplitude: Phase:

Slide by James Hays

slide-64
SLIDE 64

Image Filtering in the Frequency Domain

Slide by A. Zisserman

slide-65
SLIDE 65

Image Filtering in the Frequency Domain

Slide by A. Zisserman

slide-66
SLIDE 66

Image Filtering in the Frequency Domain

Slide by A. Zisserman

slide-67
SLIDE 67

The Convolution Theorem

  • The Fourier transform of the convolution of two

functions is the product of their Fourier transforms

  • Convolution in spatial domain is equivalent to

multiplication in frequency domain!

] F[ ] F[ ] F[ h g h g = *

]] F[ ] [F[ F *

1

h g h g

  • =

How can this be useful?

slide-68
SLIDE 68

Blurring in the Time vs Frequency Domain

Example by A. Zisserman

slide-69
SLIDE 69

Blurring in the Time vs Frequency Domain

Example by A. Zisserman

slide-70
SLIDE 70

Blurring in the Time vs Frequency Domain

Example by A. Zisserman

slide-71
SLIDE 71

Why Frequency domain?

  • Because the Discrete Fourier Transform can be computed fast using

the Fast Fourier Transform FFT algorithm.

  • Because the running time does not depend on the size of the kernel

matrix.

  • However rarely used these days because most filters used in

Computer vision are 3x3, 5x5, e.g. relatively small.

slide-72
SLIDE 72

Final Thoughts – JPEG Image Compression

  • Small amount of information can

recover almost the original image with some loss in resolution.

  • Images are dominated by low

frequency information. e.g. no need to store repeated pixels.

  • In practice JPEG uses a simpler

transformation called Discrete Cosine Transform DCT.

slide-73
SLIDE 73

Questions?

slide-74
SLIDE 74

Questions?

74