Gaussian Blur First Order kernel function:
Gaussian function Second order kernel function:
def Calc (self,x,y=0): if self.level==1: return 1/((2*math.pi ) **0.5*self.sigema) *math.exp (-(x**2/2/(self.sigema**2))) elif self.level==2: return 1/(2*math.pi*self.sigema*self.sigema) *math.exp (-(x**2+y**2)/2/self.sigema/self.sigema)
Σ as standard deviation
Define a fuzzy radius to obtain the required kernel functions through the above formula
such as Radius r=1, σ=2
First order time is x=[-1,0,1], generating nucleus for [0.176033,0.199471,0.176033]/data.sum ()
And [0.319168,0.361664,0.319168] as the following computed convolution and
The image of the edge data is blurred and symmetric, and then the data is computed by convolution to obtain the filtered data.
Fuzzy algorithm:
defVerticalflipping (Self,data):#Flip Vertically ifData.shape[0]<=1: returnData NewArray=Np.zeros (Data.shape) forIinchRange (Data.shape[0]): Newarray[i]=data[-i-1] returnNewArraydefHorizontalflipping (Self,data):#Flip Horizontally ifData.shape[1]<=1: returnData NewArray=Np.zeros (Data.shape) forIinchRange (data.shape[1]): Newarray[:,i]=data[:,-i-1] returnNewArraydefFuzzy (Self,data):#image edge Blur algorithm: Image BlurData=Np.array (data)ifself.level==2: Data=Np.row_stack (self. Verticalflipping (Data[:self.radius]), data)=np.row_stack (data,self. Verticalflipping (data[-1:]))) Data=Np.column_stack (self. Horizontalflipping (Data[:,:self.radius]), data)=np.column_stack (data,self. Horizontalflipping (data[:,-Self.radius:]) )) returnData
Filtering method
#Filter Function deffilter (self, data, template): Arr=self.fuzzy (data) Height=arr.shape[0] Width=arr.shape[1] NewData=Np.zeros (height, width)ifSelf.level==1: forIinchRange (Arr.shape[0]): forJinchRange (self.radius,arr.shape[1]-Self.radius): t=arr[i, j-self.radius:j+self.radius+1] a=np.multiply (t,template) newdata[i,j]=a.sum ()returnnewdata[:,self.radius:-Self.radius]elifself.level==2: forIinchRange (Self.radius, height-Self.radius): forJinchRange (Self.radius, width-Self.radius): t=arr[i-self.radius:i+self.radius+1, j-self.radius:j+self.radius+1] a=np.multiply (t, template) Newdata[i, j]=a.sum ()#newimage = Image.fromarray (newdata) returnNewdata[self.radius:-self.radius,self.radius:-self.radius]
Gaussian fuzzy filtering for Python one-and two-bit data