Le Activity Sechs

Properties and applications of the 2D Fourier Transform. We start with the anamorphic properties of the fourier transform. I genereated the following patterns:

Figure 1. (top left) Dots along the x-axis, (top-right) dots along the x-axis with larger spacing, (bottom-left) tall rectangle, (bottom-right) wide rectangle.

Taking their Fourier transforms, I get:

Figure 2. Corresponding Fourier transforms of the patterns in figure 1.

Anamorphism in the fourier transform is basically described in the scaling property in fourier transforms which says that a signal multiplied by some constant implies a division by the same constant in the frequency space. Basically it says that the smaller the spatial pattern, the higher spatial frequency it will occupy. This can be seen in the rectangular patterns where the axis with a thinner window produces a fourier transform with peaks occupying the higher frequencies.

For the rotation of the FFT, I generated the following synthetic images:

Figure 3. Corrugated roof patterns with different frequencies and their Fourier transforms

The change in sinusoid frequency displays anamorphism seen when the dots in the fourier space are farther apart for the tightly packed corrugated roof. Adding a bias to the sinusoid to simulate a real image, we get the a peak in the center as shown in the next figure. The next figure also shows the effect of rotation in the spatial domain to the resulting spatial domain.

Figure 4. (left) Central peak in frequency domain due to bias, (top-right) rotated sinusoid pattern, (bottom-right) fourier transform of rotated pattern.

The images in the right side of figure 4 show the effect of rotation in the spatial domain to the resulting fourier transform. It can be seen that a rotation in the pattern will also create a rotation in the fourier transform. Here is another example:

Figure 5. Rotation of a combination of sinusoids will lead to the rotation of its fourier transform.

Next, we attempt ridge enhancement in a fingerprint pattern. The finger print pattern chosen and the converted gray image is shown by:

Figure 6. Chosen fingerprint image (from http://www.safenet-inc.com/multi-factor-authentication/authenticators/pki-smart-cards/smart-card-400-with-biometric-authentication/) and the converted gray image.

We look at the fourier transform of the fingerprint and apply a filter in the attempt to enhance the ridges. I treat the fingerprint as details that contribute to the low spatial frequencies while the small unneeded details are in the higher frequencies. Thus to isolate the fingerprint, I mask out the higher frequencies to yield:

Figure 7. The fourier transform of the fingerprint and the enhanced image.

Next I attempt to remove the lines in a lunar landing image. I expect that the periodic lines will contribute to the low frequencies in the fourier domain. To remove these lines I should therefore filter out the low frequencies from the fourier domain. The images are shown below:

Figure 8. (top-left) Original lunar landing image, (top-right) gray image, (bottom-left) fourier transform of the gray image, (bottom-right) vertical lines removed by filtering the lower frequencies.

Lastly, I attempt to remove the canvas weave pattern in a painting. Similar to the lunar landing image, I expect the periodic dot pattern from the canvas to occupy relatively low frequencies and thus applying the same technique as the lunar landing pattern I get the following images:

Figure 9. (top left) Original painting, (top-right) gray image, (bottom-left) fourier transform of the painting, (bottom-right) weave pattern softened by removing the lower frequencies.

For this activity I give myself a score of 7 for lacking output. 😦

This is the python code I used for the experiment:

import numpy as np

import matplotlib.pyplot as plt

import matplotlib.cm as cm

import Image as im

N=128

#Anamorphic property

A=np.zeros([N,N])

B=np.ones([N/2,N/4])

C=np.ones([N/4,N/2])

D=np.array([[1,0,0,0,0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0,0,0,0,0]])

E=np.array([[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]])

x=(len(A)-len(E))/2

y=(len(A[0])-len(E[0]))/2

A[x:x+E.shape[0],y:y+E.shape[1]]=E

FT=np.abs(np.fft.fftshift(np.fft.fft2(A)))

#plt.matshow(FT, cmap=cm.gray)

#Rotation property

x=np.linspace(-1,1,N)

y=np.linspace(-1,1,N)

[X,Y]=np.meshgrid(x,y)

f=4

#Z=np.sin(2*np.pi*f*X)

#Z=Z+2

theta=np.pi/6

Z=np.sin(2*np.pi*f*(Y*np.sin(theta)+X*np.cos(theta)))

#Z=np.sin(2*np.pi*f*X)*np.sin(np.pi*f*Y)

#Z=np.sin(2*np.pi*f*(Y*np.sin(theta)+X*np.cos(theta)))

#Zp=np.sin(np.pi*f*(Y*np.sin(theta+np.pi/2)+X*np.cos(theta+np.pi/2)))

#Z=Z*Zp

z=np.abs(np.fft.fftshift(np.fft.fft2(Z)))

#plt.matshow(Z,cmap=cm.gray)

#finger=np.asarray(im.open(“finger.png”).convert(‘L’))

FT=np.log(np.abs(np.fft.fftshift(np.fft.fft2(finger))))

mask=np.ones([310,310])

back=np.zeros_like(finger)

x=(len(FT)-len(mask))/2

y=(len(FT[0])-len(mask[0]))/2

FT=np.fft.fft2(finger)

back[x:x+mask.shape[0],y:y+mask.shape[1]]=mask

FT=back*FT

IFT=np.abs(np.fft.fft2(FT))

#plt.matshow(IFT, cmap=cm.gray)

lunar=np.asarray(im.open(“hi_res_vertical_lg.gif”).convert(‘L’))

FT=np.log(np.abs(np.fft.fftshift(np.fft.fft2(lunar))))

FT=np.fft.fft2(lunar)

mask=np.zeros([len(FT),430])

x=(len(FT)-len(mask))/2

y=(len(FT[0])-len(mask[0]))/2

FT[x:x+mask.shape[0],y:y+mask.shape[1]]=mask

mask=np.zeros([430,len(FT[0])])

x=(len(FT)-len(mask))/2

y=(len(FT[0])-len(mask[0]))/2

FT[x:x+mask.shape[0],y:y+mask.shape[1]]=mask

IFT=np.abs(np.fft.fft2(FT))

plt.matshow(IFT, cmap=cm.gray)

canvas=np.asarray(im.open(“canvasweave.JPG”).convert(‘L’))

FT=np.log(np.abs(np.fft.fftshift(np.fft.fft2(canvas))))

FT=np.fft.fft2(canvas)

mask=np.zeros([len(FT),380])

x=(len(FT)-len(mask))/2

y=(len(FT[0])-len(mask[0]))/2

FT[x:x+mask.shape[0],y:y+mask.shape[1]]=mask

mask=np.zeros([380,len(FT[0])])

x=(len(FT)-len(mask))/2

y=(len(FT[0])-len(mask[0]))/2

FT[x:x+mask.shape[0],y:y+mask.shape[1]]=mask

IFT=np.abs(np.fft.fft2(FT))

#plt.matshow(IFTl,cmap=cm.gray)

Leave a comment