2

The situation

I am trying to apply a high pass filter to a black&white image to enhance the texture by keeping the high frequencies. The goal is to filter from a specific frequency value obtained from the outcome of applying signal.welch() from scipy library. Up to this point, the code I have tried works good enough that I could plot the frequency-PSD graph and visually identify the frequency value of interest.

The code

The following code takes a 2D numpy array image and calculates the PSD for each horizontal line derivative, and obtains the mean to plot the periodogram.

def plot_periodogram(image):
 
 # Calculate increment for each line (derivative)
 img_incr = np.diff(image[:,:,0], axis=1)
 
 # Calculate PSD for each increment of the line
 f_tot, Pxx_tot = [], []
 for i in range(image.shape[0]):
 f, Pxx = signal.welch(img_incr[i,:])
 f_tot.append(f)
 Pxx_tot.append(Pxx)
 
 # Calculate mean of the increments of the line
 f_mean = np.mean(f_tot, axis=0)
 Pxx_mean = np.mean(Pxx_tot, axis=0)
 
 # log-log plot of frequency-PSD
 plt.loglog(f_mean, Pxx_mean)
 plt.xlabel('frequency [Hz]')
 plt.ylabel('PSD')
 plt.show()
 
 return f_mean, Pxx_mean, f_tot, Pxx_tot
f_mean, Pxx_mean, f_tot, Pxx_tot = plot_periodogram(img)

In this sample image (ignore red lines), the peak around f=0.23 helps to identify the **cut-off frequency ** (i.e. fc=0.23) which should be used to apply the filter.

The Question

Having the cut-off frequency, how should I proceed to filter the image in frequency domain and return to spatial domain?

My best guess is that I should turn to 0 all Pxx_tot elements whose corresponding f_tot are lower than fc. If this approach is correct, I still don't know how to go back to spatial domain after filtering the image.

asked Nov 8, 2021 at 16:29
1

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.