帶通/帶阻濾波
顧名思義,圓環帶通過或不通過。
1.理想的帶通/帶阻濾波
理想帶阻濾波函數為:
W為帶寬。理想的帶通濾波器與此相反,1減去帶阻即可得到。
部分代碼:

# 定義函數,理想的帶阻/通濾波模板 def IdealBand(src, w, d0, ftype): template = np.zeros(src.shape, dtype=np.float32) # 構建濾波器 r, c = src.shape for i in np.arange(r): for j in np.arange(c): distance = np.sqrt((i - r / 2) ** 2 + (j - c / 2) ** 2) if (d0-w/2) <= distance <= (d0+w/2): template[i, j] = 0 else: template[i, j] = 1 if ftype == 'pass': template = 1 - template return template
2.Butterworth 帶通/帶阻濾波
n階Butterworth帶阻函數為:
帶通函數與此相反,1減帶阻即可。
部分代碼:

# 定義函數,巴特沃斯帶阻/通濾波模板 def ButterworthBand(src, w, d0, n, ftype): template = np.zeros(src.shape, dtype=np.float32) # 構建濾波器 r, c = src.shape for i in np.arange(r): for j in np.arange(c): distance = np.sqrt((i - r / 2) ** 2 + (j - c / 2) ** 2) template[i, j] = 1/(1+(distance*w/(distance**2 - d0**2))**(2*n)) if ftype == 'pass': template = 1 - template return template
3.Gaussian帶通/帶阻濾波
高斯帶阻濾波函數為:
帶通濾波函數與此相反,1減帶阻即可。
部分代碼:

# 定義函數,高斯帶阻/通濾波模板 def GaussianBand(src, w, d0, ftype): template = np.zeros(src.shape, dtype=np.float32) # 構建濾波器 r, c = src.shape for i in np.arange(r): for j in np.arange(c): distance = np.sqrt((i - r / 2) ** 2 + (j - c / 2) ** 2) temp = ((distance**2 - d0**2)/(distance*w+0.00000001))**2 template[i, j] = 1 - np.exp(-0.5 * temp) if ftype == 'pass': template = 1 - template return template