Filtering, Frequency, and Edges Various slides from previous courses - - PowerPoint PPT Presentation

filtering frequency and edges
SMART_READER_LITE
LIVE PREVIEW

Filtering, Frequency, and Edges Various slides from previous courses - - PowerPoint PPT Presentation

CS4501: Introduction to Computer Vision Filtering, Frequency, and Edges 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


slide-1
SLIDE 1

CS4501: Introduction to Computer Vision

Filtering, Frequency, and Edges

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
  • Convolution Operation
  • Image Blurring / Gaussian Blur
  • Image Gradients: The Sobel Operator

Last Class

slide-3
SLIDE 3
  • Recap on Sobel Operator
  • Filtering in Frequency
  • Canny Edge Detector (also next class)

Today’s Class

slide-4
SLIDE 4

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-5
SLIDE 5

Other filters

  • 1

1

  • 2

2

  • 1

1 Vertical Edge (absolute value)

Sobel

Slide by James Hays

slide-6
SLIDE 6

Other filters

  • 1
  • 2
  • 1

1 2 1 Horizontal Edge (absolute value)

Sobel

Slide by James Hays

slide-7
SLIDE 7

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-8
SLIDE 8

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

slide-9
SLIDE 9

Sobel filters are (approximate) partial derivatives

  • f the image

!"($, &) !$ = lim

,→.

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

,→.

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

slide-10
SLIDE 10

But digital images are not continuous, they are discrete

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

slide-11
SLIDE 11

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-12
SLIDE 12

Frequency

Figure by National Instruments

slide-13
SLIDE 13

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-14
SLIDE 14
slide-15
SLIDE 15

Difficult in practice

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

slide-16
SLIDE 16

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-17
SLIDE 17

Example

Slide by Emmanuel Agu

slide-18
SLIDE 18

Discrete Fourier Transform

! " = $

%&' ()*

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

slide-19
SLIDE 19

Keep in mind Euler’s Equation

!"# = cos ( + * sin (

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

slide-20
SLIDE 20

Discrete Fourier Transform

! " = $

%&' ()*

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

%&' ()*

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

slide-21
SLIDE 21

Inverse Discrete Fourier Transform

! " = $

%&' ()*

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

6&' ()*

! " exp 223 ," 4

Discrete Fourier Transform

slide-22
SLIDE 22

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-23
SLIDE 23

Discrete Fourier Transform - Visualization

Slide by A. Zisserman

slide-24
SLIDE 24

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-25
SLIDE 25

Image Filtering in the Frequency Domain

Slide by A. Zisserman

slide-26
SLIDE 26

Image Filtering in the Frequency Domain

Slide by A. Zisserman

slide-27
SLIDE 27

Image Filtering in the Frequency Domain

Slide by A. Zisserman

slide-28
SLIDE 28

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-29
SLIDE 29

Blurring in the Time vs Frequency Domain

Example by A. Zisserman

slide-30
SLIDE 30

Blurring in the Time vs Frequency Domain

Example by A. Zisserman

slide-31
SLIDE 31

Blurring in the Time vs Frequency Domain

Example by A. Zisserman

slide-32
SLIDE 32

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-33
SLIDE 33

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-34
SLIDE 34

Questions?

34

slide-35
SLIDE 35

Edge Detection

slide-36
SLIDE 36

Edge Detection

  • Goal: Identify sudden changes

(discontinuities) in an image

  • Intuitively, most semantic and

shape information from the image can be encoded in the edges

  • More compact than pixels
  • Ideal: artist’s line drawing (but

artist is also using object-level knowledge)

Source: D. Lowe

slide-37
SLIDE 37

Why do we care about edges?

  • Extract information, recognize objects
  • Recover geometry and viewpoint

Vanishing point Vanishing line Vanishing point Vertical vanishing point (at infinity)

Source: J. Hays

slide-38
SLIDE 38

Origin of Edges

  • Edges are caused by a variety of factors

depth discontinuity surface color discontinuity illumination discontinuity surface normal discontinuity

Source: Steve Seitz

slide-39
SLIDE 39

Edge Detection

  • Back to Sobel

But Ideally we want an output where: g(x,y) = 1 if edge g(x,y) = 0 if background

slide-40
SLIDE 40

Edge Detection

  • Sobel + Thresholding

