% DIGITAL IMAGE PROCESSING [ ELEN-512 ]  - PROJECT 1
% Assume our image is in the format that you can use imread function to
% read. Write 2 functions in Matlab. The first function is the 2-D Fourier
% transform by using equation (4.6-14) and (4.6-15). The input of this 
% function is a image, the output is the centered DFT. 
% The second function is 2-D inverse Fourier transform by referring to 
%equation (4.6-16) and (4.6-19). The input of this function is a 
%centered DFT of a image, the output is the image.Test you functions by 
%using the image coins.png. 
I = imread('coins.png');             % imread command reads given image 
                                     % file coins.png and finds the matrix
                                     % array of the image.
[m n ] = size(I);                    % for the size of the matrix array of 
                                     % the given image. 
F = zeros(m,n);
z=im2double(I);                      % im2double function converts image 
                                     % array to double precision.
c = 0;                               % initializing the values to zero
d =0;                                % initializing the values to zero
% The first function is the 2-D Fourier transform by using equation 
% (4.6-14) and (4.6-15). The input of this function is a image,
% the output is the centered DFT. 
for u = 1:m
    for v = 1:n
        for x = 1:m
            c = c + exp(-(j*2*pi*u*x)/m);
                for y = 1:n
              d = d + z(x,y)*exp(-(j*2*pi*y*v)/n);  % equation 4.6-15
             end
            end
            F(u,v) = c*d/(m*n);                     % equation 4.6-14
            c = 0;
            d = 0;
    end
end
% The second function is 2-D inverse Fourier transform by referring to 
% equation (4.6-16) and (4.6-19). The input of this function is a 
% centered DFT of a image, the output is the image.Test you functions by 
% using the image coins.png. 
for x = 1:m
    for y = 1:n
        for u = 1:m
                c = c +exp(-(j*2*pi*u*x/m));
            for v = 1:n
                d = d + conj(F(u,v))*exp(-(j*2*pi*((u*x/m)+(v*y/n))));
               end
        end
        F(x,y) = conj(c*d/(m*n));
        c = 0;
        d = 0;
    end
end
imshow(F)                             % Command to display the output image

            
