图像的傅里叶变换的频谱特征 三(平移,旋转,相位的重要性)

图像傅里叶变换的频谱特征 三

 

6,平移和旋转

图像的平移并不会影响图像的频谱,同时,图像的相位会随着图像的旋转而旋转。

 

Part I 平移和旋转对频谱的影响

下面我用矩形的频谱图来说明图像中矩形的平移并不会对频谱有丝毫的影响。

 

Matlab代码:

 


 
 
  1. clear all
  2. close all
  3. %% Author: J27
  4. % Jesus love you!
  5. Isize = 512;
  6. Rwidth = 50;
  7. Rlength = 3*Rwidth;
  8. Irect = zeros(Isize);
  9. Irect(floor((Isize - Rlength)/ 2) + 1:floor((Isize - Rlength)/ 2) + Rlength,...
  10. (floor(Isize - Rwidth)/ 2) + 1:floor((Isize - Rwidth)/ 2) + Rwidth) = 1;
  11. subplot( 3, 1, 1)
  12. imshowpair(Irect,log(abs(fftshift(fft2(Irect)))+ 1), 'montage')
  13. Irect = zeros(Isize);
  14. Irect(floor((Isize - Rlength)/ 2) + 150 + 1:floor((Isize - Rlength)/ 2) + 150 + Rlength,...
  15. (floor(Isize - Rwidth)/ 2) + 1 + 200:floor((Isize - Rwidth)/ 2) + Rwidth + 200) = 1;
  16. subplot( 3, 1, 2)
  17. imshowpair(Irect,log(abs(fftshift(fft2(Irect)))+ 1), 'montage')
  18. Irect = zeros(Isize);
  19. Irect(floor((Isize - Rlength)/ 2) + 1:floor((Isize - Rlength)/ 2) + Rlength,...
  20. (floor(Isize - Rwidth)/ 2) + 1 - 80:floor((Isize - Rwidth)/ 2) + Rwidth - 80) = 1;
  21. subplot( 3, 1, 3)
  22. imshowpair(Irect,log(abs(fftshift(fft2(Irect)))+ 1), 'montage')

 

再比如下面这个例子:

 

再来看看频谱随着矩形的旋转而旋转相同的角度。

Matlab代码:


 
 
  1. Isize = 512;
  2. Rwidth = 50;
  3. Rlength = 3*Rwidth;
  4. Irect = zeros(Isize);
  5. Irect(floor((Isize - Rlength)/ 2) + 1:floor((Isize - Rlength)/ 2) + Rlength,...
  6. (floor(Isize - Rwidth)/ 2) + 1:floor((Isize - Rwidth)/ 2) + Rwidth) = 1;
  7. Irot = imrotate(Irect, 15, 'crop', 'bilinear');
  8. subplot( 3, 1, 1)
  9. imshowpair(Irot,log(abs(fftshift(fft2(Irot)))+ 1), 'montage')
  10. Irect = zeros(Isize);
  11. Irect(floor((Isize - Rlength)/ 2) + 1:floor((Isize - Rlength)/ 2) + Rlength,...
  12. (floor(Isize - Rwidth)/ 2) + 1:floor((Isize - Rwidth)/ 2) + Rwidth) = 1;
  13. Irot = imrotate(Irect, 45, 'crop', 'bilinear');
  14. subplot( 3, 1, 2)
  15. imshowpair(Irot,log(abs(fftshift(fft2(Irot)))+ 1), 'montage')
  16. Irect = zeros(Isize);
  17. Irect(floor((Isize - Rlength)/ 2) + 1:floor((Isize - Rlength)/ 2) + Rlength,...
  18. (floor(Isize - Rwidth)/ 2) + 1:floor((Isize - Rwidth)/ 2) + Rwidth) = 1;
  19. Irot = imrotate(Irect, 90, 'crop', 'bilinear');
  20. subplot( 3, 1, 3)
  21. imshowpair(Irot,log(abs(fftshift(fft2(Irot)))+ 1), 'montage')

 

 

Part II 平移和旋转对相位的影响

     先用一个简单的例子来说明图像相位的作用(所用图像为cameraman),在图像的频域分析和滤波中,相位是常常被忽略的。虽然相位分量的贡献很不直观,但是它恰恰很重要。相位是频谱中各正弦分量关于原点的位移的度量。

上面的小实验充分说明了,看似无用的,且常常被忽略的相位,在DFT的频域中起到了多么重要的作用(注意区分实部和虚部(直角坐标系)VS 频谱和相位(极坐标系)!)。

