Thursday, 29 September 2016

Two dimensional Fourier transform using Matlab


2-D Fourier transform using 1-D Fourier transform:

The Fourier Transform ( in this case, the 2D Fourier Transform ) is the series expansion of an image function ( over the 2D space domain ) in terms of "cosine" image (orthonormal) basis functions.
The definitons of the transform (to expansion coefficients) and the inverse transform are given below:
 F(u,v) = SUM{ f(x,y)*exp(-j*2*pi*(u*x+v*y)/N) }
    and
 f(x,y) = SUM{ F(u,v)*exp(+j*2*pi*(u*x+v*y)/N) }

    where u = 0,1,2,...,N-1 and v = 0,1,2,...,N-1
   x = 0,1,2,...,N-1 and y = 0,1,2,...,N-1
   j = SQRT( -1 )
   and SUM means double summation  over proper
   x,y or u,v ranges

Program: 

aa=imread('D:\Flower.jpg');          % USE SQAURE IMAGE
aa=rgb2gray(aa)
a1=abs(fft2(aa));                          %Using the inbuilt FFT function for comparison
s=size(a);
figure(1)
imshow(aa)
title('original image')

%To find the Twiddle factor
for k=0:1:s(1)-1                            %Image is square
for n=0:1:s(2)-1
                 p=exp(-i*2*pi*k*n/s(2));
 x(k+1,n+1)=p;     %x is the DFT matrix
end
end

%To find the 1-D Fourier transform again along the rows
for n=1:1:s(1)
    d=x*a(n,:).';
z(:,n)=d;                                               %Arranged in rows
end

%To find the 1-D Fourier transform again along the columns
for n1=1:1:s(2)
    d1=x*z(n1,:).';
z1(:,n1)=d1;
end

%plotting
z=abs(z1);
figure(2);
colormap(gray);
imagesc(fftshift(log(1+z)));
title('Fourier image');
figure(3;)
colormap(gray);
imagesc(fftshift(log(1+a1)));
title('Fourier transform image');

OUTPUT:  









 

No comments:

Post a Comment