NOTE: The fft2 result has to be shifted to ensure the lower frequency components are placed around the center of the matrix. Otherwise, they exist at four corners, which is tricky to handle.
Ideal 理想低通滤波器
where is the distance to the matrix center for each pixel, and is the cutoff frequency. With a greater , more high frequencies are retained and therefore less information lost.
Gaussian 高斯滤波器
Butterworth 布特沃斯滤波器
where is the order of the Butterworth filter.
With a higher , the filter is sharper, which approachs more to the ideal filter; otherwise it approaches to the gaussian filter.
Usage Example
1 2 3 4 5 6 7 8 9 10 11 12
import torch from preprocess import ideal_bandpass, butterworth, gaussian
cutoff = 20# D0
img_tensor = torch.randn((1, 3, 224, 224)) # change it to your image tensor
img_lowpass = ideal_bandpass(img_tensor, cutoff) # lowpass=False for high-pass.
img_lowpass = butterworth(img_tensor, cutoff, 10)
img_lowpass = gaussian(img_tensor, cutoff)
Reference
Gonzalez R C. Digital image processing[M]. Pearson education india, 2009.