MatLab - moving images using FFT

I want to move an image (represented by a two-dimensional matrix) using the multiplication of its fft by exp (-j * 2 * pi * x * F), where x is the offset. I have:

 input=peaks(200); H=fftshift(fft2(fftshift(input))); x=19; H=H*exp(-1i*x*2*pi*F); IF_image=fftshift(ifft2(fftshift(H))); imshow(IF_image) 

But I'm having trouble identifying / representing F in H [F], since my input is a two-dimensional array. How can i do this? The desired result would be my original image, shifted along the horizontal axis (in units of x) in the same frame, so that it starts with x + 1. As an example:

If input=

 1 2 3 4 5 6 7 8 9 0 

and x = 2, I want:

 4 5 1 2 3 9 0 6 7 8 
+7
image image-processing matlab fft ifft
source share
1 answer

You have identified the property to translate / shift in 1D. For 2D, this is slightly different, but based on the same principle. To achieve a 2D translation, this is a translation / translation property, which is defined as:

enter image description here

x0,y0 will be the shift you want to enter. Thus, a positive value of x0 will shift your 2D signal to the right, while a negative value will shift to the left. Similarly, a positive value of y0 would move your 2D image down, while a negative value would move up.

Therefore, given your Fourier to 2D conversion, you will need to add an additional term to the exponent. In addition, you must normalize to N or the size of your 2D signal. This assumes your two-dimensional signal has the same number of rows and columns. If this is not the case, you need to take u*x0 , and you divide it by the number of columns, and v*y0 will be divided by the number of rows.
Now, the reason you mess up with F in your previous code is because you don't know how to define this in 2D. You must determine the frequency value for each point in the 2D grid . Due to your fftshift call fftshift we define the x and y values ​​between -100 and 99, since your 2D signal is 200 x 200 in size and this will center our 2D signal in the middle. This is actually what fftshift does. Similarly, ifftshift overrides the centering performed by fftshift . To define these points in 2D, I use a meshgrid . Once you define these points, you take each coordinate pair (x,y) , then create a complex exponent, as you see in the above property.

Therefore, your code must be modified in this way. Keep in mind that I got rid of the redundant fftshift and ifftshift in your source code. You have to call fft and then fftshift center the spectrum. I also changed your input variable to in , since input is a function in MATLAB, and we don’t want to inadvertently obscure the function of the variable.

I also defined the x shift for -35, and the y -shift - -50. This will mean that the resulting signal will shift to the left by 35, and up by 50.

Thus:

 in=peaks(200); %// Define input signal H=fftshift(fft2(in)); %// Compute 2D Fourier Transform x0=-35; %// Define shifts y0=-50; %// Define shift in frequency domain [xF,yF] = meshgrid(-100:99,-100:99); %// Perform the shift H=H.*exp(-1i*2*pi.*(xF*x0+yF*y0)/200); %// Find the inverse Fourier Transform IF_image=ifft2(ifftshift(H)); %// Show the images figure; subplot(1,2,1); imshow(in); subplot(1,2,2); imshow(real(IF_image)); 

Notice that I displayed the component of the actual resulting image. This is due to the fact that as soon as you accept the inverse Fourier transform, there may be some kind of numerical inaccuracy, and the complex part of the signal is actually quite small. We can ignore this by simply using the real component of the signal.

This is the image I get:

enter image description here

As you can see, the image really shifted properly, which is confirmed by the above property. If you want to specify different shifts, you just need to change x0 and y0 to suit your tastes. In your case, you must specify y0 = 0 , then x0 can be whatever you want if you want a horizontal translation.

+11
source share

All Articles