Lecture 3: Linear Filters

Similar documents
Lecture 3: Linear Filters

Computer Vision Lecture 3

I Chen Lin, Assistant Professor Dept. of CS, National Chiao Tung University. Computer Vision: 4. Filtering

Templates, Image Pyramids, and Filter Banks

CITS 4402 Computer Vision

Computer Vision Lecture 3

Lecture 04 Image Filtering

Edge Detection. Introduction to Computer Vision. Useful Mathematics Funcs. The bad news

CEE598 - Visual Sensing for Civil Infrastructure Eng. & Mgmt.

Image Filtering. Slides, adapted from. Steve Seitz and Rick Szeliski, U.Washington

6.869 Advances in Computer Vision. Bill Freeman, Antonio Torralba and Phillip Isola MIT Oct. 3, 2018

Lecture 6: Edge Detection. CAP 5415: Computer Vision Fall 2008

Thinking in Frequency

CSE 473/573 Computer Vision and Image Processing (CVIP)

Introduction to Computer Vision. 2D Linear Systems

Introduction to Linear Systems

Lecture'4:' Pixels'and'Filters Lecture 3: Pixels and Filters

Module 3. Convolution. Aim

Introduction to Computer Vision

Taking derivative by convolution

ECE Digital Image Processing and Introduction to Computer Vision

Linear Operators and Fourier Transform

Subsampling and image pyramids

Announcements. Filtering. Image Filtering. Linear Filters. Example: Smoothing by Averaging. Homework 2 is due Apr 26, 11:59 PM Reading:

Signal Processing COS 323

Filtering and Edge Detection

! Circular Convolution. " Linear convolution with circular convolution. ! Discrete Fourier Transform. " Linear convolution through circular

Edge Detection PSY 5018H: Math Models Hum Behavior, Prof. Paul Schrater, Spring 2005

Signal Processing and Linear Systems1 Lecture 4: Characterizing Systems

Reading. 3. Image processing. Pixel movement. Image processing Y R I G Q

Additional Pointers. Introduction to Computer Vision. Convolution. Area operations: Linear filtering

Outline. Convolution. Filtering

Frequency Filtering CSC 767

Why does a lower resolution image still make sense to us? What do we lose? Image:

Edge Detection. Computer Vision P. Schrater Spring 2003

Multidimensional digital signal processing

ECG782: Multidimensional Digital Signal Processing

Multiscale Image Transforms

CS 179: GPU Programming. Lecture 9 / Homework 3

Edges and Scale. Image Features. Detecting edges. Origin of Edges. Solution: smooth first. Effects of noise

Empirical Mean and Variance!

Computational Photography

Lecture 8: Interest Point Detection. Saad J Bedros

Basic Multi-rate Operations: Decimation and Interpolation

Basics on 2-D 2 D Random Signal

Assignment 2 Solutions

Sampling in 1D ( ) Continuous time signal f(t) Discrete time signal. f(t) comb

Advanced Features. Advanced Features: Topics. Jana Kosecka. Slides from: S. Thurn, D. Lowe, Forsyth and Ponce. Advanced features and feature matching

CS 179: GPU Programming. Lecture 9 / Homework 3

Introduction to Linear Image Processing

Images have structure at various scales

Image Enhancement in the frequency domain. GZ Chapter 4

Digital Image Processing

Chapter 8 The Discrete Fourier Transform

Discrete-Time Systems

Convolution. Define a mathematical operation on discrete-time signals called convolution, represented by *. Given two discrete-time signals x 1, x 2,

Feature extraction: Corners and blobs

Computer Vision & Digital Image Processing

6.003: Signals and Systems. Sampling and Quantization

Two-Dimensional Signal Processing and Image De-noising

LTI H. the system H when xn [ ] is the input.

Fourier Transforms 1D

3. Lecture. Fourier Transformation Sampling

ECG782: Multidimensional Digital Signal Processing

Digital Signal Processing Lecture 10 - Discrete Fourier Transform

