image rotation in frequency domain

巧了我就是萌 提交于 2020-01-05 08:09:29

问题


I found a code about image rotation in frequency domain. But I couldn't understand this code. This code works correct. Can anyone describe this code? Actually I have to write a code to rotate an image in frequency domain in polar coordinates. Do you think this code meet the requirements.

clear;
img=imread('cameraman.tif');
imshow(img); title('original image');
theta=26,5;
N=size(img,1);
M=size(img,2);                                      

fimg=fftshift(fft2(fftshift(img)));

p=ones(N,1)*[-N/2:(N-1)/2];               % horizontal axis
q=-p';                                                     % vertical axis

theta=2*pi*theta/360;
g=1/(N^2).*fimg;
z1=exp(i*pi/N.*((p.^2-q.^2)*cos(theta)-2*p.*q*sin(theta)));
z2=exp(-i*pi/N.*((p.^2-q.^2)*cos(theta)-2*p.*q*sin(theta)));
k=ifft2(fft2(g.*z1).*(fft2(z2)));
figure,
imshow(abs(fftshift(flipud(k))), [0 255]); 
title(['Cameraman rotated at ' num2str(theta*360/(2*pi))  ' Degrees']); axis off

回答1:


As you can see here.

For the rotation, there is no properties. But this code using the shift properties to apply the rotation.

In z1, you have the coordinate (p,q) compute normaly as well, but just by applying the 2D rotation matrix to your coordinate, you can use the shift properties.

And notice, this code change a the sign every where, that why there no minus in z1 instead of z2.

Rotation : [cos(theta) -sin(theta);
            sin(theta) cos(theta)];


来源:https://stackoverflow.com/questions/23876034/image-rotation-in-frequency-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!