I’m trying to find a Python library that works equivalently to MATLAB’s freqz2 for image processing, since scipy.signal.freqz only seems to work for 1-D arrays.
Advertisement
Answer
Found an amazing library for plotting the 3D surface of the 2-D FFT called plotly. I leave here the lines of code I used to emulate the same behaviour of freqz2 in Python:
JavaScript
x
10
10
1
import scipy.fft as fft
2
import plotly.graph_objects as go
3
4
N = 128
5
h = fspecial('unsharp', alpha=0.2)
6
H = fft.fftshift(fft.fft2(h, [N, N]))
7
f = fft.fftshift(fft.fftfreq(N))
8
fig = go.Figure(data=[go.Surface(x=f, y=f, z=np.abs(H))])
9
fig.show()
10
The 3D graphs is interactive, and the fspecial function in python I implemented it myself copying what MATLAB does (I can also post it if asked).
Which is the equivalent to MATLAB’s:
JavaScript
1
3
1
h = fspecial('unsharp');
2
freqz2(h);
3