当前位置:文档之家› 实验三 图像的空间域滤波

实验三 图像的空间域滤波

1 A=imread('E:\pic\1.jpg');
I=rgb2gray(A);
subplot(1,3,1);
imshow(I);title('原图');
J=imnoise(I,'salt & pepper',0.05);
subplot(1,3,2);
imshow(J); title('加入椒盐噪声图象');
K=imnoise(I,'gaussian',0.01,0.02);
subplot(1,3,3);
imshow(K);title('加入高斯噪声图象');
2 A=imread('E:\pic\1.jpg');
I=rgb2gray(A);
Subplot(2,2,1);
Imshow(I);title('原图');
H=fspecial('motion',20,45);
MotionBlur=imfilter(I,H,'replicate');
Subplot(2,2,2);
Imshow(MotionBlur);title('MotionBlur image'); H=fspecial('disk',10);
blurred=imfilter(I,H,'replicate');
Subplot(2,2,3);
Imshow(blurred);title('Blurred image');
H=fspecial('unsharp',0.5);
Sharpened=imfilter(I,H,'replicate');
Subplot(2,2,4);
Imshow(Sharpened);title('sharpened image');
3 A=imread('E:\pic\1.jpg');
I=rgb2gray(A);
J=imnoise(I,'salt & pepper',0.05);
Subplot(2,2,1);imshow(J);title('加入椒盐噪声图象'); H=fspecial('motion',20,45);
MotionBlur=imfilter(J,H,'replicate');
Subplot(2,2,2);
Imshow(MotionBlur);title('replicate');
MotionBlur=imfilter(J,H,'symmetric');
Subplot(2,2,3);
Imshow(MotionBlur);title('symmetric');
MotionBlur=imfilter(J,H,'circular');
Subplot(2,2,4);
Imshow(MotionBlur);title('circular');
4
A=imread('E:\pic\1.jpg');
I=rgb2gray(A);
J=imnoise(I,'salt & pepper',0.05);
Aver=J;
H=fspecial('average');
for i =1:10
Aver=imfilter(Aver,H,'replicate');
end
Subplot(1,3,1);imshow(J);title('加有椒盐噪声的图象'); Subplot(1,3,2);imshow(Aver);title('10次均值滤波图象¨'); for i = 1:10
Aver=imfilter(Aver,H,'replicate');
end
Subplot(1,3,3);imshow(Aver);title('20次均值滤波图象');
5 A=imread('E:\pic\1.jpg');
I=rgb2gray(A);
J=imnoise(I,'salt & pepper',0.05);
Subplot(1,3,1);imshow(J);title('加有椒盐噪声的图象'); H=fspecial('average');
Aver=imfilter(J,H,'replicate');
Subplot(1,3,2);imshow(Aver);title('均值滤波后的图象'); Med=medfilt2(J);
Subplot(1,3,3);imshow(Med);title('中值滤波后的图象');
6 A=imread('E:\pic\1.jpg');
f=rgb2gray(A);
Subplot(1,2,1);imshow(f);title('原图');
w=(1/16)*[1 2 1;2 4 2;1 2 1];
f=im2double(f);
g=imfilter(f,w,'replicate');
Subplot(1,2,2);imshow(g);title('平滑滤波后的图象');
1 A=imread('E:\pic\1.jpg');
f=rgb2gray(A);
w8=[1 1 1;1 -8 1;1 1 1];
f=im2double(f);
g8=f-imfilter(f,w8,'replicate');
figure;
Subplot(1,2,1);imshow(f);title('原图');
Subplot(1,2,2);imshow(g8);title(' 用拉普拉斯算子滤波后的图象');
2
function w=genlaplacian(n)
w=ones(n);
x=ceil(n)/2;
w(x,x)=-1*(n*n-1);
3 A=imread('E:\pic\1.jpg');
f=rgb2gray(A);
w5=genlaplacian(5);
f=im2double(f);
g5=f-imfilter(f,w5,'replicate');
w9=genlaplacian(9);
g9=f-imfilter(f,w9,'replicate');
w15=genlaplacian(15);
g15=f-imfilter(f,w15,'replicate');
w25=genlaplacian(25);
g25=f-imfilter(f,w25,'replicate'); figure(1);imshow(f);title('原图');
figure(2);
Subplot(2,2,1);
Imshow(g5);title('5x5的锐化增强图象'); Subplot(2,2,2);
Imshow(g9);title('9x9的锐化增强图象'); Subplot(2,2,3);
Imshow(g15);title('15x15的锐化增强图象'); Subplot(2,2,4);
Imshow(g25);title('25x25的锐化增强图象');
4 A=imread('E:\pic\1.jpg'); B=rgb2gray(A);
I=double(B);
[Gx,Gy]=gradient(I);
G=sqrt(Gx.*Gx+Gy.*Gy);
J1=G;
Subplot(2,2,1);
Imshow(J1,map);
J2=I;
K=find(G>=7);
J2(K)=G(K);
Subplot(2,2,2);
Imshow(J2,map);
J3=I;
K=find(G>=7);
J3(K)=255;
Subplot(2,2,3);
Imshow(J3,map);
J4=I;
K=find(G<=7);
J4(K)=255;
Subplot(2,2,4);
Imshow(J4,map);
5 I=imread('E:\pic\1.jpg');
B=rgb2gray(I);
A=double(B);
domain=[ 1 1 1 1 1;
1 1 1 1 1;
1 1 -24 1 1;
1 1 1 1 1;
1 1 1 1 1 ];
K=conv2(A,domain,'same');
figure
Subplot(1,2,1);imshow(B);title('原图');
Subplot(1,2,2);imshow(K);title('锐化滤波后图象');。

相关主题