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}

Your function works on a 1D spectrum given in standard (unshifted) FFT order, so negative frequencies wrap around to the end of the list. Return a list of the same length with the removed components set to 00.

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
  • Inputs: spectrum is a 1D magnitude spectrum of length N=7N = 7 in standard (unshifted) FFT order, and cutoff is D0=2D_0 = 2, the highest frequency allowed through.
  • In that order, entry ii does not hold frequency ii. Past the middle the frequencies are negative and wrap around, so entry ii has ∣u∣=min⁡(i,N−i)|u| = \min(i, N - i). For N=7N = 7 that gives ∣u∣=0,1,2,3,3,2,1|u| = 0, 1, 2, 3, 3, 2, 1.
  • Apply F′(u)=F(u)F'(u) = F(u) when ∣u∣≤2|u| \le 2, else 00. Entries with ∣u∣∈{0,1,2}|u| \in \{0, 1, 2\} keep their values 10, 5, 3 at the front and 3, 5 at the back. Both entries with ∣u∣=3|u| = 3 (the 1, 1 in the middle) become 00.
  • Output: [10, 5, 3, 0, 0, 3, 5]. It still has length 7.
  • Notice that the low frequencies sit at both ends, so the zeroed band is in the middle. uu and −u-u always pass or fail together. With D0=0D_0 = 0, only the DC term at index 00 survives.

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.