8
$\begingroup$

I load and display an image of some rice in Matlab:

g = imread('rice.png');
imshow(g);

rice

I take the FFT of this image and shift it:

G = fft2(g);
imshow(log(abs(fftshift(G)) + 1), []);

FFT(rice)

If I place a x and y axis trough the center of the image; I find that the image is symmetric g(-x,-y)=g(x,y). For a 1D signal we have that the FFT of a real signal has a symmetrical real part and an asymmetrical imaginary part. I guess that is what we see here in 2 dimensions?

Since the original image is darker at the bottom than at the top, there is a strong horizontal discontinuity at the periodic boundary causing the vertical line in the FFT.

I want to get rid of this boundary effect. A common approach to this seems to be windowing.

However I want to solve this problem by a technique I found in a paper called "mirroring". The paper was not very specific so I need your help in figuring out this approach :-).

First I create a symmetric "tile" from the original image:

tile=[flipdim(g,2) g; flipdim(flipdim(g,1),2) flipdim(g,1)];
imshow(tile);

enter image description here

Now I take the FFT of this "tile":

Tile=fft2(tile);
imshow(log(abs(fftshift(Tile)) + 1), []) 

enter image description here

The vertical line seems to be (almost) gone: good. However the mirroring seem to have introduced more symmetry.

What is the correct result: the FFT of the original image or the FFT of the "mirrored" image?

Is there a way I can "mirror" so that I both get rid of boundary effects and get a purely real FFT?

Thanks in advance for any answers!

$\endgroup$

1 Answer 1

13
$\begingroup$

The FFT of the original image is correct. The artifacts you are seeing are typical for the DFT, because the DFT basis functions have difficulty representing non-periodic signals. Even though the DFT is of finite length, it actually represents a periodic signal that extends to negative and positive infinity. The DFT's basis functions are all sinusoids with periods that are integer divisors of the DFT size, so they all start and end at the same value, and it is hard for it to fit signals that are not periodic in this way. So, imagine tiling your image: there is indeed an abrupt discontinuity at the edges. The edges do not match up well, and that is the reason for the boundary effects.

In audio signal processing, where the FFT is used often, a very common approach is to use a window function, as you noted. This tapers the edges off towards 0, and reduces this effect.

In image processing, the DCT is usually used rather than the DFT, because it imposes different symmetry constraints that give better results. In other words, it's used to prevent exactly the issue you're seeing. In contrast to the DFT's basis functions (remember how they all start and end at the same value), the DCT's basis functions are integer divisors or half of integer divisors, so many of them start and end at different values. As a result, the implied boundary conditions are different: the signal is assumed to be symmetric about its edges, which is actually somewhat similar to the "mirroring" you were experimenting with. Here is another post by me with a little more information on the DCT: https://dsp.stackexchange.com/a/362/392

So, as a short summary, if you are absolutely set on using the FFT, you might want to try windowing. However, the best choice is probably to use the DCT, which implies boundary conditions similar to your "mirroring" idea, and as a result, handles images better.

$\endgroup$
5
  • $\begingroup$ From what I could understand DFT implies periodic extension whereas DCT implies even extension. When doing image compression one is working on small blocks of the image. Since the periodic extension implied by DFT causes jumps at the border which in turn decreases the convergence rate; it is better to use DCT for image compression (faster convergence-> smaller files with same amount of visible information). However DCT seems to be mentioned mostly in this context. The context I am working in is that I want to filter an image by a Gabor filter. Can this be done using DCT? $\endgroup$
    – Andy
    Jan 10, 2012 at 14:21
  • $\begingroup$ If you just want to filter the image with a Gabor filter, you should just use the FFT. The boundary conditions won't be an issue. Why are you worried about the boundary conditions, or having a purely real spectrum, for filtering with a Gabor filter? $\endgroup$
    – schnarf
    Jan 10, 2012 at 14:30
  • $\begingroup$ Regarding having a purely real spectrum: I need to estimate the dominant frequencies: fu = Sum(u*G)/Sum(G) and fv, where G(u,v) is the FFT of my image g(x,y). I do not understand how this works if G is complex. I would get a complex fu? $\endgroup$
    – Andy
    Jan 10, 2012 at 16:33
  • $\begingroup$ Rather than considering the complex values, you should consider their magnitudes. I.e. for each complex frequency bin z = a + bi, its magnitude is sqrt(a^2 + b^2). $\endgroup$
    – schnarf
    Jan 10, 2012 at 18:24
  • $\begingroup$ Another thing to think about: It might seem confusing that you're taking real data and getting a complex spectrum. The complex spectrum is just a way of giving each sinusoid a particular phase. $\endgroup$
    – schnarf
    Jan 10, 2012 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.