www.pudn.com > mean-and-median-filtering.rar > ave2.m, change:2012-12-20,size:960b


fp = fopen('E:\Desktop\实验\实验一\background.raw', 'r'); 
I = fread(fp, [320, 240], 'int16=>int16'); 
I = I'; 
subplot(3,3,1),imshow(I);title('原图');  %显示原图像 
x=mat2gray(I);  
subplot(3,3,2),imshow(x);title('灰度图');  %显示灰度图像 
n=3; 
a(1:n,1:n)=1; 
p=size(x); 
x1=double(x); 
x2=x1; 
for i=1:p(1)-n+1 
    for j=1:p(2)-n+1 
        c=x1(i:i+(n-1),j:j+(n-1)).*a; 
        m=max(max(c))+min(min(c)); 
        s=sum(sum(c)); 
        x2(i+(n-1)/2,j+(n-1)/2)=(s-m)/(n*n); 
    end 
end 
d=x2; 
subplot(3,3,3),imshow(d);title('处理后图'); %显示均值滤波后的图像 
N=x-d; 
subplot(3,3,4),imshow(N);title('噪声图'); %显示噪声图像 
subplot(3,3,5),bar(N);title('噪声直方图'); %显示噪声的统计直方图 
M=mean2(N); 
subplot(3,3,6),plot(M);title('噪声均值');  
V = var(double(N)); 
subplot(3,3,7),plot(V);title('噪声方差');  
S = skewness(double(N)); 
subplot(3,3,8),plot(S);title('噪声偏度');  
K= kurtosis(double(N)); 
subplot(3,3,9),plot(K);title('噪声峰度');