PIXELBANKv9.1.0
Menu

Low-Pass Filter (Frequency)

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 input array represents frequency components at indices 00 to 66: [10,5,3,1,1,3,5][10, 5, 3, 1, 1, 3, 5], with a cutoff frequency of 22.
  • We keep components where ∣index−center∣≤2|\text{index} - \text{center}| \le 2; here the center is index 33, so indices 1,2,3,4,51, 2, 3, 4, 5 are within the cutoff and stay the same.
  • We zero out components outside that range (indices 00 and 66), giving [10,5,3,0,0,3,5][10, 5, 3, 0, 0, 3, 5].

Constraints:

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

Test Results

0/0
Run code to see test results.
Low-Pass Filter (Frequency) - Medium | PixelBank