数字图像处理旋转与幅度谱含MATLAB代码.docx
- 文档编号:10457779
- 上传时间:2023-02-11
- 格式:DOCX
- 页数:17
- 大小:322.77KB
数字图像处理旋转与幅度谱含MATLAB代码.docx
《数字图像处理旋转与幅度谱含MATLAB代码.docx》由会员分享,可在线阅读,更多相关《数字图像处理旋转与幅度谱含MATLAB代码.docx(17页珍藏版)》请在冰豆网上搜索。
数字图像处理旋转与幅度谱含MATLAB代码
数字图像处理实验一
15生医
一、实验内容
产生右图所示图像f1(m,n),其中图像大小为256×256,中间亮条为128×32,暗处=0,亮处=100。
对其进行FFT:
①同屏显示原图f1(m,n)和FFT(f1)的幅度谱图;
②若令f2(m,n)=(-1)^(m+n)f1(m,n),重复以上过程,比较二者幅度谱的异同,简述理由;
③若将f2(m,n)顺时针旋转90度得到f3(m,n),试显示FFT(f3)的幅度谱,并与FFT(f2)的幅度谱进行比较;
④若将f1(m,n)顺时针旋转90度得到f4(m,n),令f5(m,n)=f1(m,n)+f4(m,n),试显示FFT(f5)的幅度谱,指出其与FFT(f1)和FFT(f4)的关系;
⑤若令f6(m,n)=f2(m,n)+f3(m,n),试显示FFT(f6)的幅度谱,并指出其与FFT(f2)和FFT(f3)的关系,比较FFT(f6)和FFT(f5)的幅度谱。
二、运行环境
MATLABR2014a
三、运行结果及分析
1.同屏显示原图f1(m,n)和FFT(f1)的幅度谱图:
2.令f2(m,n)=(-1)^(m+n)f1(m,n),对其进行FFT,比较f2与f1幅度谱的异同,简述理由:
异同及理由:
①空域:
f2由于前边乘了系数(-1)^(m+n),导致灰度值有正有负,而在MATLAB的imshow函数中默认把负值变为0(有些情况是取反),所以形成了如左图所示的黑白花纹。
②频域:
FFT
(2)为FFT
(1)中心化后的图像。
空域进行乘以(-1)^(m+n)的操作,即相当于频域里的位移,实现频谱的中心化。
3.将f2(m,n)顺时针旋转90度得到f3(m,n),试显示FFT(f3)的幅度谱,并与FFT(f2)的幅度谱进行比较:
比较:
空域图像旋转90度后,频域幅度谱也旋转90度。
4.将f1(m,n)顺时针旋转90度得到f4(m,n),令f5(m,n)=f1(m,n)+f4(m,n),试显示FFT(f5)的幅度谱,指出其与FFT(f1)
和FFT(f4)的关系:
关系:
空域里原图与其旋转90度后的图像进行叠加,在频域里也体现为相应幅度谱的叠加,即FFT(f5)=FFT(f1)+FFT(f4)。
5.令f6(m,n)=f2(m,n)+f3(m,n),试显示FFT(f6)的幅度谱,并指出其与FFT(f2)和FFT(f3)的关系,比较FFT(f6)和FFT(f5)的幅度谱:
关系:
空域里原图与其旋转90度后的图像进行叠加,在频域里也体现为相应幅度谱的叠加,即FFT(f6)=FFT(f2)+FFT(f3)。
比较:
FFT(6)为FFT(5)中心化后的图像。
四、心得体会
通过MATLAB编程更加熟练了课上的知识点,比如空域旋转频域也旋转,空域叠加频域也满足叠加关系。
同时,对MATLAB实现傅里叶变换及其显示的机理也有所掌握,比如后边附的程序中会提到的Note1-Note5的思考。
Note1:
复数取绝对值后才可以二维图示;Note2:
为什么这里要划分255个灰度级?
为什么是在频域里操作?
(可能的解释:
用灰度来表示值的大小,越白值越大);Note3:
空域进行此操作频域位移;Note4:
双线性插值法;Note5:
旋转坐标计算式:
256*(1+0)
五、具体程序
(复制于matlabnotebook)
%产生亮块图像0暗100亮
f1=zeros(256,256);
form=64:
192
forn=112:
144
f1(m,n)=100;
end
end
figure
(1);
subplot(1,2,1);
imshow(f1);
xlabel('(a)亮块图像f1(m,n)');
axison;
%求f1(m,n)的傅里叶变换
FFT_f1=fft2(f1);
%求f1(m,n)的频谱
FFT_f1=abs(FFT_f1);%Note1:
复数取绝对值后才可以二维图示
tmax=FFT_f1(1,1);
tmin=FFT_f1(1,1);
form=1:
256
forn=1:
256
iftmax tmax=FFT_f1(m,n); end iftmin>FFT_f1(m,n) tmin=FFT_f1(m,n); end end end delta=tmax-tmin; form=1: 256 forn=1: 256 FFT_f1(m,n)=255*(FFT_f1(m,n)-tmin)/delta; end end %Note2: 为什么这里要划分255个灰度级? 为什么是在频域里操作? (可能的解释: 用灰度来表示值的大小,越白值越大) subplot(1,2,2); imshow(FFT_f1); xlabel('(b)f1(m,n)的频谱'); axison; %频谱中心化 f2=f1; form=1: 256 forn=1: 256 f2(m,n)=(-1)^(m+n)*f1(m,n);%Note3: 空域进行此操作频域位移 end end FFT_f2=fft2(f2); FFT_f2=abs(FFT_f2); tmax=FFT_f2(1,1); tmin=FFT_f2(1,1); form=1: 256 forn=1: 256 iftmax tmax=FFT_f2(m,n); end iftmin>FFT_f2(m,m) tmin=FFT_f2(m,n); end end end delta=tmax-tmin; form=1: 256 forn=1: 256 FFT_f2(m,n)=255*(FFT_f2(m,n)-tmin)/delta; end end figure (2) subplot(1,2,1); imshow(f2); xlabel('(a)亮块图像f2(m,n)'); axison; subplot(1,2,2); imshow(FFT_f2); xlabel('(b)f2(m,n)的频谱'); axison; %f2(m,n)旋转90°生成f3(m,n) f3=imrotate(f2,-90,'bilinear');%Note4: 双线性插值法 FFT_f3=fft2(f3); FFT_f3=abs(FFT_f3); tmax=FFT_f3(1,1); tmin=FFT_f3(1,1); form=1: 256 forn=1: 256%Note5: 旋转坐标计算式: 256*(1+0) iftmax tmax=FFT_f3(m,n); end iftmin>FFT_f3(m,n) tmin=FFT_f3(m,n); end end end delta=tmax-tmin; form=1: 256 forn=1: 256 FFT_f3(m,n)=255*(FFT_f3(m,n)-tmin)/delta; end end figure(3); subplot(1,2,1); imshow(FFT_f2); xlabel('(a)FFT(f2)幅度谱'); axison; subplot(1,2,2); imshow(FFT_f3); xlabel('(b)FFT(f3)幅度谱'); axison; %旋转90°与原图叠加的空域频域比较 f4=imrotate(f1,-90,'bilinear'); f5=f1+f4; FFT_f4=fft2(f4); FFT_f4=abs(FFT_f4); tmax=FFT_f4(1,1); tmin=FFT_f4(1,1); form=1: 256 forn=1: 256 iftmax tmax=FFT_f4(m,n); end iftmin>FFT_f4(m,n) tmin=FFT_f4(m,n); end end end delta=tmax-tmin; form=1: 256 forn=1: 256 FFT_f4(m,n)=255*(FFT_f4(m,n)-tmin)/delta; end end FFT_f5=fft2(f5); FFT_f5=abs(FFT_f5); tmax=FFT_f5(1,1); tmin=FFT_f5(1,1); form=1: 256 forn=1: 256 iftmax tmax=FFT_f5(m,n); end iftmin>FFT_f5(m,n) tmin=FFT_f5(m,n); end end end delta=tmax-tmin; form=1: 256 forn=1: 256 FFT_f5(m,n)=255*(FFT_f5(m,n)-tmin)/delta; end end figure(4); subplot(3,2,1); imshow(f1); xlabel('(a)亮块图像f1(m,n)'); axison; subplot(3,2,2); imshow(FFT_f1); xlabel('(b)FFT(f1)幅度谱'); axison; subplot(3,2,3); imshow(f4); xlabel('(c)旋转图像f4(m,n)'); axison; subplot(3,2,4); imshow(FFT_f4); xlabel('(d)FFT(f4)幅度谱'); axison; subplot(3,2,5); imshow(f5); xlabel('(e)叠加图像f5(m,n)'); axison; subplot(3,2,6); imshow(FFT_f5); xlabel('(f)FFT(f5)幅度谱'); axison; %旋转90°与原图叠加的空域频域比较(二者均中心化) f6=f2+f3; FFT_f6=fft2(f6); FFT_f6=abs(FFT_f6); tmax=FFT_f6(1,1); tmin=FFT_f6(1,1); form=1: 256 forn=1: 256 iftmax tmax=FFT_f6(m,n); end iftmin>FFT_f6(m,n) tmin=FFT_f6(m,n); end end end delta=tmax-tmin; form=1: 256 forn=1: 256 FFT_f6(m,n)=255*(FFT_f6(m,n)-tmin)/delta; end end figure(5); subplot(3,2,1); imshow(f2); xlabel('(a)亮块图像f2(m,n)'); axison; subplot(3,2,2); imshow(FFT_f2); xlabel('(b)FFT(f2)幅度谱'); axison; subplot(3,2,3); imshow(f3); xlabel('(c)旋转图像f3(m,n)'); axison; subplot(3,2,4); imshow(FFT_f3); xlabel('(d)FFT(f3)幅度谱'); axison; subplot(3,2,5); imshow(f6); xlabel('(e)叠加图像f6(m,n)'); axison; subplot(3,2,6); imshow(FFT_f6); xlabel('(f)FFT(f6)幅度谱'); axison; figure(6); subplot(1,2,1); imshow(FFT_f5); xlabel('(a)FFT(f5)幅度谱'); axison; subplot(1,2,2); imshow(FFT_f6); xlabel('(b)FFT(f6)幅度谱');
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数字图像 处理 旋转 幅度 MATLAB 代码