文档详情

中值和均值滤波---matlab实现(Median and mean filter ---matlab implementation).doc

发布:2017-07-23约4.07千字共7页下载文档
文本预览下载声明
中值和均值滤波---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 hightn, widthn 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 End Not assigned elements from% of original value D=uint8 (x2); Self compiled median filter function. X is the image that needs filtering, and N is the template size (that is, n * n) Function d=mid_filter (x, n) [height, width]=size (x);% input images are p * q, and pn, qn X1=double (x); X2=x1; For i=1:height-n+1 For j=1:height-n+1 C=x1 (i:i+ (n-1), j:j+ (n-1));% out X1 from J (I); n row n column element, that is template (n * n) E=c (1::);% is the first row of the C matrix For u=2:n E=[e, C (U::));% turns the C matrix into a row matrix End Mm=median (E);%mm is the median X2 (i+ (n-1), /2, j+ (n-1) /2) =mm;%, the median of the template elements assigned to the center of the template End End Not assigned elements from% of original value D=uint8 (x2); % of the Gauss filter function, S is the need to filter the image, n is the mean, and K is the variance Function, d=gaussfilt (k, N, s) Img = double (s); N1=floor ((n+1) /2)% computed image center For i=1:n For j=1:n B (I, J) =exp (- (i-n1) ^2+ (j-n1) ^2) / (4*k)) / (4*pi*k); End End % generates Gauss sequence B. Img1=conv2 (Img, B,same);% Gauss convolution is performed with the generated Gauss sequence convolution D=uint8 (Img1); (5) MATLAB code of median filtering Global ImagenUmbral% defines a global variable, ImagenUmbral Global J%
显示全部
相似文档