Frequency domain image filtering helps us change images by focusing on patterns like edges or smooth areas. It works by changing the image into waves, filtering those waves, and then changing back to the image.
Frequency domain image filtering in Signal Processing
1. Convert image to frequency domain using Fourier Transform. 2. Create a filter mask to keep or remove certain frequencies. 3. Multiply the frequency image by the filter mask. 4. Convert the filtered image back to spatial domain using Inverse Fourier Transform.
The Fourier Transform changes the image from pixels to waves.
The filter mask controls which wave patterns to keep or remove.
# Convert image to frequency domain
F = fft2(image)# Create a low-pass filter mask mask = create_low_pass_mask(shape=image.shape, cutoff=30)
# Apply filter in frequency domain
F_filtered = F * mask# Convert back to image
image_filtered = ifft2(F_filtered).realThis code creates a noisy image, applies a low-pass frequency filter to remove noise, and shows the before and after images.
import numpy as np import matplotlib.pyplot as plt from numpy.fft import fft2, ifft2, fftshift, ifftshift # Create a simple image with noise np.random.seed(0) image = np.zeros((100, 100)) image[40:60, 40:60] = 1 # square in center image += 0.3 * np.random.randn(100, 100) # add noise # Step 1: Fourier transform F = fft2(image) F_shifted = fftshift(F) # center frequencies # Step 2: Create low-pass filter mask rows, cols = image.shape crow, ccol = rows // 2, cols // 2 mask = np.zeros_like(image) radius = 20 for i in range(rows): for j in range(cols): if (i - crow)**2 + (j - ccol)**2 < radius**2: mask[i, j] = 1 # Step 3: Apply mask F_filtered = F_shifted * mask # Step 4: Inverse Fourier transform F_ishift = ifftshift(F_filtered) image_filtered = ifft2(F_ishift).real # Plot original and filtered images plt.figure(figsize=(8,4)) plt.subplot(1,2,1) plt.title('Original Noisy Image') plt.imshow(image, cmap='gray') plt.axis('off') plt.subplot(1,2,2) plt.title('Filtered Image (Low-pass)') plt.imshow(image_filtered, cmap='gray') plt.axis('off') plt.show()
Frequency domain filtering works best on images with clear patterns or noise.
Choosing the right filter size (cutoff) controls how much detail is kept or removed.
Remember to shift frequencies to center before filtering and shift back before inverse transform.
Frequency domain filtering changes images by working with wave patterns instead of pixels.
It uses Fourier Transform to move between image and frequency views.
Filters in frequency domain can remove noise or enhance details effectively.
Practice
Solution
Step 1: Understand frequency domain filtering
Frequency domain filtering works by changing the image's frequency components, which represent patterns like edges or textures.Step 2: Identify the effect on image
By modifying these frequency components, we can remove noise or enhance details, not change colors or crop.Final Answer:
To remove or enhance specific patterns by modifying frequency components -> Option AQuick Check:
Frequency domain filtering = modify patterns [OK]
- Confusing frequency filtering with color editing
- Thinking it crops or resizes images
- Assuming it increases file size
Solution
Step 1: Identify Fourier transform function
To convert an image to frequency domain, we use the 2D Fourier transform, which is np.fft.fft2() in Python.Step 2: Check other options
np.mean() calculates average, np.sort() sorts values, np.resize() changes shape, none convert to frequency domain.Final Answer:
np.fft.fft2() -> Option BQuick Check:
Frequency domain = fft2() [OK]
- Using mean or sort instead of fft2
- Confusing resize with frequency transform
- Not knowing fft2 is 2D transform
filtered_img after inverse FFT?
import numpy as np img = np.random.rand(64, 64) freq = np.fft.fft2(img) mask = np.zeros((64, 64)) mask[30:34, 30:34] = 1 filtered_freq = freq * mask filtered_img = np.fft.ifft2(filtered_freq)
Solution
Step 1: Check input image shape
The original image has shape (64, 64), so the FFT and inverse FFT keep this shape.Step 2: Understand mask effect
The mask zeros out frequencies except a small block, but does not change overall shape.Final Answer:
(64, 64) -> Option DQuick Check:
Inverse FFT output shape = input shape [OK]
- Assuming mask changes output size
- Confusing mask slice size with output shape
- Expecting doubled or cropped shape
import numpy as np img = np.random.rand(32, 32) freq = np.fft.fft2(img) mask = np.ones((16, 16)) filtered_freq = freq * mask filtered_img = np.fft.ifft2(filtered_freq)
Solution
Step 1: Check shapes of freq and mask
freq has shape (32, 32), but mask is (16, 16). Multiplying arrays of different shapes causes error.Step 2: Confirm other code parts
fft2 and ifft2 are correct for 2D images; grayscale conversion is not mandatory here.Final Answer:
Mask size does not match frequency array size -> Option AQuick Check:
Mask shape must match freq shape [OK]
- Using smaller mask without resizing
- Confusing fft2 with fft
- Thinking grayscale needed for filtering
Solution
Step 1: Understand noise frequency location
High-frequency noise appears at edges of frequency domain; low frequencies are near center.Step 2: Choose mask to keep low frequencies
A circular mask centered at origin with radius 20 keeps low frequencies and blocks high frequencies, removing noise.Step 3: Evaluate other options
Random mask or passing only high frequencies will not remove noise effectively.Final Answer:
A circular mask centered at frequency origin with radius 20, passing low frequencies -> Option CQuick Check:
Low-pass mask = circular center pass [OK]
- Passing high frequencies instead of blocking
- Using random masks without pattern
- Zeroing low frequencies by mistake
Ready to prove it?
Pass the test and this pattern moves unknown
