https://github.com/geeksloth/image-fourier-transform-example
A simple demo of image Fourier Transformation, invented from-scratch DFT and iDFT Python functions.
https://github.com/geeksloth/image-fourier-transform-example
fourier-transform image-processing
Last synced: about 1 year ago
JSON representation
A simple demo of image Fourier Transformation, invented from-scratch DFT and iDFT Python functions.
- Host: GitHub
- URL: https://github.com/geeksloth/image-fourier-transform-example
- Owner: geeksloth
- Created: 2024-02-11T08:29:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-23T12:29:55.000Z (over 2 years ago)
- Last Synced: 2025-01-30T14:48:37.332Z (over 1 year ago)
- Topics: fourier-transform, image-processing
- Language: Python
- Homepage:
- Size: 301 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Image Fourier Transform Example
A simple demo of Fourier image transformation by from-scratch DFT and iDFT functions.

## Theorem
The discrete two-dimensional Fourier transform of an image array is defined in series form as

I implemented from scratch in Python (without the normalization part) as follow:
```python
def DFT_2d(image):
#data = np.asarray(image)
data = image
M, N = image.shape # (img x, img y)
dft2d = np.zeros((M,N),dtype=complex)
for k in range(M):
for l in range(N):
sum_matrix = 0.0
for m in range(M):
for n in range(N):
e = cmath.exp(- 2j * np.pi * ((k * m) / M + (l * n) / N))
sum_matrix += data[m,n] * e
dft2d[k,l] = sum_matrix
return dft2d
```
inverse transform equation:

the implementation (and again, without the normalization part) is as follow:
```python
def iDFT_2d(image):
#data = np.asarray(image)
data = image
#M, N = image.size # (img x, img y)
M, N = image.shape
dft2d = np.zeros((M,N),dtype=complex)
for k in range(M):
for l in range(N):
sum_matrix = 0.0
for m in range(M):
for n in range(N):
e = cmath.exp(2j * np.pi * ((k * m) / M + (l * n) / N))
sum_matrix += data[m,n] * e
dft2d[k,l] = sum_matrix
return dft2d
```
These 4 steps are:
1. Showing the original spatial domain of the input image.
2. Transform it into the Frequency Domain by applying the Fourier Transform, then show the F-image.
3. Cutting some frequencies area, this might be more complex process a you desire, then show the filtered F-image.
4. Transfrom into the Saptial Domain and show the result.