engi 4559 signal processing for software engineers dr. richard khoury fall 2009
TRANSCRIPT
ENGI 4559 Signal Processing for Software Engineers
Dr. Richard KhouryFall 2009
Fourier Analysis in 2D: Overview2D Extensions of Fourier TransformAliasing and Moiré PatternsFourier Transform of ImagesMatlab
2 ENGI 4559 © Dr. Richard Khoury, 2009
2D Extensions: CTFT
ENGI 4559 © Dr. Richard Khoury, 20093
dtetsS tj)()(
deSts tj)(2
1)(
2121212211),(),( dtdteettsS tjtj
2121212211),(
²4
1),( ddeeStts tjtj
2D Extensions: DTFT
ENGI 4559 © Dr. Richard Khoury, 20094
n
njensS )()(
deSns nj)(2
1)(
x
yj
y
xj eeyxsS 21),(),( 21
2121
21),(²4
1),( ddeeSyxs yjxj
2D Extensions: DFT
ENGI 4559 © Dr. Richard Khoury, 20095
1
0
2
)()(N
n
knN
jenskS
1
0
2
)(1
)(N
k
knN
jekS
Nns
1
0
21
0
2
21
21
),(),(X
x
ykY
jY
y
xkX
jeeyxskkS
1
0
21
0
2
21
1
2
2
1
),(1
),(X
k
ykY
jY
k
xkX
jeekkS
XYyxs
2D Extensions: Sampling Theorem1D sampling theorem:
If the maximum frequency contained in an analog signal is Ωmax = B, then it can be perfectly reconstructed from samples taken at the sampling frequency Ωs = 2B (or more).
2D sampling theorem:If the maximum frequency contained in an analog signal is Ω1 = B1 in one direction and Ω2 = B2 in the other, then it can be perfectly reconstructed from samples taken at the sampling frequencies Ωs1 = 2B1 in the first direction and Ωs2 = 2B2 in the other.
ENGI 4559 © Dr. Richard Khoury, 20096
2D Extensions: Aliasing
ENGI 4559 © Dr. Richard Khoury, 20097
Aliasing in ImagesImagine a perfect digital camera taking a
picture of a checkerboard where each square is one pixel in size
If we sample it (i.e. take the picture) at a resolution of several pixels per square, it works
16 pixels per square:
6 pixels per square:
ENGI 4559 © Dr. Richard Khoury, 20098
Aliasing in ImagesAt resolutions less than one pixel per square,
severe aliasing occurs0.9 pixels per square:
ENGI 4559 © Dr. Richard Khoury, 20099
Aliasing in ImagesIn DIP, modifying the sampling rate is not always possible
Downsampling (shrinking) a picture would require access to the original scene to resample it
Aliasing is unavoidableOften covered up by blurring the image slightly before
resizing
ENGI 4559 © Dr. Richard Khoury, 200910
Aliasing in ImagesAliasing is very visible in diagonal edges
ENGI 4559 © Dr. Richard Khoury, 200911
Moiré Patterns
ENGI 4559 © Dr. Richard Khoury, 200912
Another common type of artefact
Result of sampling an image that already has a sampled periodic element
Typically visible in Two overlapping insect
window screensStriped material on TVDigital scan of
newspaper pictures
Moiré PatternsTake two patterns that are
individuallyClean and devoid of
interferencePeriodic or nearly periodicAt different angles from each
otherSuperimposing one on the
other creates a new pattern with frequencies that do not exist in the originals
ENGI 4559 © Dr. Richard Khoury, 200913
Fourier Transform of ImagesThe Fourier transform of an image is
generally a complex number
where
ENGI 4559 © Dr. Richard Khoury, 200914
1221
121212
1
0
21
0
2
21 ),(),(
jX
x
ykY
jY
y
xkX
jerjIReeyxskkS
1,...,1,0
1,...,1,0
)/arctan(
2
1
121212
2212 1212
Yk
Xk
RI
IRr
Fourier Transform of ImagesThe magnitude r12 is the Fourier spectrum or
frequency spectrumr12² is the power spectrum
The exponent ω12 is the phase angleWe can display the resulting matrices as
images!
ENGI 4559 © Dr. Richard Khoury, 200915
Fourier Transform of ImagesLet’s run an experiment!We’ll use this imageWe compute the DFT and display
the spectrumAll the highest values are in the
cornersThey correspond to the zero
frequenciesIt’s more convenient (and
conventional) to shift the graphic to display them in the middle
Still too dark to make out the detailsSo we normalize and display
ENGI 4559 © Dr. Richard Khoury, 200916
)(log1 1210 r
Fourier Transform of ImagesThe phase angle can be displayed directlyWhat does it mean?
The spectrum represents the amplitude of the sinusoids that form the signal
The phase is the displacement of each sinusoid to the origin
ENGI 4559 © Dr. Richard Khoury, 200917
ENGI 4559 © Dr. Richard Khoury, 200918
Fourier Transform of Images
ENGI 4559 © Dr. Richard Khoury, 200919
)( 1212
jerifft )( 12rifft )( 12jeifftLenna 12r 12
Fourier Transform of ImagesThe Fourier Spectrum represents intensitiesTheir positions in the spectrum has meaning
too
ENGI 4559 © Dr. Richard Khoury, 200920
Center value (origin, since we shifted the graph) is the average intensity value of the image
Low frequency values (near the origin) are slow-varying intensity regions
High frequency values (far from the origin) are regions with fast variations in intensity
MatlabMatlab already implements the 1D and 2D
DFTF = fft2(M) computes the 2D DFT of a matrix
MM = ifft2(F) computes the 2D inverse DFT of
a Fourier matrix, recovering the original matrix M
F = fftshift(M) performs a quadrant shift of the matrix, which is convenient to display the Fourier spectrum
ENGI 4559 © Dr. Richard Khoury, 200921
Matlab>> z = 4 + 3i;
>> r = abs(z)
r = 5
>> r = sqrt(real(z)^2 + imag(z)^2)
r = 5
>> theta = atan2(imag(z),real(z))
theta = 0.6435
>> z = r *exp(i *theta)
z = 4.0000 + 3.0000i
ENGI 4559 © Dr. Richard Khoury, 200922
)/arctan(
²²
RI
IRr
rejIR j
MatlabComputing the Fourier spectrum and phase angle%Read the image using the method we knowimagereal = imread('lenna.png');%Convert from uint8 to double for mathimagereal = double(imagereal);%Fourier transformF = fft2(imagereal);%Fourier spectrumSpectrum = sqrt( real(F).^2 + imag(F).^2 );%Shift the spectrum, as per conventionSpectrumS = fftshift(Spectrum);%Phase anglePhase = atan2( imag(F), real(F) );
ENGI 4559 © Dr. Richard Khoury, 200923
MatlabDisplaying the spectrum and phase
figure;
colormap(gray)
imagesc(1+log10(SpectrumS))
title('Fourier Spectrum')
figure;
colormap(gray)
imagesc(Phase)
title('Phase angle')
ENGI 4559 © Dr. Richard Khoury, 200924
Don’t forget to normalize the spectrum display!
MatlabReconstructing the image%Shift the spectrum backSpectrumSS = fftshift(SpectrumS);%Compute the values of Fourier TransformF2 = SpectrumSS .* exp(sqrt(-1)* Phase );%Perform the inverse DFT%Note that rounding errors can leave a small % imaginary part (10-14) which we must discardreconstructed = real(ifft2(F2));%Display the imagefigure;colormap(gray)imagesc(reconstructed)title('Reconstructed image')
ENGI 4559 © Dr. Richard Khoury, 200925
SummaryWe learned the 2D equations of the
continuous-time, discrete-time, and discrete Fourier transform, and of the sampling theorem
We considered the effect of aliasing and Moiré patterns, and the difference between these two phenomena
We applied our knowledge by computing the Fourier transform of images, and splitting the result into the frequency spectrum and phase angle componentsAnd we learned the meaning of these two
components
ENGI 4559 © Dr. Richard Khoury, 200926