📘
Frequency Domain Filtering
HardFrequency
Implement image filtering in the frequency domain using FFT.
Convolution in spatial domain = multiplication in frequency domain: F(f∗g)=F(f)⋅F(g)
Algorithm:
- Compute FFT of image: F=F(I)
- Create frequency domain filter H (same size as image)
- Multiply: G=F⋅H
- Inverse FFT: Ifiltered=F−1(G)
Common filters:
- Low-pass: Keep center (low frequencies) → blur
- High-pass: Keep edges (high frequencies) → sharpen
- Band-pass: Keep ring of frequencies
Example:
Input:
image = 64×64 image with edges filter_type = 'lowpass' cutoff = 0.1
Output:
Blurred image (edges smoothed)
Reasoning:
- FFT shifts image to frequency domain
- Create circular mask: 1 inside radius cutoff*max_freq, 0 outside
- Multiply FFT by mask (kills high frequencies)
- Inverse FFT → blurred image
Low cutoff = more blur (fewer frequencies retained)
Constraints:
- image: 2D grayscale array
- filter_type: 'lowpass', 'highpass', or 'bandpass'
- cutoff: Cutoff frequency (0-1, fraction of max frequency)
- Return: Filtered image (real part)
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.