# Fourier Transform High Pass Circular Filter Intuition

The situation

I need to apply a high pass filter to an image. The approach I'm following uses Fourier transform to apply a circular filter which would eliminate low frequencies.

Say I have a frequency threshold below which frequencies should be filtered out, i.e. cut-off frequency.

The resulting spectogram shape of the FTT operation is the same than the image, hence I am not sure how to link the radius value of the mask to the cut-off frequency of interest.

The code

# read image
img = np.asarray(image)

# FFT
dft = cv2.dft(np.float32(img), flags=cv2.DFT_COMPLEX_OUTPUT)
dft_shift = np.fft.fftshift(dft)
magnitude_spectrum = 20 * np.log(cv2.magnitude(dft_shift[:,:,0], dft_shift[:,:,1]))

# center of image
rows, cols = img.shape
crow, ccol = int(rows/2), int(cols/2)

# create mask - circular filter
mask = np.ones((rows, cols, 2), np.uint8)
r=4.34
center = [crow, ccol]
x, y = np.ogrid[:rows, :cols]
mask_area = (x - center[0])**2 + (y - center[1])**2 <= r*r

# apply filter

f_ishift = np.fft.ifftshift(fshift)
img_back = cv2.idft(f_ishift)
img_back = cv2.magnitude(img_back[:,:,0], img_back[:,:,1])


The question

What is the intuition for the radius choice for the mask? I understand that a higher the radius will filter out more frequencies. However, how would I know that frequencies above the threshold are not being affected by the filter?

• Welcome to SE.SP! The choice of $r$ will depend on what frequencies you’re interested in. (I know, professor answer). Why are you aiming to high pass filter the image? What are you using the high pass filtered image for?
– Peter K.
Nov 10, 2021 at 12:24
• Hi @PeterK. the image is a x-ray image and the high pass filter is aiming to enhance the bone structure by removing the low frequencies. For this particular application, the filter is not generic but needs to filter above a specific value. My question is also related to this other post but with a different approach. Nov 10, 2021 at 13:15

This question, I believe, really requires an "it depends" answer.

I think you need to get some example images and work with them for different values of r.

I've adapted your code to do this and applied it to this image:

and then some of the different r values:

# Python code below

import cv2
import numpy as np
import matplotlib.pyplot as plt

img = np.asarray(image)

plt.figure(1)
plt.imshow(image)
plt.title('Original Image')

# FFT
dft = cv2.dft(np.float32(img), flags=cv2.DFT_COMPLEX_OUTPUT)
dft_shift = np.fft.fftshift(dft)
magnitude_spectrum = 20 * np.log(cv2.magnitude(dft_shift[:,:,0], dft_shift[:,:,1]))

# center of image
rows, cols = img.shape
crow, ccol = int(rows/2), int(cols/2)

figNo = 2
# create mask - circular filter
for r in np.arange(4.0,5.1,0.1):
mask = np.ones((rows, cols, 2), np.uint8)
center = [crow, ccol]
x, y = np.ogrid[:rows, :cols]
mask_area = (x - center[0])**2 + (y - center[1])**2 <= r*r

# apply filter

• Thanks for your reply @PeterK. As I see, this FFT methodology has no strict control over the frequency values to be deleted. Trial and error over the r parameter leads to uncertainty. Since the cut-off frequency is a requirement for this particular application, I guess other methodologies should be explored. Do you know any approach which would allow the required control over the threshold? Nov 10, 2021 at 15:16