均值滤波&阈值均值滤波

来源:互联网 发布:首席数据执行官 编辑:程序博客网 时间:2024/05/19 03:43
I=imread('imagefile.jpg');I=rgb2gray(I);%J=imnoise(I,'gaussian',0,0.005);       %高斯噪声J=imnoise(I,'salt & pepper');           %椒盐噪声subplot(2,2,1);imshow(I); title('原始图像'); subplot(2,2,2); imshow(J); title('加入高斯噪声之后的图像'); K=filter2(fspecial('average',9),J)/255; %模板尺寸为9的均值滤波subplot(2,2,3);imshow(K); title('均值滤波后'); n=5;a(1:n,1:n)=1;[h,w]=size(I);x1=double(I);x2=x1;for i=1:h-n+1    for j=1:w-n+1        c=x1(i:i+(n-1),j:j+(n-1)).*a;        s=sum(sum(c));        x2(i+(n-1)/2,j+(n-1)/2)=s/(n*n);    endendX=uint8(x1);subplot(2,2,4);imshow(X);title('阈值均值滤波后');

0 0
原创粉丝点击