clear,clc,close all
f=zeros(100,100);
f(20:30,18:42)=1;
f(70:80,18:42)=1;
f(31:79,25:35)=1;
f(20:30,53:87)=1;
f(31:80,65:75)=1;
figure(1)
imshow(f)
title('矩阵的显示')
F=fft2(f);
F2=1+log(abs(F));
figure(2)
imshow(F2,[-1 5],'notruesize')
title('傅立叶变换显示')
figure(3) %三维显示
subplot(221),imshow(f,'notruesize');
subplot(222),mesh(fftshift(abs(F)));
F2=fftshift(log(abs(F)));
subplot(223),imshow(F2,[-1 5],'notruesize');
colormap(jet);colorbar
F=fft2(f,256,256);
subplot(224),imshow(fftshift(log(abs(F))),[-1 5]);
colormap(jet);colorbar
figure(4) %把fft2输出的结果的零频率部分移到数轴的中间
subplot(221)
imshow(f)
title('矩阵的显示')
F2=1+log(abs(F));
subplot(222)
imshow(F2,[-1 5],'notruesize')
title('傅立叶变换显示')
subplot(223)
imshow(fftshift(F2),[-1 5],'notruesize')
title('傅立叶变换频移显示')
figure(5) %平移性:不影响傅立叶变换的幅值
subplot(221),imshow(f,'notruesize')
title('原图象')
F=fftshift(abs(fft2(f)));
subplot(222),imshow(F,[-1 5],'notruesize')
title('傅立叶变换频谱')
f0=zeros(100,100);
f0(20:30,30:54)=1;
f0(70:80,30:54)=1;
f0(31:79,37:47)=1;
f0(20:30,65:99)=1;
f0(31:80,77:87)=1;
subplot(223),imshow(f0,'notruesize')
title('x轴方向移动后的图象')
F=fftshift(abs(fft2(f0)));
subplot(224),imshow(F,[-1 5],'notruesize')
title('x方向移动后的傅立叶变换频谱')
figure(6)
subplot(121),imshow(fftshift(abs(F)),[-1 5])
subplot(122),imshow(fftshift(log(1+abs(F))),[-1 5]) %增强高频分量
colormap(jet),colorbar
figure(7)
subplot(121),mesh(fftshift(abs(F)),[-1 5]) %增强高频分量
subplot(122),mesh(fftshift(log(1+abs(F))),[-1 5])
colormap(jet),colorbar
figure(8) %图像旋转x度后,它的傅里叶谱会旋转相应的x度
f=zeros(100,100);
f(20:30,18:42)=1;
f(70:80,18:42)=1;
f(31:79,25:35)=1;
f(20:30,53:87)=1;
f(31:80,65:75)=1;
subplot(221),imshow(f,'notruesize')
title('原图象')
F=fftshift(abs(fft2(f)));
subplot(222),imshow(F,[-1 5],'notruesize')
title('傅立叶变换频谱')
f1=imrotate(f,45,'bilinear','crop');
subplot(223),imshow(f1,'notruesize')
title('图象正向旋转45^{0}')
F1=fftshift(abs(fft2(f1)));
subplot(224),imshow(F1,[-1 5],'notruesize')
title('图象旋转后的傅立叶变换频谱')
figure(9) %符合加法分配律
subplot(231),imshow(f,'notruesize')
title('原图象')
F=fftshift(abs(fft2(f)));
subplot(232),imshow(F,[-1 5],'notruesize')
title('傅立叶变换频谱')
f2=imrotate(f,45,'bilinear','crop');
subplot(233),imshow(f2,'notruesize')
title('图象正向旋转45^{0}')
F2=fftshift(abs(fft2(f2)));
subplot(234),imshow(F2,[-1 5],'notruesize')
title('图象旋转后的傅立叶变换频谱')
f3=imadd(f,f2);
subplot(235),imshow(f3,'notruesize')
title('图象相加')
F3=fftshift(abs(fft2(f3)));
subplot(236),imshow(F3,[-1 5],'notruesize')
title('相加后的傅立叶变换频谱')
figure(10) %比例性,反应空域采样频率增加,频域变化慢;空域采样频率减小,频域变化快
subplot(231),imshow(f)
j=fftshift(log(1+abs(fft2(f))));
subplot(232),mesh(j),colormap(jet)
f3=imresize(f,[500 500]);
subplot(233),imshow(f3)
j1=fftshift(log(1+abs(fft2(f3))));
subplot(234),mesh(j1),colormap(jet)
f4=imresize(f,[50 50]);
subplot(235),imshow(f4)
j2=fftshift(log(1+abs(fft2(f4))));
subplot(236),mesh(j2),colormap(jet)
figure(11) %比例性:af(x,y) <=> aF(u,v)
subplot(221),imshow(f,'notruesize');
F1=fft2(f);
F2=fft2(3*f); %F2=F3
F3=3*fft2(f);
subplot(222),mesh(fftshift(abs(F1)));
subplot(223),mesh(fftshift(abs(F2)));
subplot(224),mesh(fftshift(abs(F3)));