數字圖像處理-頻域濾波-帶通/帶阻濾波

帶通/帶阻濾波

顧名思義,圓環帶經過或不經過。ide

1.理想的帶通/帶阻濾波

理想帶阻濾波函數爲:函數

W爲帶寬。理想的帶通濾波器與此相反,1減去帶阻便可獲得。spa

 部分代碼:3d

# 定義函數,理想的帶阻/通濾波模板
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
Ideal_band

2.Butterworth 帶通/帶阻濾波

n階Butterworth帶阻函數爲:code

帶通函數與此相反,1減帶阻便可。blog

部分代碼:模板

# 定義函數,巴特沃斯帶阻/通濾波模板
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
Butterworth_band

 3.Gaussian帶通/帶阻濾波

高斯帶阻濾波函數爲:class

帶通濾波函數與此相反,1減帶阻便可。bfc

 

部分代碼:float

# 定義函數,高斯帶阻/通濾波模板
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
Gaussian_band
相關文章
相關標籤/搜索