v9.1.1
Menu

Low-Pass Filter (Frequency)

mediumFREEFourier TransformsSignal ProcessingCV: Image Processing

Implement an ideal low-pass filter in the frequency domain to remove high-frequency components from an image spectrum. This process involves modifying the frequency representation of an image to only retain frequency components below a specified cutoff frequency.

The concept of filtering in the frequency domain is rooted in the Fourier Transform, which decomposes a signal into its constituent frequencies. In image processing, this allows for the separation of low-frequency components, representing overall brightness and shape, from high-frequency components, representing details and noise. By applying a low-pass filter, we can reduce noise and blur an image.

To achieve this, we follow these steps:

  1. Obtain the frequency spectrum of the image.
  2. Identify the cutoff frequency, below which frequency components are retained.
  3. Set frequency components above the cutoff to zero.
F′(u,v)={F(u,v)if ∣u∣≤D0 and ∣v∣≤D00otherwiseF'(u, v) = \begin{cases} F(u, v) & \text{if } |u| \leq D_0 \text{ and } |v| \leq D_0 \\ 0 & \text{otherwise} \end{cases}

This technique is widely used in image denoising applications.

Example

Input
low_pass_filter([10, 5, 3, 1, 1, 3, 5], 2)
Output
[10, 5, 3, 0, 0, 3, 5]
Reasoning
  • The spectrum is in FFT order: index ii holds frequency min⁡(i,N−i)\min(i, N - i). For N=7N = 7 that is 0,1,2,3,3,2,10, 1, 2, 3, 3, 2, 1, so the low frequencies sit at both ends and the highest in the middle.
  • Keep index ii when i≤D0i \le D_0 or i≥N−D0i \ge N - D_0. With D0=2D_0 = 2 that keeps indices 0,1,20, 1, 2 and 5,65, 6.
  • Zero indices 33 and 44 (frequency 3>23 > 2): [10,5,3,1,1,3,5]→[10,5,3,0,0,3,5][10, 5, 3, 1, 1, 3, 5] \to [10, 5, 3, 0, 0, 3, 5].

Constraints

  • cutoff is the maximum frequency index to keep (0-indexed)
  • Return filtered magnitude spectrum

Learn this in

More from CV: Image Processing

solution.py

Test results

Sign in to run your code against the test cases.