Blobs & Scale Invariance

CEE598 - Visual Sensing for Civil Infrastructure Eng. & Mgmt.

Colorado School of Mines Image and Multidimensional Signal Processing

ENT 315 Medical Signal Processing CHAPTER 2 DISCRETE FOURIER TRANSFORM. Dr. Lim Chee Chin

Multiresolution Analysis

Fourier Analysis and Imaging Ronald Bracewell L.M. Terman Professor of Electrical Engineering Emeritus Stanford University Stanford, California

Neural Networks 2. 2 Receptive fields and dealing with image inputs

ECE 425. Image Science and Engineering

Filtering, Frequency, and Edges

Today s lecture. Local neighbourhood processing. The convolution. Removing uncorrelated noise from an image The Fourier transform

Blob Detection CSC 767

! Introduction. ! Discrete Time Signals & Systems. ! Z-Transform. ! Inverse Z-Transform. ! Sampling of Continuous Time Signals

Spatial-Domain Convolution Filters

IT DIGITAL SIGNAL PROCESSING (2013 regulation) UNIT-1 SIGNALS AND SYSTEMS PART-A

Computer Vision. Filtering in the Frequency Domain

EE 225D LECTURE ON DIGITAL FILTERS. University of California Berkeley

Corners, Blobs & Descriptors. With slides from S. Lazebnik & S. Seitz, D. Lowe, A. Efros

Lecture Notes 5: Multiresolution Analysis

Theory and Problems of Signals and Systems

Introduction to Sparsity in Signal Processing

The Frequency Domain, without tears. Many slides borrowed from Steve Seitz

Introduction to Sparsity in Signal Processing

CS 179: LECTURE 16 MODEL COMPLEXITY, REGULARIZATION, AND CONVOLUTIONAL NETS

Digital Image Processing COSC 6380/4393

Machine vision. Summary # 4. The mask for Laplacian is given

EENG580 Game 2: Verbal Representation of Course Content

Sound & Vibration Magazine March, Fundamentals of the Discrete Fourier Transform

Achieving scale covariance

Review Smoothing Spatial Filters Sharpening Spatial Filters. Spatial Filtering. Dr. Praveen Sankaran. Department of ECE NIT Calicut.

Lecture 20: Discrete Fourier Transform and FFT

Detectors part II Descriptors

Vlad Estivill-Castro (2016) Robots for People --- A project for intelligent integrated systems

V(t) = Total Power = Calculating the Power Spectral Density (PSD) in IDL. Thomas Ferree, Ph.D. August 23, 1999

Machine vision, spring 2018 Summary 4

Transcription:

Lecture 3: Linear Filters Professor Fei Fei Li Stanford Vision Lab 1

What we will learn today? Images as functions Linear systems (filters) Convolution and correlation Discrete Fourier Transform (DFT) Sampling and aliasing Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7 & 8 Jae S. Lim, Two dimensional signal and image processing, Chapter 1, 4, 5 2

Images as functions An Image as a function f from R 2 to R M : f( x, y ) gives the intensity at position ( x, y ) Defined over a rectangle, with a finite range: f: [a,b] x [c,d ] [0,255] Domain support range f(x,y) y f(x,y) y x x 3

Images as functions An Image as a function f from R 2 to R M : f( x, y ) gives the intensity at position ( x, y ) Defined over a rectangle, with a finite range: f: [a,b] x [c,d ] [0,255] Domain support range A color image: rxy (, ) f( x, y) g( x, y) bxy (, ) 4

Images as discrete functions Images are usually digital (discrete): Sample the 2D space on a regular grid Represented as a matrix of integer values pixel 5

Images as discrete functions Cartesian coordinates Notation for discrete functions 6

Images as discrete functions Array coordinates Matlab notation 7

What we will learn today? Images as functions Linear systems (filters) Convolution and correlation Discrete Fourier Transform (DFT) Sampling and aliasing Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7 & 8 Jae S. Lim, Two dimensional signal and image processing, Chapter 1, 4, 5 8

