Lecture 14: Convolution and Frequency Domain Filtering

Similar documents
Lecture 13: Implementation and Applications of 2D Transforms

SIMG-782 Digital Image Processing Homework 6

Lecture 16: Multiresolution Image Analysis

Fourier Transform 2D

&& && F( u)! "{ f (x)} = f (x)e # j 2$ u x. f (x)! " #1. F(u,v) = f (x, y) e. f (x, y) = 2D Fourier Transform. Fourier Transform - review.

F(u) = f e(t)cos2πutdt + = f e(t)cos2πutdt i f o(t)sin2πutdt = F e(u) + if o(u).

Fourier series: Any periodic signals can be viewed as weighted sum. different frequencies. view frequency as an

3. Lecture. Fourier Transformation Sampling

DFT-Based FIR Filtering. See Porat s Book: 4.7, 5.6

Fourier analysis of discrete-time signals. (Lathi Chapt. 10 and these slides)

Empirical Mean and Variance!

Lecture 7 January 26, 2016

Image Enhancement in the frequency domain. GZ Chapter 4

BME I5000: Biomedical Imaging

Module 3. Convolution. Aim

Lecture 3: Linear Filters

EXAMINATION QUESTION PAPER

Lecture 3: Linear Filters

MIT 2.71/2.710 Optics 10/31/05 wk9-a-1. The spatial frequency domain

CS 179: GPU Programming. Lecture 9 / Homework 3

Lecture 4 Filtering in the Frequency Domain. Lin ZHANG, PhD School of Software Engineering Tongji University Spring 2016

CS 179: GPU Programming. Lecture 9 / Homework 3

Linear Convolution Using FFT

EEO 401 Digital Signal Processing Prof. Mark Fowler

Lecture 11 FIR Filters

EE-210. Signals and Systems Homework 7 Solutions

ECG782: Multidimensional Digital Signal Processing

Lecture 10, Multirate Signal Processing Transforms as Filter Banks. Equivalent Analysis Filters of a DFT

Fall 2011, EE123 Digital Signal Processing

Introduction to Fourier Analysis Part 2. CS 510 Lecture #7 January 31, 2018

Multidimensional digital signal processing

Computer Vision & Digital Image Processing. Periodicity of the Fourier transform

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

