# Image translation

I am trying to build a simple function to translate the pixels of an image following the x axis and the y axis.To do so, I am using the following pseudo algorithm we saw in class:

1. Compute the DFT of the image I
2. Multiply each I(k,l) by exp(-2*ipix*l/L)*exp(-2*ipik/L)

3. Compute the inverse fourrier transform of the previous matrix considering that the image have 3 channels (Red ,green and blue).

The instruction 2 have to be done for each one. Now here is my matlab implementation.My problem is that the output image is not translated.Does any one have any suggestion?

     function [translatedImage  ] = TranslateImage( image,x,y )
FreqImage=fft2(image);

S=size(image);
M=S(1,1);
L=S(1,2);
for j=1:3
for m=1:M
for l=1:L
FreqImage(m,l,j)=FreqImage(m,l,j)*exp(2*i*pi*m*x/M)*exp(2*i*pi*l*y/L);
end
end
end
translatedImage=ifft2(FreqImage);


The following code is taken from your post and modified accordingly to produce the working result. Mainly input is normalized, output bound values are properly adjusted and for-loop variables j and l are replaced with s and n for clarity.

image = double(imread('path to your file...'));
image = image/255;      % Normalize the image to [0,1] range (it was 8 bit in [0-255] range before)

figure,imshow(image);

FreqImage=fft2(image);

S=size(image);
M=S(1,1);
N=S(1,2);

x = 16;
y = 16;
for s=1:3
for m=1:M
for n=1:N
FreqImage(m,n,s)=FreqImage(m,n,s)*exp(j*2*pi*m*x/M)*exp(j*2*pi*n*y/N);
end
end
end

I = real(ifft2(FreqImage));

I = I - min(I(:));          % Adjust for out-of bounds [0,1] range.
I = I ./ max(I(:));

figure,imshow(I)