Skip to content

FatineHic/Projet-OMI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 

Repository files navigation

🌍 Projet OMI β€” 2D Fourier Transform Applied to Image Processing

Frequency analysis of images using the 2D Fourier Transform: decomposition, filtering, and reconstruction of an Earth image through sinusoidal components.

Python Colab NumPy Matplotlib


πŸ“Œ Table of Contents


πŸ”¬ Overview

This project explores the 2D Fourier Transform (FT2D) and its applications to digital image processing. Through two progressive exercises, we analyze the decomposition of images into frequency components (sinusoids) and their reconstruction via the Inverse Fourier Transform (IFT).

The reference image used throughout the project is a photograph of the Earth (Earth.png), converted to grayscale for analysis.


🧠 Mathematical Concepts

Concept Description
2D Fourier Transform Decomposes an image into spatial frequencies
Inverse Fourier Transform Reconstructs the image from its frequency components
Sinusoidal grating 2D pattern whose amplitude varies sinusoidally
Amplitude Contrast between light and dark regions of the grating
Phase Lateral shift of the sinusoidal signal
Spatial frequency Number of cycles per unit distance in the image
Point pairs (FT2D) Symmetric points in Fourier space representing a sinusoid
fftshift Recenters the Fourier spectrum around low frequencies

πŸ“‚ Project Structure

projet-OMI-transformee-fourier/
β”‚
β”œβ”€β”€ notebooks/                      # Jupyter / Colab notebooks
β”‚   └── PROJET_OMI.ipynb            # Main notebook (Google Colab)
β”‚
β”œβ”€β”€ images/                         # Reference images
β”‚   └── Earth.png                   # Earth image used in the project
β”‚
β”œβ”€β”€ docs/                           # Additional documentation
β”‚   └── rapport.md                  # Supplementary notes and explanations
β”‚
β”œβ”€β”€ .gitignore                      # Files ignored by Git
β”œβ”€β”€ requirements.txt                # Python dependencies
└── README.md                       # Project documentation

πŸ““ Notebook Content

Exercise 1 β€” Interactive Sinusoidal Grating Visualization

Generates an interactive 2D sinusoidal grating with sliders to vary in real time:

  • Amplitude (0.1 to 50) β€” controls image contrast
  • Phase (-Ο€ to Ο€) β€” controls lateral shift of the grating

Key observations:

Parameter Effect
High amplitude (e.g., 50) Strong contrast, distinct black and white bands
Low amplitude (e.g., 0.1) Nearly all-black image, total loss of contrast
Increasing phase Grating shifts to the left
Decreasing phase Grating shifts to the right

Exercise 2 β€” Earth Image Analysis via FT2D

This exercise proceeds through five progressive steps:

Earth.png (RGB)
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 1: Load &       │──→ Convert to grayscale (np.mean on RGB)
β”‚ Convert Image        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 2: Compute      │──→ np.fft.fft2 + fftshift
β”‚ 2D Fourier Transform β”‚    Log-scale spectrum display
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 3: Identify     │──→ Sort frequencies by amplitude
β”‚ Point Pairs          β”‚    Identify dominant sinusoidal components
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 4: Iterative    │──→ IFT per pair, cumulative reconstruction
β”‚ IFT Reconstruction   β”‚    Observe progressive image formation
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 5: Frequency    │──→ Reconstruct using % of frequencies
β”‚ Percentage Filtering β”‚    Compare low vs high frequency content
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Step 1 β€” Image Loading & Conversion: Upload Earth.png into Google Colab, convert to grayscale using np.mean across RGB channels.

Step 2 β€” 2D Fourier Transform: Compute FT2D with np.fft.fft2, apply np.fft.fftshift to recenter the spectrum, and display in logarithmic scale (np.log(abs(...))) to visualize frequencies.

Step 3 β€” Point Pair Identification: Point pairs in the Fourier spectrum represent sinusoidal waves in the image. Frequencies are sorted by decreasing amplitude to identify the most significant components.

Step 4 β€” Iterative IFT Reconstruction: For each frequency pair, apply the Inverse Fourier Transform and accumulate sinusoids one by one to progressively reconstruct the image.

Step 5 β€” Frequency Percentage Filtering: Reconstruct the image using only a percentage of available frequencies:

Frequencies Used Result
100% Identical to the original image
10% lowest Still recognizable (low freq = global contours)
10% highest Grayish image (high freq = fine details, little useful info)

πŸ”¬ Results & Interpretations

Why Identify Point Pairs?

In the FT2D, each symmetric pair of points corresponds to a 2D sinusoidal wave in the image. By modulating the amplitude, phase, and frequency of these waves, then applying the IFT, we can:

  • Reconstruct the original image
  • Filter specific frequencies (compression, denoising)
  • Analyze the frequency structure of the image

High vs Low Frequencies

Frequencies Content Effect on Image
Low frequencies Global shapes, main contours Image recognizable even with few
High frequencies Fine details, textures, noise Weak contribution but needed for sharpness

🌍 Real-World Applications

The Fourier Transform is a fundamental mathematical tool used across many fields:

Domain Application
Signal Processing Filtering, spectral analysis
Image Processing JPEG compression, edge detection
Medicine MRI (Magnetic Resonance Imaging), CT scanners
Telecommunications Signal modulation, WiFi, 4G/5G
Astronomy Light and radio wave analysis
Quantum Computing Shor's algorithm for factorization

πŸ“ Key Formulas

Discrete 2D Fourier Transform

$$F(u,v) = \sum_{x=0}^{M-1} \sum_{y=0}^{N-1} f(x,y) \cdot e^{-2\pi i \left(\frac{ux}{M} + \frac{vy}{N}\right)}$$

Inverse Fourier Transform

$$f(x,y) = \frac{1}{MN} \sum_{u=0}^{M-1} \sum_{v=0}^{N-1} F(u,v) \cdot e^{2\pi i \left(\frac{ux}{M} + \frac{vy}{N}\right)}$$

2D Sinusoidal Grating

$$g(x,y) = A \cdot \sin\left(2\pi(f_x \cdot x + f_y \cdot y) + \phi\right)$$

Where:

  • A = amplitude
  • f_x, f_y = spatial frequencies in x and y
  • Ο† = phase

πŸš€ How to Run

Option 1 β€” Google Colab (recommended, no installation required)

  1. Open the notebook in Colab
  2. Click "Runtime" β†’ "Run all"
  3. When the files.upload() cell executes, upload the Earth.png file

Option 2 β€” Local (Jupyter Notebook)

Prerequisites: Python 3.8+, pip

# 1. Clone the repository
git clone https://github.com/YOUR_USERNAME/projet-OMI-transformee-fourier.git
cd projet-OMI-transformee-fourier

# 2. Install dependencies
pip install numpy matplotlib ipywidgets jupyter

# 3. Launch Jupyter
jupyter notebook notebooks/PROJET_OMI.ipynb

⚠️ For local execution, replace the from google.colab import files and files.upload() lines with:

image_filename = "../images/Earth.png"

πŸ“¦ Dependencies

Library Purpose
numpy Numerical computing, FFT (np.fft)
matplotlib Image display and plotting
ipywidgets Interactive sliders (amplitude, phase)
google.colab File upload (Colab only)

About

2D Fourier Transform applied to image processing: frequency decomposition, sinusoidal grating visualization, iterative reconstruction, and frequency filtering on an Earth image. Interactive Python notebook (Google Colab / Jupyter).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors