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


帶通/帶阻濾波

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

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
Ideal_band

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
Butterworth_band

 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
Gaussian_band

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM