Image 2D Real Cepstrum with DFT, Is `ifftshift` Needed? This is my testing image,it is taken from this paper:



I tried to transform it into its real cepstrum domain with this simple MATLAB code:

cepstrum_img=ifft2(log(1+abs(fft2(img(:,:,1)))));
imshow((abs(cepstrum_img)))


But my result is very weird: The maximum is not at the center of image, they are at the 4 corners. And here is the zoomed-in picture with the  maximum at the left top corner:



But the result in this paper is like this:



The maximum is actually at the center!!

As I didn't do any fftshift ,  I don't think I need to do any ifftshift.


This makes me so confused. Is there something wrong with my code?
or my understanding about 2D real cepstrum with DFT?


UPDATE 1: Why do I think that fftshift or ifftshift is not needed here.

For a length-$N$ sequence $x[n]$, you do an $N$-point DFT. You will get another length-$N$ sequence $X[n]$. The first element of the resulting sequence is corresponded to the zero frequency. Then we do fftshift to the resulting length-$N$ sequence, and we get a third length-$N$ sequence $X'[n]$, because we want to make the center (may not be at the center if $N$ is even) of the element in $X'[n]$ corresponded to the zero frequency.


The question is how can you get the original  $x[n]$ with IDFT?


$\textrm{IDFT}(X[n])$ is right. $\textrm{IDFT}(X'[n])$ is wrong.

Check this MATLAB code:  

% the original sequence
x=1:8
% this will give you the original sequence
ifft(fft(x))
% but this won't
ifft(fftshift(fft(x)))
% anyway, the amplitude is the same.


The case would be the same for images and fft2 &amp; ifft2. i.e.this will get you the original img:  

 ifft2(fft2(img))


And if the cepstrum is defined as  

$$C=\mathcal F^{-1}\left\{\ln\left(\lvert \mathcal F\left\{I(x,y)\right\}\rvert\right)\right\}$$

Where $I$ = img. This is something like transforming from Fourier domain back to the spatial domain.  

UPDATE 2: I found where I am wrong..  

When the papers are saying 


  The Cepstrum (Calculated with FT) has the maximum at the center


I misunderstood it as 


  The Cepstrum calculated with DFT &amp; IDFT has the maximum at the
  center


If the Cepstrum above is really calculated with Fourier transform, the Cepstrum will be with the maximum at the origin. That means if I calculate this with DFT &amp; IDFT,the maximum should be at the corners. The same as FT vs DFT, I have assumed the Cepstrum calculated with DFT should have its maximums at the center. That's where I am wrong.
If you have image in the spatial domain, in order to calculate its DFT transform you should use fft.
Once you have its DFT in order to get back to the spatial domain use the function ifft.  

Either way, the DFT transform gives you the data in the [0, 2pi] axis.
Use fftshift to move it into the [-pi, pi] domain as seen in the paper.

Good Luck.

MATLAB Code

This code worked for me:

mInputImage = imread('3.png');
mInputImage = double(mInputImage) / 255;
mInputImage = mean(mInputImage, 3);

mImageDft = (fft2(mInputImage));

mImageDft = log(1 + abs(mImageDft));

mImageCepstrum = abs(fftshift(ifft2(mImageDft)));

mImageCepstrum = mImageCepstrum / max(mImageCepstrum(:));

figure();
imshow(mImageCepstrum);


Enjoy...