Topics. Example. Modulation. [ ] = G(k x. ] = 1 2 G ( k % k x 0) G ( k + k x 0) ] = 1 2 j G ( k x

! Review: Discrete Fourier Transform (DFT) ! DFT Properties. " Duality. " Circular Shift. ! Circular Convolution. ! Fast Convolution Methods

Biophysics 230: Nuclear Magnetic Resonance Haacke Chapter 11

8 The Discrete Fourier Transform (DFT)

Therefore the new Fourier coefficients are. Module 2 : Signals in Frequency Domain Problem Set 2. Problem 1

Introduction to Sparsity in Signal Processing

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

FOURIER TRANSFORM METHODS David Sandwell, January, 2013

6 The Fourier transform

CSE548, AMS542: Analysis of Algorithms, Fall 2015 Date: October 12. In-Class Midterm. ( 1:05 PM 2:20 PM : 75 Minutes )

Lecture 20: Discrete Fourier Transform and FFT

Computer Vision. Filtering in the Frequency Domain

The spatial frequency domain

Digital Image Processing

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

Image Processing 1 (IP1) Bildverarbeitung 1

Key Intuition: invertibility

The Fourier transform allows an arbitrary function to be represented in terms of simple sinusoids. The Fourier transform (FT) of a function f(t) is

GBS765 Electron microscopy

Digital Signal Processing. Midterm 2 Solutions

Image as a signal. Luc Brun. January 25, 2018

ESS Finite Impulse Response Filters and the Z-transform

ANALOG AND DIGITAL SIGNAL PROCESSING ADSP - Chapter 8

Introduction to Sparsity in Signal Processing

18.085: Summer 2016 Due: 3 August 2016 (in class) Problem Set 8

Description Syntax Remarks and examples Conformability Diagnostics Also see

DSP Algorithm Original PowerPoint slides prepared by S. K. Mitra

VII. Discrete Fourier Transform (DFT) Chapter-8. A. Modulo Arithmetic. (n) N is n modulo N, n is an integer variable.

INTRODUCTION TO THE DFS AND THE DFT

Definition. A signal is a sequence of numbers. sequence is also referred to as being in l 1 (Z), or just in l 1. A sequence {x(n)} satisfying

Two-Dimensional Signal Processing and Image De-noising

Convolution Spatial Aliasing Frequency domain filtering fundamentals Applications Image smoothing Image sharpening

Topics. Bioengineering 280A Principles of Biomedical Imaging. Fall Quarter 2006 CT/Fourier Lecture 2

Biomedical Engineering Image Formation II

SEISMIC WAVE PROPAGATION. Lecture 2: Fourier Analysis

Computational Methods for Astrophysics: Fourier Transforms

DISCRETE FOURIER TRANSFORM

The Fastest Convolution in the West

Introduction to Linear Systems

(Refer Slide Time: 1:09)

Central to this is two linear transformations: the Fourier Transform and the Laplace Transform. Both will be considered in later lectures.

Digital Signal Processing Lecture 4

Solutions For Homework #5

Lecture? Using the FFT for Computation

Fourier transform. Stefano Ferrari. Università degli Studi di Milano Methods for Image Processing. academic year

Defining the Integral

Contents. Signals as functions (1D, 2D)

Solution Set #1

ECS455: Chapter 5 OFDM. ECS455: Chapter 5 OFDM. OFDM: Overview. OFDM Applications. Dr.Prapun Suksompong prapun.com/ecs455

Discrete Fourier Transform

Centre for Mathematical Sciences HT 2017 Mathematical Statistics

Ex. Here's another one. We want to prove that the sum of the cubes of the first n natural numbers is. n = n 2 (n+1) 2 /4.

3. Coding theory 3.1. Basic concepts

Contents. Signals as functions (1D, 2D)

CITS 4402 Computer Vision

Mathematics 13: Lecture 10

T h e C S E T I P r o j e c t

Fundamentals of the DFT (fft) Algorithms

A. Relationship of DSP to other Fields.

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

Lecture 4 - Spectral Estimation

2 M. Hasegawa-Johnson. DRAFT COPY.

UNIT 4: DIGITAL SYSTEM MODELS

Spatial-Domain Convolution Filters

We know that f(x, y) and F (u, v) form a Fourier Transform pair, i.e. f(ax, by)e j2π(ux+vy) dx dy. x x. a 0 J = y y. = 0 b

IMAGE ENHANCEMENT: FILTERING IN THE FREQUENCY DOMAIN. Francesca Pizzorni Ferrarese

Fundamentals of the Discrete Fourier Transform

Transcription:

Lecture 4: Convolution and Frequency Domain Filtering Harvey Rhody Chester F. Carlson Center for Imaging Science Rochester Institute of Technology rhody@cis.rit.edu October 7, 005 Abstract The impulse response of a filter describes its spatial processing behavior. This is closely tied to the global processing characteristics that are obtained using Fourier transforms. Here we focus on the relationship between the spatial and frequency domains and provide examples of alternative implementations of filters with various desirable characteristics. DIP Lecture 4

Filtering by Convolution We will first examine the relationship of convolution and filtering by frequency-domain multiplication with D sequences. Let f(n), 0 n L be a data record. Let h(n), 0 n K be the impulse response of a discrete filter. If the sequence f(n) is passed through the discrete filter then the output is g(m) = k k=k h(k)f(m k), < m < where k and k are appropriate limits on the index. DIP Lecture 4

Index Values The values of k and k depend upon m. Getting this dependence right is the detail that causes the most trouble in the implementation of convolution. Condition Restriction h(k) = 0 for k < 0 k 0 f(m k) = 0 for m k L k m L + h(k) = 0 for k K k K f(m k)=0 for m k < 0 k m These restrictions can be combined with the requirement that k k to yield m k k 0 m 0 () K k k m L + m K + L () Hence, g(m) = 0 outside the interval 0 m K + L. DIP Lecture 4

Convolution Sum g(m) = k (m) k=k (m) = 0, elsewhere h(k)f(m k), 0 m K + L where the limits are described by the following tables. Case K < L Range of m k k 0 m K 0 m K m L 0 K L m K + L m L + K Case K L Range of m k k 0 m L 0 m L m K m L + m K m K + L m L + K DIP Lecture 4 3

Periodic Convolution The complexity of the convolution calculation can be reduced by using periodic functions. Let f(n) and h(n) be padded with zeros to length P L + K and then repeated with period P. The resulting periodic functions will be called f P (n) and h P (n). The periodic convolution is defined as g P (m) = k=0 h P (k)f P (m k) The result is periodic with period P. g P (m + jp ) = k=0 h P (k)f P (m + jp k) = k=0 h P (k)f P (m k) DIP Lecture 4 4

Shown at the right are two functions that we would like to process by convolution. f(n) has length L = 6 and h(n) has length K = 5. The functions have been extended by zero-padding to length P = L + K = 0. Example 5 4 3.5 0.5-0.5-4 6 8 Function f(n). 4 6 8 Function h(n). DIP Lecture 4 5

Example The convolution of f P (n) with h P (n) is shown at the right. One period of f P (n) is shown at the top of each column. The cyclic shifts h P (n m) of the filter response are shown in rows -6. 5 4 3 4 6 8.5 0.5 g(0) = 0 4 6 8-0.5 -.5 0.5 g() = 4 6 8-0.5-5 4 3.5 0.5-0.5 -.5 0.5-0.5-4 6 8 4 6 8 4 6 8 g(5) = 5 g(6) =.5.5 The value of g P (m) is found by multiplying h P (m n) with f P (n) and summing. The result for each shift is listed beside the corresponding filter shift. 0.5 g() = 4 4 6 8-0.5 -.5 0.5 g(3) = 8 4 6 8-0.5 -.5 0.5 g(4) = 4 6 8-0.5-0.5-0.5 -.5 0.5-0.5 -.5 0.5-0.5-4 6 8 4 6 8 4 6 8 g(7) = g(8) = 4 g(9) = 5 DIP Lecture 4 6

It is readily demonstrated that Periodic Convolution g P (m) = g(m), 0 m P Thus, we can use circular convolution to compute the a finite convolution. The periodic functions f P (n) and h P (n) have the discrete Fourier transforms F (u) = P f P (n) = u=0 n=0 f P (n)e iπun/p H(u) = P F (u)e iπun/p h P (n) = u=0 n=0 h P (n)e iπun/p H(u)e iπun/p Note the dependence on P, rather than on L or K. Note also that F (u) and H(u) are periodic with period P. DIP Lecture 4 7

Example 5 5 4 3.5 0.5 0 5-0.5 0 0 30 40 50 0 0 30 40 50 0 0 30 40 50 - -5 Function f P (n). Function h P (n). Function g P (n). The functions involved in the periodic convolution of f and h are shown above. The period P = 0 is the minimum length for these functions. The result is a periodic function that is in agreement with g in the interval 0 n K + L. DIP Lecture 4 8

DFT The DFT of g P (m) can be computed by G(u) = P = P m=0 k=0 g P (m)e iπum/p m=0 h P (k)f P (m k)e iπum/p Make the change of index m = k + n and rearrange. G(u) = P = ( P k=0 k=0 h P (k) P k n= k h P (k)e iπuk/p ) f P (n)e iπu(n+k)/p P k n= k f P (n)e iπun/p The terms n = k,..., in the last sum can be replaced by n = P k,..., P because the summand is periodic. Hence... DIP Lecture 4 9

DFT The sum then simplifies to the product G(u) = P ( P k=0 = P H(u)F (u) ) ( h P (k)e iπuk/p P n=0 f P (n)e iπun/p ). By construction, f P (n), h P (n) and g P (n) are all periodic with period P.. It is required that P L + K. 3. F (u), H(u) and G(u) are all complex periodic functions with period P. 4. F (u) can be computed by padding f(n) with zeros to length P and then doing a DFT. 5. A similar statement is true for H(u) and G(u). 6. u takes on integer values. DIP Lecture 4 0

Example Function F (u). Function H(u). Function G(u). The transforms F (u), H(u) and G(u) can be displayed in the complex plane. The points are numbered with the value of the index u, 0 u P. Because the functions are periodic, they follow the same cycle repetitively. DIP Lecture 4

Power Relationships The mean-squared value of f(n) over the interval of length P is P n=0 f P (n)f P (n) = P = u=0 n=0 v=0 u=0 v=0 F (u)f (v)e iπ(u v)n/p ( F (u)f (v) P n=0 e iπ(u v)n/p ) The term in parentheses is δ u,v Hence, P n=0 f P (n) = u=0 F (u). Because f(n) = f P (n) in 0 n P, the above statement is also valid for f(n).. An equivalent statement is true for h P (n) and g P (n). DIP Lecture 4

Example The power calculations for the waveforms and their transforms are shown in the table below. In each case, the same result is obtained in both domains. P u=0 n=0 f P (n) = 5.5 F (u) = 5.5 P u=0 n=0 h P (n) = 0.7 H(u) = 0.7 P u=0 n=0 g P (n) = 63.9 G(u) = 63.9 DIP Lecture 4 3

Filtering of D Functions Let f(x, y) be a L L array that represents the brightness values of an image. Let h(x, y) be a K K array that represents the impulse response of a spatial filter. The result of filtering f with h is the array g(x, y). By analogy with the D example, we find that g(x, y) has size (L + K, L + K ). The convolution operation can be most conviently written in terms of functions that are periodic with period (P, P ), where P L + K P L + K DIP Lecture 4 4

Periodic Convolution The periodic convolution is defined as g P (x, y) = j=0 k=0 h P (j, k)f P (x j, y k) The result is periodic with period P, P. g P (x + ap, y + bp ) = j=0 k=0 h P (j, k)f P (x + ap j, y + bp k) = j=0 k=0 h P (j, k)f P (x j, y k) = g P (x, y) DIP Lecture 4 5

Periodic Convolution. Assume that f(x, y) is given only for 0 x L and 0 y L.. Assume that h(x, y) is given only for 0 x K and 0 y K. 3. Without loss of generality, we can assume any extension we wish outside the region of definition. 4. The convolution g = f h has size (L + K, L + K ). 5. We can construct periodic functions f P (x, y) and h P (x, y) that are defined on the primary frame (P L + K, P L + K ) by padding with zeros. In the examples we will use P = L + K, P = L + K 6. Periodic convolution of f P (x, y) with h P (x, y) produces a periodic function g P (x, y) that is equal to g(x, y) for 0 x P, 0 y P. DIP Lecture 4 6

Periodic Convolution 7. Periodic convolution is equivalent to multiplication of the transforms of the periodic spatial functions. 8. The discrete Fourier transforms are periodic with period (P, P ). F (u, v) = P P x=0 y=0 f P (x, y)e iπ xu P + vy P = P P L x=0 L y=0 f(x, y)e iπ xu P + vy P Similar expressions hold for the other variables. DIP Lecture 4 7

Algorithm. Read the image array f(x, y) and determine the dimensions (L, L ).. Define the filter h(x, y) with dimensions (K, K ). 3. Construct zero-padded arrays f P (x, y) and h P (x, y) with dimensions (P, P ). 4. Compute F (u, v) = FFT(f P (x, y)) and H(u, v) = FFT(h P (x, y)). 5. Compute G(u, v) = P P F (u, v)h(u, v) 6. Compute g P (x, y) = FFT (G(u, v)). DIP Lecture 4 8

Algorithm Example ;STEP : DEFINE THE IMAGE ARRAY WITH SIZE 0X0. N=0 & M=0 x=(findgen(n)-n/)#replicate(,m) y=(findgen(m)-m/)##replicate(,n) fxy=exp(-(xˆ/5+yˆ/5)) ;STEP : DEFINE THE FILTER ARRAY WITH SIZE 3X3. hxy=[[-,0,-],[0,4,0],[-,0,-]] ;STEP 3: PAD THE ARRAYS TO (,). hp=zeropad(hxy,,) fp=zeropad(fxy,,) ;STEP 4: DO THE FFT s ff=fft(fp) hf=fft(hp) ;STEP 5: COMPUTE G(u,v) gf=hf*ff** ;STEP 6: COMPUTE gp gp=float(fft(gf,/inverse)) DIP Lecture 4 9

Example Function f(x, y). Function h P (x, y). Function g P (x, y). Function F (u, v). Function H(u, v). Function G(u, v). DIP Lecture 4 0

Zeropad Function zeropad,a,n,m,center=center ;+ ;B=zeroPad(A,N,M) returns an array B of size NxM such that B[i,j]=A[i,j] ;where A is defined and B[i,j]=0 where A[i,j] is not defined. B is the same ;type as A. ; ;If A is a scalar or a row vector then zeropad can be called with a single ;dimension argument. B=zeroPad(A,N) returns a row vector of length N. ; ;B=zeropad(A) returns an array that has a single ring of zeros around A. ; ;It is an error if N or M is smaller than the corresponding dimension of A. ; ;KEYWORDS ; ;CENTER: Set the keyword center if the array should be centered in the ;field of zeros. ; ;HISTORY ;Written by H. Rhody September, 999 ;Modified to include additional error checks and CENTER keyword ;January 00. ;Modified to handle B=zeropad(A) case. 9.3.005 HR ;- DIP Lecture 4

Zeropad Examples IDL> print,zeropad(4) 0 0 0 0 4 0 0 0 0 IDL> print,zeropad([,,3]) 0 0 0 0 0 0 3 0 0 0 0 0 0 IDL> print,zeropad([,,3],7) 3 0 0 0 0 IDL> print,zeropad([,,3],7,/center) 0 0 3 0 0 IDL> print,zeropad(indgen(3,4),7,8,/center) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 5 0 0 0 0 6 7 8 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 DIP Lecture 4

Comparison with Convolution. Spatial filtering can be carried out by convolution.. IDL contains a fast convolution routine, CONVOL. 3. Care must be taken to do mathematical convolution with CONVOL. Steps to do convolution of arrays A and B with CONVOL.. Determine the dimensions (L, L ) and (K, K ) of A and B.. Construct A p by zero-padding A to size (L + K, L + K ). Ap=zeropad(A,L+K-,L+K-) 3. Compute CP=CONVOL(Ap,B,CENTER=0,/EDGE ZERO). This procedure replaces a more complicated method that was required before the EDGE ZERO keyword was introduced in IDL 6.. The old method is used in the CONVOLVE program below, which makes it compatible with older versions of IDL. DIP Lecture 4 3

CONVOLVE Program FUNCTION CONVOLVE,A,M,SCALE,_EXTRA=extra ;+ ;B=CONVOLVE(A,M,S) returns an array B that is the D ;convolution of the arrays A and M. The convolution calculation ;is actually carried out by the IDL CONVOL routine. ; ;An array AP is constructed by padding A, then ;C=CONVOL(AP,M,S,CENTER=0,/EDGE_TRUNCATE) is computed ;and then C is trimmed to provide the proper output. ; ;The size of the returned array is equal to ;Ac+Mc- by Ar+Mr-, where Ac x Ar is the size of ;A and Mc x Mr is the size of M. ; ;If S is provided then the results are scaled by ;passing S to the CONVOL routine. Otherwise, the ;scale value S= is used. ; ;CONVOL keywords are passed via _EXTRA. ; ;H. Rhody ;September, 00 ;- DIP Lecture 4 4

CONVOLVE (cont) IF N_PARAMS() LT THEN MESSAGE, Incorrect number of parameters. SA=Size(A) SM=Size(M) typea=sa[sa[0]+] typem=sm[sm[0]+] IF N_PARAMS() LT 3 THEN SCALE= ;Determine the width and height parameters. The case of a D array ;has to be handled differently. CASE SA[0] OF : BEGIN WA=SA[] & HA= END : BEGIN WA=SA[] & HA=SA[] END ENDCASE CASE SM[0] OF : BEGIN WM=SM[] & HM= END : BEGIN WM=SM[] & HM=SM[] END ENDCASE DIP Lecture 4 5

CONVOLVE (cont) ;Construct a zero-padded array to use in the convolution operation SAP=[,WA+*(WM-),HA+*(HM-),MAX([typeA,typeM]),(WA+*(WM-))*(HA+*(HM-))] AP=Make_Array(Value=0,Size=SAP) AP[WM-:WM+WA-,HM-:HM+HA-]=A ;Do the convolution of AP with M AC=CONVOL(AP,M,SCALE,CENTER=0,/EDGE_TRUNCATE,_EXTRA=extra) ;Trim and return the convol result. CSTART=WM- RSTART=HM- RETURN,AC[CSTART:CSTART+WM+WA-,RSTART:RSTART+HM+HA-] END DIP Lecture 4 6

Comparison of Transform and Convolution Methods Output Difference Shown above is the output array and the magnitude of the difference between the transform and convolution methods. All of the differences are less than 3 0 7. DIP Lecture 4 7

Power Calculations The mean-squared value can be computed in either the spatial or frequency domain. P P x=0 y=0 For the preceding example we have f P (x, y) = u=0 v=0 F (u, v) x=0 y=0 f P (x, y) = 0.08 u=0 v=0 F (u, v) = 0.08 DIP Lecture 4 8

Power Calculations (cont) The output image has the frequency-domain relationship G(u, v) = P P F (u, v)h(u, v) Hence, the power can be computed by P P x=0 y=0 g(x, y) = u=0 v=0 G(u, v) = (P P ) u=0 v=0 F (u, v) H(u, v) =.047 for the example above DIP Lecture 4 9

Image Filtering Example Image arrays can be processed by either spatial or transform filtering. Just substitute the image array for f(x, y) in the above techniques. You may need to rescale the amplitude of the final array to fit the range [0,55] for display. Original Image Transform Filtering Convolution Filtering DIP Lecture 4 30