Thursday, May 31, 2012

2D DFT and Convolution


2D DFT and Convolution

The regular 2D convolution equation is
g[m,n]=
N1
k=0
 (
N1
l=0
 (f[k,l]h[mk,nl])
)
(5)

EXAMPLE 2

Below we go through the steps of convolving two two-dimensional arrays. You can think of f as representing an image and h represents a PSF, where h[m,n]=0 formn>1 and mn<0h=(
h[0,0]h[0,1]
h[1,0]h[1,1]
) f=(
f[0,0]f[0,N1]
f[N1,0]f[N1,N1]
)
 Step 1 (Flip h):
h[m,n]=(
h[1,1]h[1,0]0
h[0,1]h[0,0]0
000
)
(6)
Step 2 (Convolve):
g[0,0]=h[0,0]f[0,0](7)
We use the standard 2D convolution equation (Equation 5) to find the first element of our convolved image. In order to better understand what is happening, we can think of this visually. The basic idea is to take h[m,n] and place it "on top" of f[k,l], so that just the bottom-right element, h[0,0] of h[m,n] overlaps with the top-left element, f[0,0], of f[k,l]. Then, to get the next element of our convolved image, we slide the flipped matrix, h[m,n], over one element to the right and get the following result: g[0,1]=h[0,0]f[0,1]+h[0,1]f[0,0] We continue in this fashion to find all of the elements of our convolved image, g[m,n]. Using the above method we define the general formula to find a particular element of g[m,n] as:
g[m,n]=h[0,0]f[m,n]+h[0,1]f[m,n1]+h[1,0]f[m1,n]+h[1,1]f[m1,n1](8)

Circular Convolution

EXERCISE 1

What does H[k,l]F[k,l] produce?
Due to periodic extension by DFT (Figure 2):
Figure 2
Figure 2 (dft_extension.png)
Based on the above solution, we will let
g[m,n]=IDFT(H[k,l]F[k,l])(10)
Using this equation, we can calculate the value for each position on our final image, g[m,n]. For example, due to the periodic extension of the images, when circular convolution is applied we will observe a wrap-around effect.
g[0,0]=h[0,0]f[0,0]+h[1,0]f[N1,0]+h[0,1]f[0,N1]+h[1,1]f[N1,N1](11)
Where the last three terms in Equation 11 are a result of the wrap-around effect caused by the presence of the images copies located all around it.

Zero Padding

If the support of h is MxM and f is NxN, then we zero pad f and h to M+N1 x M+N1 (see Figure 3).
Figure 3
Figure 3 (zero_pad.png)

NOTE: 

Circular Convolution = Regular Convolution

Computing the 2D DFT

F[k,l]=
N1
m=0
 (
N1
n=0
 (f[m,n]()
2πkm
N
 
()
2πln
N
 
)
)
(12)
where in the above equation, 
N1
n=0
 (f[m,n]()
2πln
N
 
)
 is simply a 1D DFT over n. This means that we will take the 1D FFT of each row; if we have N rows, then it will requireNlogN operations per row. We can rewrite this as
F[k,l]=
N1
m=0
 (f[m,l]()
2πkm
N
 
)
(13)
where now we take the 1D FFT of each column, which means that if we have N columns, then it requires NlogN operations per column.

NOTE: 

Therefore the overall complexity of a 2D FFT is O(N2logN) where N2 equals the number of pixels in the image.

No comments:

Post a Comment