1、平滑滤波器
1.1线性平滑滤波器
1.1.1给图像加入椒盐噪声
I=imread('eight.tif');
J=imnoise(I,'salt & pepper',0.02);
subplot(121),imshow(I),title('原始图像');
subplot(122),imshow(J),title('加入椒盐噪声的图像');
效果图如下:
1.1.2对一个图像进行不同大小模板的均值滤波,并比较结果
I=imread('eight.tif');
J=imnoise(I,'salt & pepper',0.02);
subplot(221),imshow(J),title('噪声图像');
K1=filter2(fspecial('average',3),J)/255; %进行3*3模板的均值滤波
K2=filter2(fspecial('average',5),J)/255; %进行5*5模板的均值滤波
K3=filter2(fspecial('average',7),J)/255; %进行7*7模板的均值滤波
subplot(222),imshow(K1),title('3*3模板均值滤波');
subplot(223),imshow(K2),title('5*5模板均值滤波');
subplot(224),imshow(K3),title('7*7模板均值滤波');
效果图如下:
1.2非线性平滑滤波器
I=imread('eight.tif');
J=imnoise(I,'salt & pepper',0.02);
subplot(221),imshow(J),title('噪声图像');
K1=medfilt2(J,[3 3]); %进行3*3模板的中值滤波
K2=medfilt2(J,[5 5]); %进行5*5模板的中值滤波
K3=medfilt2(J,[7 7]); %进行7*7模板的中值滤波
subplot(222),imshow(K1),title('3*3模板中值滤波');
subplot(223),imshow(K2),title('5*5模板中值滤波');
subplot(224),imshow(K3),title('7*7模板中值滤波');
效果图如下:
2、平滑滤波器
2.1线性锐化滤波器
2.1.1对图像cameraman.tif进行线性高通滤波
I=imread('cameraman.tif');
h=fspecial('laplacian');
I2=filter2(h,I);
subplot(121),imshow(I),title('原始图像');
subplot(122),imshow(I2),title('滤波后图像');
效果图如下:
2.1.2用sobel算子、prewitt算子、log算子对图像滤波
I=imread('rice.png');
subplot(221),imshow(I),title('原始图像');
h1=fspecial('sobel');
I1=filter2(h1,I);
subplot(222),imshow(I1),title('sobel算子滤波');
h1=fspecial('prewitt');
I1=filter2(h1,I);
subplot(223),imshow(I1),title('prewitt算子滤波');
h1=fspecial('log');
I1=filter2(h1,I);
subplot(224),imshow(I1),title('log算子滤波');
效果图如下