# Connexions

You are here: Home » Content » 2D DFT

## Navigation

### Recently Viewed

This feature requires Javascript to be enabled.

# 2D DFT

Module by: Robert Nowak. E-mail the author

Summary: This module extends the ideas of the Discrete Fourier Transform (DFT) into two-dimensions, which is necessary for any image processing.

Note: You are viewing an old version of this document. The latest version is available here.

## 2D DFT

To perform image restoration (and many other useful image processing algorithms) in a computer, we need a Fourier Transform (FT) that is discrete and two-dimensional.

Fkl=Fuv| u=2πkN , v=2πlN F k l u 2 k N v 2 l N F u v
(1)
for k=0N1 k 0 N 1 and l=0N1 l 0 N 1 .
Fuv=mnfmne(ium)e(ivm) F u v m n f m n u m v m
(2)
Fkl=m=0N1n=0N1fmne(i)2πkmNe(i)2πlnN F k l m N 1 0 n N 1 0 f m n 2 k m N 2 l n N
(3)
where the above equation (Equation 3) has finite support for an NNxNN image.

### Inverse 2D DFT

As with our regular fourier transforms, the 2D DFT also has an inverse transform that allows us to reconstruct an image as a weighted combination of complex sinusoidal basis functions.

fmn=1N2k=0N1l=0N1Fklei2πkmNei2πlnN f m n 1 N 2 k N 1 0 l N 1 0 F k l 2 k m N 2 l n N
(4)

## 2D DFT and Convolution

The regular 2D convolution equation is

gmn=k=0N1l=0N1fklhmknl g m n k N 1 0 l N 1 0 f k l h m k n l
(5)

### Example 2

Below we go through the steps of convolving two two-dimensional arrays. You can think of ff as representing an image and hh represents a PSF, where hmn=0 h m n 0 for mn>1 m n 1 and mn<0 m n 0 . h=( h00h01 h10h11 ) h h 0 0 h 0 1 h 1 0 h 1 1 f=( f00f0N1 fN10fN1N1 ) f f 0 0 f 0 N 1 f N 1 0 f N 1 N 1 Step 1 (Flip hh):

hmn=( h11h100 h01h000 000 ) h m n h 1 1 h 1 0 0 h 0 1 h 0 0 0 0 0 0
(6)
Step 2 (Convolve):
g00=h00f00 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 hmn h m n and place it "on top" of fkl f k l , so that just the bottom-right element, h00 h 0 0 of hmn h m n overlaps with the top-left element, f00 f 0 0 , of fkl f k l . Then, to get the next element of our convolved image, we slide the flipped matrix, hmn h m n , over one element to the right and get the following result: g01=h00f01+h01f00 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, gmn g m n . Using the above method we define the general formula to find a particular element of gmn g m n as:
gmn=h00fmn+h01fmn1+h10fm1n+h11fm1n1 g m n h 0 0 f m n h 0 1 f m n 1 h 1 0 f m 1 n h 1 1 f m 1 n 1
(8)

### Circular Convolution

#### Exercise 1

What does HklFkl H k l F k l produce?

##### Solution

2D Circular Convolution

g ~ mn=IDFTHklFkl=circular convolution in 2D g ~ m n IDFT H k l F k l circular convolution in 2D
(9)

Due to periodic extension by DFT (Figure 2):

Based on the above solution, we will let

g ~ mn=IDFTHklFkl 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 ~ mn 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 ~ 00=h00f00+h10fN10+h01f0N1+h11fN1N1 g ~ 0 0 h 0 0 f 0 0 h 1 0 f N 1 0 h 0 1 f 0 N 1 h 1 1 f N 1 N 1
(11)
Where the last three terms in Equation 11 are a result of the wrap-around effect caused by the presense of the images copies located all around it.

### Zero Padding

If the support of hh is MMxMM and ff is NNxNN, then we zero pad ff and hh to M+N1 M N 1 x M+N1 M N 1 (see Figure 3).

#### note:

Circular Convolution = Regular Convolution

### Computing the 2D DFT

Fkl=m=0N1n=0N1fmne(i)2πkmNe(i)2πlnN F k l m N 1 0 n N 1 0 f m n 2 k m N 2 l n N
(12)
where in the above equation, n=0N1fmne(i)2πlnN n N 1 0 f m n 2 l n N is simply a 1D DFT over nn. This means that we will take the 1D FFT of each row; if we have NN rows, then it will require NlogN N N operations per row. We can rewrite this as
Fkl=m=0N1 f mle(i)2πkmN F k l m N 1 0 f m l 2 k m N
(13)
where now we take the 1D FFT of each column, which means that if we have NN columns, then it requires NlogN N N operations per column.

#### note:

Therefore the overall complexity of a 2D DFT is ON2logN O N 2 N where N2 N 2 equals the number of pixels in the image.

## Content actions

### Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks