31
Lecture 13: Implementation and Applications of 2D Transforms Harvey Rhody Chester F. Carlson Center for Imaging Science Rochester Institute of Technology [email protected] October 25, 2005 Abstract The Fourier transform provides information about the global frequency-domain characteristics of an image. The Fourier description can be computed using discrete techniques, which are natural for digital images. This lecture addresses the implementation of the 2D transform and provides examples of its use. DIP Lecture 13

Lecture 13: Implementation and Applications of 2D Transforms · Lecture 13: Implementation and Applications of 2D Transforms Harvey Rhody Chester F. Carlson Center for Imaging Science

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Lecture 13: Implementation and Applicationsof 2D Transforms

Harvey RhodyChester F. Carlson Center for Imaging Science

Rochester Institute of [email protected]

October 25, 2005

AbstractThe Fourier transform provides information about the global

frequency-domain characteristics of an image. The Fourier descriptioncan be computed using discrete techniques, which are natural fordigital images. This lecture addresses the implementation of the 2Dtransform and provides examples of its use.

DIP Lecture 13

Image Transformation

Let A be an N ×M array that represents an image in the spatial domain.

The frequency-domain representation is found by using the FFT.

AF=FFT(A)

The array AF is complex and has dimensions N ×M .

The frequency-domain origin of AF is position [0,0]. Filtering is facilitatedby shifting the origin to [N/2,M/2] using the command

AFS=Shift(AF,N/2,M/2)

DIP Lecture 13 1

Effect of ShiftingThe DFT is

F (u, v) =1

MN

N−1∑x=0

M−1∑y=0

f(x, y)e−i2π(uxN +vy

M )

f(x, y) =N−1∑u=0

M−1∑v=0

F (u, v)ei2π(uxN +vy

M )

Shifting F (u, v) is equivalent to replacing (u, v) → (u − u0, v − v0). Theeffect in the spatial domain is

fs(x, y) = F−1F (u− u0, v − v0)

=N−1∑u=0

M−1∑v=0

F (u− u0, v − v0)ei2π(uxN +vy

M )

=N−1−u0∑s=−u0

M−1−v0∑t=−v0

F (s, t)ei2π�

(s+u0)xN +

(t+v0)yM

DIP Lecture 13 2

Effect of Shifting

fs(x, y) =

N−1−u0∑s=−u0

M−1−v0∑t=−v0

F (s, t)ei2π�

