中值和均值滤波---matlab实现(Median and mean filter ---matlab implementation)
中值和均值滤波---matlab实现(Median and mean filter ---matlab implementation)
%x is the image that needs filtering, and N is the template size (that is, n * n)
Function d=avg_filter (x, n)
A (1:n, 1:n) =1;%a, that is, n * n template, the element is 1
[height, width]=size (x);% input image is hightxwidth, and hight>n, width>n
X1=double (x);
X2=x1;
For i=1:hight-n+1
For j=1:width-n+1
C=x1 (i:i+ (n-1), j:j+ (n-1)),.*a;%, take out X1 from J (I), start n row, n column element, and template multiply
S=sum (sum (c));% the sum of the elements in the C matrix
X2 (i+ (n-1), /2, j+ (n-1), /2) =s/ (n*n);% will assign the mean of the elements after the template operation to the central location of the template
End