I've write a function that calculates the DFT of an image, My prupose is to show the amplitude spectrum without using the fftshift command. DFT_img.m looks like this:
function f = DFT_img(a);
[n m]=size(a);
for i =1:n
k=1;
for j =1:n
l=1;
F(i,j)=(1/n*n)*a(i,j)*exp(-i*2*pi*(k*i+l*j)/n);
l=l+1;
end
k=k+1;
end
f=F;
And when i write in Command Window the commands
A = imread("lena.tiff");
ans = DFT_img(A);
spectrum = log(abs(ans));
mesh(spectrum)
i am not getting the same result that
fftshift matlab function
does !!! Am i having a mistake in the function, or where is the problem with that ?
% draw a square in the middle of image % m - height of image % n - width of image % k - dimension of square function f = Kat(m,n,k) A = zeros(m,n); A(m/2-k:m/2+k,n/2-k:n/2+k)=1; f=A; end
– ah92 May 25 '13 at 10:05