(sxN + ty

M

� ei2π(u0x

N +v0yM )

Everything in the summation is periodic with period (N,M). Therefore,the starting index on the sum is not significant, and

fs(x, y) =

(N−1∑s=0

M−1∑t=0

F (s, t)ei2π�

(sxN + ty

M

�)ei2π(u0x

N +v0yM )

= f(x, y)ei2π(u0xN +

v0yM )

The image fs(x, y) has the same amplitude information as a function oflocation, but it is modulated by a phase shift that depends on (x, y). Sincethe phase shift is known, it can be removed.

DIP Lecture 13 3

Effect of Shifting

In particular,|f(x, y)| = |fs(x, y)|

If f(x, y) is known to contain only non-negative real numbers as it doesin images, then the phase modulation can be eliminated by using themagnitude

f(x, y) = |fs(x, y)|

Shift by (N/2,M/2)

If N and M are even and u0 = N/2 and v0 = M/2 the phase is

2π(u0x

N+

v0y

M

)= π(x + y)

Therefore,fs(x, y) = f(x, y)(−1)x+y

DIP Lecture 13 4

Effect of Shifting

The hurricane image from the IDL distribution is shown below. Themodulation effect produced by a (N/2,M/2) shift is shown to the right.

Hurricane image (440×340) Effect of shifting F (u, v) by (220,170)

DIP Lecture 13 5

Effect of Shifting

Corresponding small regions of the image arrays illustrate the effect.

56. 48. 52. 56. 52.44. 48. 52. 56. 52.52. 44. 52. 56. 60.56. 52. 52. 48. 60.64. 56. 56. 48. 56.

56. −48. 52. −56. 52.−44. 48. −52. 56. −52.

52. −44. 52. −56. 60.−56. 52. −52. 48. −60.

64. −56. 56. −48. 56.From f(x, y) From fs(x, y)

Note the sign changes that follow the diagonal lines of the array.

DIP Lecture 13 6

Frequency Grid

We often want to process an image by using a filter that is described in thefrequency domain.

G(u, v) = F (u, v)H(u, v)

Many filter functions are constructed analytically. We need to be ableto convert the analytical expression into an array of values of the properdimensions.

The conversion can be done by representing U and V as coordinate arraysand then evaluating H(U, V ).

-3 -2 -1 0 1 2-3 -2 -1 0 1 2-3 -2 -1 0 1 2-3 -2 -1 0 1 2-3 -2 -1 0 1 2-3 -2 -1 0 1 2

-3 -3 -3 -3 -3 -3-2 -2 -2 -2 -2 -2-1 -1 -1 -1 -1 -10 0 0 0 0 01 1 1 1 1 12 2 2 2 2 2

Array U Array V

The array origin must be constructed to match the origin of F (u, v).

DIP Lecture 13 7

Frequency Grid

IDL array multiplication operators can be used to construct the desired gridarrays. Let uu and vv be row vectors of lengths N and M , respectively,that contain the (u, v) coordinates. Then U and V can be constructed by

U=uu#Replicate(1,M)V=vv##Replicate(1,N)

For example, to construct arrays that have the origin at (N/2,M/2)

U=(Findgen(N)-N/2)#Replicate(1,M)V=(Findgen(M)-M/2)##Replicate(1,N)

DIP Lecture 13 8

Lowpass Filter

We can construct a symmetric lowpassfilter like the one shown by use of theanalytic expression

H(U, V ) =1

1 +(

U2+V 2

D20

)p

In terms of IDL

D2=Uˆ2+Vˆ2H=1/(1+(D2/D0ˆ2)ˆp)

For this example N = M = 101, p = 1and D0 = 10.

DIP Lecture 13 9

Non-Isotropic Filters

When distance is measured using the standard Euclidean scale then thefilter turns out isotropic–meaning that the response depends only on thedistance from the frequency origin.

An elliptical measure can be used to make a non-isotropic response. Theequation of a simple ellipse is

u2

a2+

v2

b2= 1

The ellipse intersects the u-axis at ±a and the v-axis at ±b.

Distance from the origin is measured in units of a and b. A distance arrayis now

D2=(U/a)ˆ2+(V/b)ˆ2

DIP Lecture 13 10

Filter Response

Equal distance contours Butterworth LPF

The Butterworth LPF response is computed with the elliptical distance array

H =1

1 + (D2)p

The footprint of the filter is controlled by the (a, b) values.

DIP Lecture 13 11

Coordinate Rotation

Assume that you have an initial coordinate grid (u, v). To rotate by anangle α you need new coordinate values.

s = u cos α + v sinα

t = u sinα− v cos α

Then an array can be constructed using the (s, t) coordinates, but referencedusing the (u, v) coordinates. This produces a rotation by α.

A function H(s, t) will be a rotated version of H(u, v).

DIP Lecture 13 12

Coordinate Rotation

Construct an ellipse that isrotated with respect to thecoordinate axes.

D2=(s/a)ˆ2+(t/b)ˆ2H=1/(1+D2ˆp)Contour,H,s,tContour,H,u,v

(u, v)-plane (s, t)-plane

DIP Lecture 13 13

Rotated Elliptical Butterworth Filter

Axis rotation can be used to produce the array for a rotated ellipticalButterworth filter.

Equal distance contours Butterworth LPF

DIP Lecture 13 14

Filter Rotation

Coordinate rotation can be used with any filter response function.

1. Construct arrays for u and v (or x and y if in the spatial domain).

2. Rotate the axes by α using

s = u cos α + v sinα

t = u sinα− v cos α

3. Construct H(s, t).

DIP Lecture 13 15

Rectangular Filter

N=401 & M=401u=(Findgen(N)-N/2)#Replicate(1,M)v=(Findgen(M)-M/2)##Replicate(1,N)alpha=!pi/6s=u*Cos(alpha)+v*sin(alpha)t=u*sin(alpha)-v*cos(alpha)H1=(Abs(u) LE 70) AND (Abs(v) LE 50)H2=(Abs(s) LE 70) AND (Abs(t) LE 50)Window,/Free,xsize=N,ysize=2*M+1TVSCL,H1,0,M+1TVSCL,H2

DIP Lecture 13 16

Example 1: Additive Harmonic Distortion

Shown below is an original picture and the same picture with additiveharmonic distortion. The goal is the recovery of the original image.

DIP Lecture 13 17

Plan

1. Analyze the distorted image to determine the distortion frequencies.

2. Construct a filter that removes the distortion components.

3. Filter the distorted image by multiplication in the frequency domain.

4. Transform the filtered image to the spatial domain.

5. Display the result.

DIP Lecture 13 18

Step 1

We will read the image array, find its dimensions, do the transform, andfind the distortion components.

B=Read Image(’barb.bmp’)SB=Size(B,/dimensions) & N=SB[0] & M=SB[1]u=(Findgen(N)-N/2)#Replicate(1,M)v=(Findgen(M)-M/2)##Replicate(1,N)BF=Shift(FFT(B),N/2,M/2)BF0=BF & BF0[N/2,M/2]=0;Suppress (0,0) component for displayWindow,0,xsize=400,ysize=400Contour,ABS(BF0),u,vWindow,1,xsize=400,ysize=400Surface,ABS(BF0),u,v

DIP Lecture 13 19

Step 1: Results

Contour and surface plots are shown below. Evidently the distortion is aharmonic at frequency (u0, v0) = (40,−20). (Only the central part of thearray was displayed, and gridlines were added to the contour plot.)

DIP Lecture 13 20

Step 2: Construct a Filter

We want to suppress the frequency components in a small zone around(u0, v0) and (−u0,−v0). Use circular regions with radius c.

u0=40 & v0=-20 & c=3H=1-((((u-u0)ˆ2+(v-v0)ˆ2) LT cˆ2)$

+(((u+u0)ˆ2+(v+v0)ˆ2) LT cˆ2))Shade Surf,H[206:306,206:306],u[206:306,206:306],v[206:306,206:306]

DIP Lecture 13 21

Steps 3-5: Remove the Distortion

BFH=BF*H; Filter the imageBFHI=Abs(FFT(BFH,/Inverse)) ;Back TransformWindow,1,xsize=N,ysize=MTV,BFHI

Original Restored

DIP Lecture 13 22

Example 2: Non-harmonic Banding

The image below has been corrupted non-harmonic banding.

DIP Lecture 13 23

Image Analysis

Contour and surface plots are shown below. Evidently the distortion is afrequency sweep (chirp) with a 1 : 2 slope.

DIP Lecture 13 24

Step 2: Construct a Filter

We want to suppress the frequency components along the line with a 1 : 2slope but leave some of the central area or we will erase picture content.

phi=Atan(1,2)s=u*cos(phi)-v*sin(phi)t=u*sin(phi)+v*cos(phi)H=1-(Abs(s) LE 20 and Abs(s) GT 5 AND Abs(t) LE 1)Shade Surf,H[206:306,206:306],u[206:306,206:306],v[206:306,206:306]

The filter response is shown on the next slide.

DIP Lecture 13 25

Filter Design

Filter Response Filter Response

DIP Lecture 13 26

Results

BFH=BF*H; Filter the imageBFHI=Abs(FFT(BFH,/Inverse)) ;Back Transform

Original Distorted Restored

The image is partially restored but the result is not perfect. A more detailedfilter design may be more successful.

DIP Lecture 13 27

Example 3 – Sharpening Filter

A high-pass filter can be used to emphasize high frequency information. Ifone has an analytical expression for a LP filter, then one can form

Hhp(u, v) = 1−Hlp(u, v)

For a Butterworth filter of order p and cutoff D0 this becomes

Hhp(U, V ) =

(U2+V 2

D20

)p

1 +(

U2+V 2

D20

)p

DIP Lecture 13 28

Example 3The test chart image is of size500× 500.

A filter array with parametersD0 = 15 and p = 2 is constructedby:

N=500 & M=500D0=15 & p=2U=(Findgen(N)-N/2)#Replicate(1,M)V=(Findgen(M)-M/2)##Replicate(1,N)D=((U^2+V^2)/D0^2)^pH=D/(1+D)

DIP Lecture 13 29

Example 3

D0 = 15 D0 = 80

DIP Lecture 13 30