📄 spacefil.m
字号:
ft = imread('tire.tif');
f=imnoise(ft,'gaussian', 0,0.01);
ft=im2double(ft);
f=im2double(f);
h1=[1 2 1;2 4 2;1 2 1]./16;
h2=[0 1 0;1 6 1;0 1 0]./10;
f1=conv2(f,h1,'same'); %空域滤波
f2=conv2(f,h2,'same');
b=fftshift(fft2(ft));
b1=fftshift(fft2(f1));
b2=fftshift(fft2(f2));
nn=3;
h3=ones(nn)./(nn^2);
f3=conv2(f,h3,'same');
f4=medfilt2(f,[nn nn]);
h5=ones(7)./(7^2);
f5=conv2(f,h5,'same');
b3=fftshift(fft2(f3));
b4=fftshift(fft2(f4));
b5=fftshift(fft2(f5));
h6=[-1 -1 -1;-1 9 -1;-1 -1 -1]; %普通锐化滤波模板
f6=conv2(ft,h2,'same');
f7=f6+ft;
h8=fspecial('sobel');
f8=filter2(h8,ft)+ft; %水平边界sobel
f9=filter2(h8',ft)+ft; %垂直边界sobel
figure(1); %使用不同滤波模板效果比较
subplot(2,3,1);
imshow(ft);
xlabel('原始图像');
subplot(2,3,4);
imshow(b);
xlabel('原始图像频谱');
subplot(2,3,2);
imshow(f1);
xlabel('LPF1滤波后图像');
subplot(2,3,5);
imshow(b1);
xlabel('LPF1滤波后频谱');
subplot(2,3,3);
imshow(f2);
xlabel('LPF2滤波后图像');
subplot(2,3,6);
imshow(b2);
xlabel('LPF2滤波后频谱');
figure(2); %使用相同大小的邻域平均模板和中值滤波模板滤波,比较效果
subplot(2,3,1);
imshow(f3);
xlabel('3*3邻域平均模板');
subplot(2,3,2);
imshow(f4);
xlabel('3*3中值滤波模板');
subplot(2,3,3);
imshow(f5);
xlabel('7*7邻域平均模板');
subplot(2,3,4);
imshow(b3);
xlabel('3*3邻域平均模板滤波后频谱');
subplot(2,3,5);
imshow(b4);
xlabel('3*3中值滤波模板滤波后频谱');
subplot(2,3,6);
imshow(b5);
xlabel('7*7邻域平均模板滤波后频谱');
figure(3);%锐化滤波
subplot(2,2,1);
imshow(f6);
subplot(2,2,2);
imshow(f7);
subplot(2,2,3);
imshow(f8);
subplot(2,2,4);
imshow(f9);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -