其他分享
首页 > 其他分享> > 【论文复现】中值滤波改进:Noise Adaptive Fuzzy Switching Median Filter(NAFSMF)

【论文复现】中值滤波改进:Noise Adaptive Fuzzy Switching Median Filter(NAFSMF)

作者:互联网

Noise Adaptive Fuzzy Switching Median Filter (NAFSM)

在这里插入图片描述

将图像 X X X的噪声像素置0,非噪声像素置1,保存到binary noise mask N N N
N ( i , j ) = { 0 , X ( i , j ) = L salt   or  L pepper  1 ,  otherwise  N(i, j)=\left\{\begin{array}{ll}0, & X(i, j)=L_{\text {salt }} \text { or } L_{\text {pepper }} \\1, & \text { otherwise }\end{array}\right. N(i,j)={0,1,​X(i,j)=Lsalt ​ or Lpepper ​ otherwise ​

定义方形滤波窗口, s s s初始化为1:
W 2 s + 1 ( i , j ) = { X ( i + m , j + n ) }  where  m , n ∈ ( − s , … , 0 , … , s ) \begin{aligned}W_{2 s+1}(i, j)=\{X(i+m, j+n)\} & \text { where } \\m, n \in(-s, \ldots, 0, \ldots, s)\end{aligned} W2s+1​(i,j)={X(i+m,j+n)}m,n∈(−s,…,0,…,s)​ where 

方形滤波窗口 W 2 s + 1 ( i , j ) W_{2s+1}(i,j) W2s+1​(i,j)内图像的非噪声像素数目为
G 2 s + 1 ( i , j ) = ∑ m , n ∈ ( − s , … , 0 , … , s ) N ( i + m , j + n ) G_{2 s+1}(i, j)=\sum_{m, n \in(-s, \ldots, 0, \ldots, s)} N(i+m, j+n) G2s+1​(i,j)=m,n∈(−s,…,0,…,s)∑​N(i+m,j+n)

如果 W 2 s + 1 ( i , j ) W_{2s+1}(i,j) W2s+1​(i,j)内有非噪声像素(即 G 2 s + 1 ( i , j ) ≥ 1 G_{2s+1}(i,j)\ge 1 G2s+1​(i,j)≥1),则用这些非噪声像素计算像素点 ( i , j ) (i,j) (i,j)的替代值:

M ( i , j ) = median ⁡ { X ( i + m , j + n ) }  with  N ( i + m , j + n ) = 1  .  M(i, j)=\operatorname{median}\{X(i+m, j+n)\} \text { with } N(i+m, j+n)=1 \text { . } M(i,j)=median{X(i+m,j+n)} with N(i+m,j+n)=1 . 

如果没有非噪声像素(即 G 2 s + 1 ( i , j ) < 1 G_{2s+1}(i,j)\lt 1 G2s+1​(i,j)<1),那么滤波窗口将扩大1个尺寸(即 s ← s + 1 s\leftarrow s+1 s←s+1)。直到 G 2 s + 1 ( i , j ) ≥ 1 G_{2s+1}(i,j)\ge 1 G2s+1​(i,j)≥1。
在这个过程如果 s = 3 s=3 s=3时,还是 G 2 s + 1 ( i , j ) < 1 G_{2s+1}(i,j)\lt 1 G2s+1​(i,j)<1,则设定窗口 W W W大小为 3 × 3 3\times 3 3×3来计算 M ( i , j ) M(i,j) M(i,j)
W 3 ( i , j ) = { X ( i + k , j + l ) }  where  k , l ∈ ( − 1 , 0 , 1 ) W_{3}(i, j)=\{X(i+k, j+l)\} \text { where } k, l \in(-1,0,1) W3​(i,j)={X(i+k,j+l)} where k,l∈(−1,0,1)

M ( i , j ) = median ⁡ { X ( i − 1 , j − 1 ) , X ( i , j − 1 ) , X ( i + 1 , j − 1 ) , X ( i − 1 , j ) }  when  s = 3  and  G 7 ( i , j ) = 0. \begin{aligned}M(i, j)=\operatorname{median}\{& X(i-1, j-1), X(i, j-1), \\&X(i+1, j-1), X(i-1, j)\} \\\text { when } s=& 3 \text { and } G_{7}(i, j)=0 .\end{aligned} M(i,j)=median{ when s=​X(i−1,j−1),X(i,j−1),X(i+1,j−1),X(i−1,j)}3 and G7​(i,j)=0.​

得出 M ( i , j ) M(i,j) M(i,j)后,再通过 3 × 3 3\times 3 3×3窗口来计算窗内其他像素与中心像素灰度值差的绝对值
d ( i + k , j + l ) = ∣ X ( i + k , j + l ) − X ( i , j ) ∣  with  ( i + k , j + l ) ≠ ( i , j ) . \begin{aligned}d(i+k, j+l)=|X(i+k, j+l)-X(i, j)| & \\\text { with }(i+k, j+l) \neq(i, j) .\end{aligned} d(i+k,j+l)=∣X(i+k,j+l)−X(i,j)∣ with (i+k,j+l)​=(i,j).​

然后,定义局部信息为 3 × 3 3\times 3 3×3滤波窗口内的最大绝对亮度差:
D ( i , j ) = max ⁡ { d ( i + k , j + l ) } D(i, j)=\max \{d(i+k, j+l)\} D(i,j)=max{d(i+k,j+l)}

使用最大值操作而不是最小值操作的原因如下图所示:

在这里插入图片描述
如图3(a)所示,取最大值操作能使得“噪声像素”被置为最大亮度值255,其他像素则将被置为动态范围内的其他值。这个结果也表达了局部信息,例如图像细节、边缘或无噪声像素,以供进一步处理。

相反的,如图3(b)所示,取最小值操作则无法区分“噪声像素”和“非噪声像素”。

模糊推理:定义模糊隶属函数为:
F ( i , j ) = { 0 , : D ( i , j ) < T 1 D ( i , j ) − T 1 T 2 − T 1 , : T 1 ≤ D ( i , j ) < T 2 1 , : D ( i , j ) ≥ T 2 F(i, j)=\left\{\begin{array}{lll}0, & : & D(i, j)\lt T_{1} \\\frac{D(i, j)-T_{1}}{T_{2}-T_{1}}, & : & T_{1} \leq D(i, j)\lt T_{2} \\1, & : & D(i, j) \geq T_{2}\end{array}\right. F(i,j)=⎩⎨⎧​0,T2​−T1​D(i,j)−T1​​,1,​:::​D(i,j)<T1​T1​≤D(i,j)<T2​D(i,j)≥T2​​
表示像素 ( i , j ) (i,j) (i,j)应该被修复的程度。

在这里插入图片描述
0 ∼ T 1 : 0\sim T_1: 0∼T1​:不修复

T 1 ∼ T 2 : T_1\sim T_2: T1​∼T2​: 部分修复

T 2 ∼ 255 : T_2\sim255: T2​∼255:全部修复

T 1 , T 2 T_1,T_2 T1​,T2​分别设为10和30。

替代噪声像素的修正值 Y ( i , j ) Y(i,j) Y(i,j)为被处理的像素 X ( i , j ) X(i,j) X(i,j)与中值像素值 M ( i , j ) M(i,j) M(i,j)的加权和:
Y ( i , j ) = [ 1 − F ( i , j ) ] ⋅ X ( i , j ) + F ( i , j ) ⋅ M ( i , j ) Y(i, j)=[1-F(i, j)] \cdot X(i, j)+F(i, j) \cdot M(i, j) Y(i,j)=[1−F(i,j)]⋅X(i,j)+F(i,j)⋅M(i,j)

# -*- coding:utf-8 -*-
'''
@paper:Noise Adaptive Fuzzy Switching Median Filter for Salt-and-Pepper Noise Reduction
'''
import numpy as np


# Adaptive Weighted Mean Filter
class Nafsmf(object):
    def __init__(self, h, s_max, T1, T2):
        self.h = h
        self.s_max = s_max
        self.T1 = T1
        self.T2 = T2

    def t_zero_pad_matrix(self, A, t):
        '''图像四周填充t层0'''
        m, n = np.shape(A)
        img_pad = np.zeros((m + t, n + t))
        img_pad[t:, t:] = A
        return img_pad

    def binary_noise_mask(self, A):
        '''噪声像素置0,其他像素置1'''
        B = np.zeros(np.shape(A))
        B[(A == 255) | (A == 0)] = 0
        B[(A != 255) & (A != 0)] = 1
        return B

    def k_approximate_matrix(self, img_pad, i, j, k, t):
        k_approximate_mat = img_pad[(i + t - k):(i + t + k + 1), (j + t - k):(j + t + k + 1)]
        return k_approximate_mat

    def fuzzy(self, D):
        if D < self.T1:
            F = 0
        elif D >= self.T2:
            F = 1
        else:
            F = (D - self.T1) / (self.T2 - self.T1)
        return F

    def process_image(self, X):
        m, n = np.shape(X)
        Y = X.copy()
        N = self.binary_noise_mask(X)
        img_pad = self.t_zero_pad_matrix(X, self.s_max)
        for i in range(m):
            for j in range(n):
                if N[i, j] == 0:
                    s = 1
                    while s <= self.s_max:
                        W = self.k_approximate_matrix(img_pad, i, j, k=s, t=self.s_max)
                        G = np.sum(self.binary_noise_mask(W))
                        if G >= 1:
                            M = np.median(W[self.binary_noise_mask(W).astype(bool)])
                        elif G == 0 and s == 3:
                            tem = self.k_approximate_matrix(img_pad, i, j, k=1, t=self.s_max)
                            tem = tem.flatten()
                            M = np.median(tem[0:4])
                        else:
                            s = s + 1
                            continue
                        tem = self.k_approximate_matrix(img_pad, i, j, k=1, t=self.s_max)
                        d = np.abs(tem - X[i, j])
                        D = np.max(d)
                        F = self.fuzzy(D)
                        Y[i, j] = (1 - F) * X[i, j] + F * M
                        break
        return Y


Noise levelNoise imageNAFSM
90%在这里插入图片描述在这里插入图片描述
95%在这里插入图片描述在这里插入图片描述
99%在这里插入图片描述在这里插入图片描述

标签:Noise,text,self,Median,像素,pad,max,np,NAFSMF
来源: https://blog.csdn.net/weixin_44378835/article/details/116853462