! ", $ = &1, ((", $) ≥ , 0, ( ", $ < ,

slide-41
SLIDE 41
  • Sobel + Thresholding

! ", $ = &1, ((", $) ≥ , 0, ( ", $ < ,

Problems:

  • Edges are too wide: We want 1-pixel wide edges if possible.
  • Lots of disconnected edges: We want to respect continuity or connectivity.
slide-42
SLIDE 42

Solution: Canny edge detector

  • Suppress Noise
  • Compute gradient magnitude and direction
  • Non-Maximum Suppression
  • Hysteresis and connectivity analysis

Similar to Sobel: Blurring + Gradients

slide-43
SLIDE 43

Example

  • original image

Source: Juan C. Niebles and Ranjay Krishna.

slide-44
SLIDE 44

Derivative of Gaussian filter

x-direction y-direction

Source: Juan C. Niebles and Ranjay Krishna.

slide-45
SLIDE 45

Compute gradients (DoG)

X-Derivative of Gaussian Y-Derivative of Gaussian Gradient Magnitude

Source: J. Hays

slide-46
SLIDE 46

Get orientation at each pixel

Source: J. Hays

slide-47
SLIDE 47

Compute gradients (DoG)

X-Derivative of Gaussian Y-Derivative of Gaussian Gradient Magnitude

Source: Juan C. Niebles and Ranjay Krishna.

slide-48
SLIDE 48

Canny edge detector

  • Suppress Noise
  • Compute gradient magnitude and direction
  • Apply Non-Maximum Suppression
  • Assures minimal response

Source: Juan C. Niebles and Ranjay Krishna.

slide-49
SLIDE 49

Non-maximum suppression

  • Edge occurs where gradient reaches a maxima
  • Suppress non-maxima gradient even if it passes threshold
  • Only eight angle directions possible
  • Suppress all pixels in each direction which are not maxima
  • Do this in each marked pixel neighborhood

Source: Juan C. Niebles and Ranjay Krishna.

slide-50
SLIDE 50

Remove spurious gradients

is the gradient at pixel (x, y)

!" #, %

!" #, % !" #, % > !" #′, %′ !" #, % > !" #′′, %′′

Source: Juan C. Niebles and Ranjay Krishna.

slide-51
SLIDE 51

Non-maximum suppression

  • Edge occurs where gradient reaches a maxima
  • Suppress non-maxima gradient even if it passes threshold
  • Only eight angle directions possible
  • Suppress all pixels in each direction which are not maxima
  • Do this in each marked pixel neighborhood

Source: Juan C. Niebles and Ranjay Krishna.

slide-52
SLIDE 52

Non-maximum suppression

At q, we have a maximum if the value is larger than those at both p and at r. Interpolate to get these values.

Source: D. Forsyth

slide-53
SLIDE 53

Non-max Suppression Before After

Source: Juan C. Niebles and Ranjay Krishna.

slide-54
SLIDE 54

Canny edge detector

  • Suppress Noise
  • Compute gradient magnitude and direction
  • Apply Non-Maximum Suppression
  • Assures minimal response
  • Use hysteresis and connectivity analysis to detect edges

Source: Juan C. Niebles and Ranjay Krishna.

slide-55
SLIDE 55

Source: Juan C. Niebles and Ranjay Krishna.

slide-56
SLIDE 56

Hysteresis thresholding

  • Avoid streaking near threshold value
  • Define two thresholds: Low and High
  • If less than Low, not an edge
  • If greater than High, strong edge
  • If between Low and High, weak edge

Source: Juan C. Niebles and Ranjay Krishna.

slide-57
SLIDE 57

Hysteresis thresholding

If the gradient at a pixel is

  • above High, declare it as an ‘strong edge pixel’
  • below Low, declare it as a “non-edge-pixel”
  • between Low and High
  • Consider its neighbors iteratively then declare it an “edge pixel” if it is

connected to an ‘strong edge pixel’ directly or via pixels between Low and High

Source: Juan C. Niebles and Ranjay Krishna.

slide-58
SLIDE 58

Hysteresis thresholding

Source: S. Seitz

strong edge pixel weak but connected edge pixels strong edge pixel

slide-59
SLIDE 59

Final Canny Edges

Source: Juan C. Niebles and Ranjay Krishna.

slide-60
SLIDE 60

Canny edge detector

  • 1. Filter image with x, y derivatives of Gaussian
  • 2. Find magnitude and orientation of gradient
  • 3. Non-maximum suppression:
  • Thin multi-pixel wide ridges down to single pixel width
  • 4. Thresholding and linking (hysteresis):
  • Define two thresholds: low and high
  • Use the high threshold to start edge curves and the low threshold to

continue them

Source: Juan C. Niebles and Ranjay Krishna.

slide-61
SLIDE 61

Canny Edge Detector

  • Classic algorithm in Computer Vision / Image Analysis
  • Commonly implemented in most libraries
  • e.g. in Python you can find it in the skimage package.

OpenCV also has an implementation with python bindings.

slide-62
SLIDE 62

Corners (and Interest Points)

  • How to find corners? What is a corner?