The activity is entitled: Fourier transform model of image formation. (I got this.) The mathematical side of the Fourier transform has be previously discussed in AP 185. In image formation, we now apply the Fourier transform to change the physical dimension of an image to its spatial frequency. To familiarize myself with the discrete Fourier transform, I take the Fourier transforms of different images. (Program written in Python)
Figure 1. (top-left) Synthetic circle image, (top-middle) Fourier transform of the synthetic circle, Airy pattern, (top-right) Fourier transform of the Airy pattern. (bottom-left) Image of the letter ‘A’, (bottom-right) Fourier transform on the letter ‘A’.
I started with a circular aperture and the capital letter ‘A’ as my initial test images. As predicted by the analytical Fourier transform, there is an Airy pattern produced when I take the Fourier transform of a circular aperture. Here are the other produced synthetic images:
Figure 2. (top-left pair) Sinusoid/Corrugated roof and its Fourier transform, (top-right pair) double slit and its Fourier Transform, (middle-left pair) modified double slit and its Fourier transform, (middle-right pair) centered square and its Fourier transform, (bottom pair) Gaussian bell curve and its Fourier transform.
Next, we were to simulate the image of the word ‘VIP’ as viewed from an aperture. To do this, we need to convolute the Fourier transform of the ‘VIP’ image with the aperture (already in frequency domain). It can be seen that the resulting image in convolution still shows the word ‘VIP’ written in an Airy pattern-like font. These are the images acquired:
Figure 3. (left) Image of the aperture used in convolution which is already considered to be in fourier domain, (middle) image of the word ‘VIP’, (right) and the convolution or effectively the product of the Fourier transform of the ‘VIP’ image and the aperture.
Next, we are to locate all the A’s in the phrase: THE RAIN IN SPAIN STAYS MAINLY IN THE PLAIN. To do this, we need to perform correlation on the image of the phrase and the image of the letter ‘A’ by multiplying the Fourier transform of the text to the complex conjugate of the Fourier transform of the letter ‘A’. It can be seen that if the text image is inverted (written from bottom right to top left), the peaks in correlation image show the locations of the letter A’s in the text. These are the images acquired:
Figure 4. (left) Image of the letter ‘A’, (middle) image of the text, (right) and the correlation of the two images.
For this activity, I would give myself a score of 8 for the lacking output. This is the python code I used for the activity.
# -*- coding: utf-8 -*-
“””
Created on Wed Sep 9 11:02:14 2015
@author: jesli
“””
#AP186 Activity5
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import Image as im
import scipy as sp
def gaussian(x):
return np.exp(-(x**2)/2)
M=128
W=10
dim=range(M)
x=np.linspace(-5,5,M)
[xx,yy]=np.meshgrid(x,x)
##Circle
#r=np.sqrt(xx**2+yy**2)
#A=np.zeros([M,M])
#for i in dim:
# for j in dim:
# if r[i][j]<=0.5:
# A[i][j]=1
##Sinusoid
#A=np.sin(xx*np.pi)
##Simulated double slit
#A=np.zeros([M,M])
#for i in dim:
# for j in dim:
# if np.abs(xx[i][j])>=1.5 and np.abs(xx[i][j])<=1.7:
# A[i][j]=1
##Double slit 2
#A=np.zeros([M,M])
#for i in dim:
# for j in dim:
# if np.abs(xx[i][j])>=1.5 and np.abs(xx[i][j])<=1.7 and np.abs(yy[i][j])<=4:
# A[i][j]=1
##Square function
#A=np.zeros([M,M])
#for i in dim:
# for j in dim:
# if np.abs(xx[i][j])<=1 and np.abs(yy[i][j])<=1:
# A[i][j]=1
##2D Gaussian
#r=np.sqrt(xx**2+yy**2)
#A=gaussian(2*r)
## ‘A’ image to matrix
#image=im.open(“A.jpg”)
#im=np.array(image)/np.max(np.array(image))
#A=im[:,:,0]
#’VIP’ image to matrix and convolution
image=im.open(“VIP.jpg”)
im=np.array(image)/np.max(np.array(image))
B=im[:,:,0]
#A=np.fft.fftshift(A)
#Bft=np.fft.fft2(B)
#C=A*Bft
#D=np.fft.ifft2(C)
#intensity=np.abs(D)
## Text correlation
#image1=im.open(“Text.jpg”)
#B=np.array(image1)/np.max(np.array(image1))
#image2=im.open(“A2.jpg”)
#A=np.array(image2)/np.max(np.array(image2))
#a=np.fft.fft2(A)
#b=np.fft.fft2(B)
#b=np.conjugate(b)
#c=a*b
#C=np.fft.ifft2(c)
#intensity=np.abs(C)
#intensity=np.fft.fftshift(intensity)
#Edge detection by convolution
A=np.array([[-1,-1,-1],[2,2,2],[-1,-1,-1]])
C=np.zeros([128,128])
#for i in range(len(C)):
# for j in range(len(C[0])):
# if j>=62 and j<=64 and i>=62 and i<=64:
# C[i][j]=A[i-62][j-62]
x=62
y=x
C[x:x+A.shape[0],y:y+A.shape[1]]=A
C=np.fft.fftshift(C)
b=np.fft.fft2(B)
d=C*b
D=np.fft.ifft2(d)
intensity=np.abs(D)
#ft=np.fft.fft2(A)
#intensity=np.abs(ft)
#shifted=np.fft.fftshift(intensity)
#ft2s=np.fft.fft2(shifted)
#ft2s=np.abs(ft2s)
#ft2s=np.fft.fftshift(ft2s)
#ft2i=np.fft.fft2(intensity)
#ft2i=np.abs(ft2i)
#ft2i=np.fft.fftshift(ft2i)
#plt.figure(1)
#plt.matshow(A,cmap=cm.gray)
plt.figure(2)
plt.matshow(intensity,cmap=cm.gray)
#plt.figure(3)
#plt.matshow(shifted,cmap=cm.gray)
#plt.figure(4)
#plt.matshow(ft2s,cmap=cm.gray)
#plt.figure(5)
#plt.matshow(ft2i,cmap=cm.gray)