Filtering: Systems and Filters 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 9

De noising Super resolution Salt and pepper noise In painting Bertamio et al 10

2D discrete space systems (filters) 11

Filters: Examples 2D DS moving average over a 3 3 window of neighborhood 12 1 1 1 1 1 1 1 1 1 ], [ ], [ 9 1 ], )[ (, l n k m h l k f n m h f l k h

This image cannot currently be displayed. Moving average 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 0 90 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 90 90 90 90 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Courtesy of S. Seitz 13

Moving average 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 0 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 (f g)[m,n] k,l f[k, l] g[m k,n 14 l] 14

Moving average 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 20 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 0 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 (f g)[m,n] k,l f[k, l] g[m k,n l] 15

Moving average 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 20 30 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 0 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 (f g)[m,n] k,l f[k, l] g[m k,n l] 16

Moving average 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 20 30 30 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 0 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 (f g)[m,n] k,l f[k, l] g[m k,n l] 17

Moving average 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 20 10 0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20 0 0 0 90 90 90 90 90 0 0 0 30 60 90 90 90 60 30 0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30 0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30 0 0 0 90 90 90 90 90 0 0 0 20 30 50 50 60 40 20 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 30 20 10 0 0 90 0 0 0 0 0 0 0 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 (f g)[m,n] k,l f[k, l] g[m k,n l] Source: S. Seitz 18

Moving average In summary: g[, ] Replaces each pixel with an average of its neighborhood. 1 1 1 1 1 1 1 1 1 Achieve smoothing effect (remove sharp features) 19

Moving average 20

Filters: Examples Image segmentation based on a simple threshold: 21

Classification of systems Amplitude properties Linearity Stability Invertibility Spatial properties Causality Separability Memory Shift invariance Rotation invariance 22

Shift invariance If then for every input image f[n,m] and shifts n 0,m 0 Is the moving average shift invariant a system? 23

Is the moving average system is shift invariant? 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 20 10 0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20 0 0 0 90 90 90 90 90 0 0 0 30 60 90 90 90 60 30 0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30 0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30 0 0 0 90 90 90 90 90 0 0 0 20 30 50 50 60 40 20 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 30 20 10 0 0 90 0 0 0 0 0 0 0 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 24

Is the moving average system is shift invariant? Yes! 25

Linear Systems (filters) Linear filtering: Form a new image whose pixels are a weighted sum of original pixel values Use the same set of weights at each point S is a linear system (function) iff it S satisfies superposition property 26

Linear Systems (filters) Is the moving average a linear system? Is thresholding a linear system? f1[n,m] + f2[n,m] > T f1[n,m] < T f2[n,m]<t No! 27

LSI (linear shift invariant) systems Impulse response 28

LSI (linear shift invariant) systems Example: impulse response of the 3 by 3 moving average filter: h 1 1 1 1 1 1 1 1 1 29

LSI (linear shift invariant) systems An LSI system is completely specified by its impulse response. sifting property of the delta function superposition Discrete convolution 30

What we will learn today? Images as functions Linear systems (filters) Convolution and correlation Discrete Fourier Transform (DFT) Sampling and aliasing Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7 & 8 Jae S. Lim, Two dimensional signal and image processing, Chapter 1, 4, 5 31

Discrete convolution Fold h[n,m] about origin to form h[ k, l] Shift the folded results by n,m to form h[n k,m l] Mul ply h[n k,m l] by f[k, l] Sum over all k,l Repeat for every n,m h[k,l] h[ k, l] h[n k,m l] n 32

Discrete convolution Fold h[n,m] about origin to form h[ k, l] Shift the folded results by n,m to form h[n k,m l] Mul ply h[n k,m l] by f[k, l] Sum over all k,l Repeat for every n,m h[k,l] h[ k, l] h[n k,m l] n 33

Discrete convolution Fold h[n,m] about origin to form h[ k, l] Shift the folded results by n,m to form h[n k,m l] Mul ply h[n k,m l] by f[k, l] Sum over all k,l Repeat for every n,m h[n k,m l] f[k,l] x h[n k,m l] f[k,l] Sum (f[k,l] x h[n k,m l]) n 34

Convolution in 2D examples =? Original Courtesy of D Lowe 35

Convolution in 2D examples = Original Filtered (no change) Courtesy of D Lowe 36

Convolution in 2D examples =? Original Courtesy of D Lowe 37

Convolution in 2D examples = Original Shifted right By 1 pixel Courtesy of D Lowe 38

Convolution in 2D examples =? Original Courtesy of D Lowe 39

Convolution in 2D examples = Original Blur (with a box filter) Courtesy of D Lowe 40

Convolution in 2D examples 2 - =? (Note that filter sums to 1) Original details of the image + - Courtesy of D Lowe 41

What does blurring take away? = original smoothed (5x5) detail Let s add it back: + a = original detail sharpened 42

Convolution in 2D Sharpening filter 2 - = Original Sharpening filter: Accentuates differences with local average Courtesy of D Lowe 43

Convolution properties Commutative property: Associative property: Distributive property: The order doesn t matter! 44

Convolution properties Shift property: Shift invariance: 45

Image support and edge effect A computer will only convolve finite support signals. That is: images that are zero for n,m outside some rectangular region MATLAB s conv2 performs 2D DS convolution of finitesupport signals. * = N2 M2 (N1 + N2 1) (M1 +M2 1) N1 M1 46

Image support and edge effect A computer will only convolve finite support signals. What happens at the edge? f h zero padding edge value replication mirror extension more (beyond the scope of this class) > Matlab conv2 uses zero padding 47

Cross correlation Cross correlation of two 2D signals f[n,m] and g[n,m] Equivalent to a convolution without the flip (k, l) is called the lag 48

Cross correlation example MATLAB s xcorr2 Courtesy of J. Fessler 49

Cross correlation example Left Right scanline Norm. corr 50

Convolution vs. Correlation A convolution is an integral that expresses the amount of overlap of one function as it is shifted over another function. convolution is a filtering operation Correlation compares the similarity of two sets of data. Correlation computes a measure of similarity of two input signals as they are shifted by one another. The correlation result reaches a maximum at the time when the two signals match best. correlation is a measure of relatedness of two signals 51 2010.12.18

What we will learn today? Images as functions Linear systems (filters) Convolution and correlation Discrete Fourier Transform (DFT) Sampling and aliasing Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7 & 8 Jae S. Lim, Two dimensional signal and image processing, Chapter 1, 4, 5 52

2D Discrete Signal Fourier Transform (DSFT) 2D discrete signal Fourier transform (DSFT) of a 2D discrete space signal g[n,m]: Inverse 2D DSFT: For memory refresher: Forsyth and Ponce, Ch 8 53

54

DSFT properties Shift: Convolution: Delta function: 55

Example: DSFT of moving average filter 56 ], [ ], [ 9 1 ], )[ (, l n k m h l k f n m h f l k 1 1 1 1 1 1 1 1 1 h

Why is DFT important? Perform efficient linear convolution as product of DFTs Each DFT can be implemented using the FFT (Fast Fourier Transform ) [see appendix for details] 58

What we will learn today? Images as functions Linear systems (filters) Convolution and correlation Discrete Fourier Transform (DFT) Sampling and aliasing Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7 & 8 Jae S. Lim, Two dimensional signal and image processing, Chapter 1, 4, 5 59

Sampling Throw away every other row and column to create a 1/2 size image 60

Sampling Down sampling operation: (trivial form of image compression) 61

Why is a multi scale representation useful? Find template matches at all scales e.g., when finding hands or faces, we don t know what size they will be in a particular image Template size is constant, but image size changes Efficient search for correspondence look at coarse scales, then refine with finer scales Examining all levels of detail Find edges with different amounts of blur Find textures with different spatial frequencies (levels of detail) Slide credit: David Lowe (UBC) 62

Things can go wrong! Aliasing 63

Things can go wrong! Aliasing 64

65

Sampling Theorem (Nyquist) When sampling a signal at discrete intervals, the sampling frequency must be 2 f max f max = max frequency of the input signal. v v v good bad 66

g[n,m] Small sampling period N g sampled [n,m] y N = sampling period T = periodicity of the replicas of the DFT (g) T T 1/N x 67

g[n,m] Large sampling period N g sampled [n,m] y N = sampling period T = periodicity of the replicas of the DFT (g) T 1/N x 68

Anti aliasing Solutions: Sample more often Get rid of all frequencies that are greater than half the new sampling frequency Will lose information but it s better than aliasing Apply a smoothing filter to remove high frequencies 69

Anti aliasing Apply a smoothing filter to remove high frequencies: G( ) x Low pass filter (smoothing) 70

Sampling algorithm 71

Resampling with Prior Smoothing Note: We cannot recover the high frequencies, but we can avoid artifacts by smoothing before resampling. Image Source: Forsyth & Ponce

The Gaussian Pyramid Low resolution G 4 ( G 3 * gaussian) 2 G 3 ( G 2 * gaussian blur ) 2 blur G 2 ( G 1 * gaussian) 2 blur G 1 ( G 0 * gaussian) 2 G 0 Image blur High resolution 73

Gaussian Pyramid Stored Information All the extra levels add very little overhead for memory or computation! Source: Irani & Basri 74

Summary: Gaussian Pyramid Construction: create each level from previous one Smooth and sample Smooth with Gaussians, in part because a Gaussian*Gaussian = another Gaussian G( 1 ) * G( 2 ) = G(sqrt( 1 2 + 2 2 )) Gaussians are low pass filters, so the representation is redundant once smoothing has been performed. There is no need to store smoothed images at the full original resolution. Slide credit: David Lowe 75

Application: Vision system for TV remote control - uses template matching Figure from Computer Vision for Interactive Computer Graphics, W.Freeman et al, IEEE Computer Graphics and Applications, 1998 copyright 1998, IEEE 76

What we have learned today? Images as functions Linear systems (filters) Convolution and correlation Discrete Fourier Transform (DFT) Sampling and aliasing 77

Appendix 78

Convergence If g absolutely summable: then If g is square summable (energy signal): 79

80

Fast Fourier transforms (FFT) Brute force evaluation of the 2D DFT would require O((NM)2) flops DFT is a separable operation we can reduce greatly the computation 81

Fast Fourier transforms (FFT) DFT is a separable operation: Apply the 1D DFT to each column of the image, and then apply the 1D DFT to each row of the result. Use the fast Fourier transform (1 D FFT) for these 1D DFTs! 82

Fast Fourier transforms (FFT) FFT computational efficiency: inner set of 1D FFTs : N O(M logm) outer set of 1D FFTs: M O(N logn) Total: O(MN logmn) flops A critical property of FFT is that N = 2 k with k =integer If x = 512x512 image saving is a factor of 15000 relative to the brute force 2D DFT! Matlab: fft2 = fft(fft(x). ). 83

FFT & Efficiency General goal: perform efficient linear convolution Perform convolution as product of DFTs Pros: DFT can be implemented using the FFT (fast fourier transform) FFT is very efficient (fast!) Cons: DFT perform circular convolution Compensate the wrap around effect Cons: Online memory storage Use the overlap add method or overlap save method 84

FFT & Efficiency Suppose we wish to convolve a 256 256 image with a 17 17 filter. The result will be 272 272. The smallest prime factors of 272 is 2. So one could pad to a 512 512 image Note: only 28% of the final image would be the part we care about the rest would be zero in exact arithmetic. Handling to a 512 512 image requires much memory Use overlap add method 85