Matlab代码:


 
 
  1. close all;
  2. clear all;
  3. I = im2double(imread( 'cameraman.tif'));
  4. DFT = fft2(I);
  5. absF = abs(DFT);
  6. Phi = atan2(imag(DFT),real(DFT));
  7. subplot( 2, 3, 1);
  8. imshow(I,[]);
  9. title( 'Image(Cameraman)');
  10. subplot( 2, 3, 2);
  11. imshow(log(fftshift(absF) + 1),[]);
  12. title( 'Spectrum');
  13. subplot( 2, 3, 3);
  14. imshow(fftshift(Phi),[]);
  15. title( 'Phase');
  16. F = absF.*exp( 1j*Phi);
  17. Rebuild = im2uint8(real(ifft2(F)));
  18. subplot( 2, 3, 4);
  19. imshow(Rebuild,[]);
  20. title( 'Rebuild with orginal specturm and phase');
  21. % rebuild with spectrum only
  22. F = absF.*exp( 1j* 1);
  23. Rebuild = im2uint8(real(fftshift(ifft2(F))));
  24. subplot( 2, 3, 5);
  25. imshow(Rebuild,[]);
  26. title( 'Rebuild with spectrum only');
  27. % rebuild with Phase only
  28. g = 1.*exp( 1j*Phi);
  29. g = im2uint8(real(ifft2(g)));
  30. subplot( 2, 3, 6);
  31. imshow(g,[]);
  32. title( 'Rebuild with Phase only');

     接下来我们再来看看图像在空间域中的移位和旋转对相位有什么影响。下图中,左边一列是图像,中间一列是频谱,右边一列是相位图。你必须意识到,通过肉眼,你很难从相位图中得到什么有用的信息。

(上图中最后一行打错了,不是“旋转改变了相位”而是“平移改变了相位”)

Matlab代码:


 
 
  1. clear all
  2. close all
  3. %% Author: J27
  4. % Jesus love you!
  5. % shifting and rotation
  6. Isize = 512;
  7. Rwidth = 50;
  8. Rlength = 3*Rwidth;
  9. Irect = zeros(Isize);
  10. Irect(floor((Isize - Rlength)/ 2) + 1:floor((Isize - Rlength)/ 2) + Rlength,...
  11. (floor(Isize - Rwidth)/ 2) + 1:floor((Isize - Rwidth)/ 2) + Rwidth) = 1;
  12. Idft = fft2(Irect);
  13. subplot( 3, 3, 1);
  14. imshow(Irect);
  15. subplot( 3, 3, 2);
  16. imshow(log(abs(fftshift(Idft))+ 1),[]);
  17. subplot( 3, 3, 3);
  18. imshow((atan2(imag(Idft),real(Idft))),[]);
  19. Irot = imrotate(Irect, 45, 'crop', 'bilinear');
  20. Idft = fft2(Irot);
  21. subplot( 3, 3, 4);
  22. imshow(Irot);
  23. subplot( 3, 3, 5);
  24. imshow(log(abs(fftshift(Idft))+ 1),[]);
  25. subplot( 3, 3, 6);
  26. imshow(atan2(imag(Idft),real(Idft)),[]);
  27. Irect = zeros(Isize);
  28. Irect(floor((Isize - Rlength)/ 2) + 150 + 1:floor((Isize - Rlength)/ 2) + 150 + Rlength,...
  29. (floor(Isize - Rwidth)/ 2) + 1 + 200:floor((Isize - Rwidth)/ 2) + Rwidth + 200) = 1;
  30. Idft = fft2(Irect);
  31. subplot( 3, 3, 7);
  32. imshow(Irect);
  33. subplot( 3, 3, 8);
  34. imshow(log(abs(fftshift(Idft))+ 1),[]);
  35. subplot( 3, 3, 9);
  36. imshow(atan2(imag(Idft),real(Idft)),[]);

 

Matlab代码:


 
 
  1. I = im2double(imread( 'cameraman.tif'));
  2. Idft = fft2(I);
  3. figure;
  4. subplot( 2, 3, 1);
  5. imshow(I,[]);
  6. subplot( 2, 3, 2);
  7. imshow(log(abs(fftshift(Idft))+ 1),[]);
  8. subplot( 2, 3, 3);
  9. imshow(atan2(imag(Idft),real(Idft)),[]);
  10. Iswap = fftshift(I);
  11. Idft = fft2(Iswap);
  12. subplot( 2, 3, 4);
  13. imshow(Iswap,[]);
  14. subplot( 2, 3, 5);
  15. imshow(log(abs(fftshift(Idft))+ 1),[]);
  16. subplot( 2, 3, 6);
  17. imshow(atan2(imag(Idft),real(Idft)),[]);

                                                                                (全文完)

                                                                                 谢谢收看!

  • 7
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值