MATLAB实现各种常用滤波的代码
(2011-01-21 09:25:35)
标签:
傅立叶变换低通滤波器灰度级图像matlab |
分类: 学习资料 |
clear all;clc;
�T变换
I=imread('cameraman.tif');
A1=fft2(I);
A2=ifft2(A1);
A3=uint8(A2);
figure,subplot(221),imshow(I);
subplot(222);imshow(A3);
�T变换
I=imread('cameraman.tif');
figure,subplot(223);imshow(I);
I=im2double(I);
T=dctmtx(8);
B=blkproc(I,[8 8], 'P1*x*P2',T,T');
Mask=[1 1 1 1 0 0 0 0
B2=blkproc(B,[8
8],'P1.*x',Mask);
I2=blkproc(B2,[8 8], 'P1*x*P2',T',T);
subplot(224);imshow(I2);
%直方图均衡
I=imread('pout.tif');
figure,subplot(321);imshow(I);
subplot(322);imhist(I);
[J,T]=histeq(I,64);
subplot(323);imshow(J);
subplot(324);imhist(J);
J=histeq(I,32);
subplot(325);imshow(J);
subplot(326);imhist(J);
figure,plot((0:255)/255,T); % 转移函数的变换曲线
%灰度拉伸
I=imread('pout.tif');
figure,subplot(221);imshow(I);
subplot(222);imhist(I);
[X,map]=imread('pout.tif');
Y=imadjust(X,[0.1 0.99],[0 1]);
subplot(223);imshow(Y,map);
subplot(224);imhist(Y);
% 图像空间域处理
[I,map] = imread('pout.tif');
J1=imnoise(I,'gaussian',0,0.02);
% 叠加均值为0,方差为0.02的高斯噪声,可以用localvar代替
%J2=imnoise(I,'salt & pepper',0.04); %
叠加密度为0.04的椒盐噪声
M4=[0 1 0; 1 0 1; 0 1 0];
M4=M4/4;
I_filter1=filter2(M4,J1);
figure,subplot(321);imshow(I);
subplot(322);imshow(J1);
subplot(323);imshow(I_filter1,map);
M8=[1 1 1; 1 0 1; 1 1
1];
M8=M8/8;
I_filter2=filter2(M8,J1);
subplot(324);imshow(I_filter2,map);
K1 = medfilt2(J1,[3,3]);
subplot(325);imshow(K1);
K2=medfilt2(J2,[7 7]);
subplot(326);imshow(K2);
%频域处理
I=imread('pout.tif');
figure,subplot(221);imshow(I);
J1=imnoise(I,'salt &
pepper');
subplot(222);imshow(J1);
f=double(J1);
g=fft2(f);
g=fftshift(g);
[M,N]=size(g);
nn=2;
d0=50;
m=fix(M/2); n=fix(N/2);
for i=1:M
end
result=ifftshift(result);
J2=ifft2(result);
J3=uint8(real(J2));
subplot(223);imshow(J3);
[I,map]=imread('pout.tif');
figure,subplot(221);imshow(I,map);
H2=[-1 -1 -1;-1 -9 -1;-1 -1 -1];
J1=filter2(H2,I);
subplot(222);imshow(J1,map);
I=imread('pout.tif');
figure,subplot(221);imshow(I);
f=double(I);
g=fft2(f);
g=fftshift(g);
[M,N]=size(g);
nn=2;
d0=5;
m=fix(M/2);
n=fix(N/2);
for i=1:M
result(i,j)=h*g(i,j);
end
end
result=ifftshift(result);
J2=ifft2(result);
J3=uint8(real(J2));
subplot(222);imshow(J3);
end
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/guomei/archive/2008/05/09/2425568.aspx