2
$\begingroup$

This is my testing image,it is taken from this paper:

enter image description here

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:

enter image description here

But the result in this paper is like this:

enter image description here

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 & 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 & 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 & 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.

$\endgroup$
3
$\begingroup$

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...

$\endgroup$
  • $\begingroup$ thank you @Drazick. But I have used both fft2 and ifft2 in my codes. The Real cepstrum is defined as $cepstrum=F^{-1}(log|F(I(x,y))|)$ . So I think there's no need to use ifftshift or fftshift. $\endgroup$ – alexyangfox Jul 19 '14 at 7:38
  • $\begingroup$ @alexyangfox, Have a look at my code. It worked for me (Namely, the function maximum was centered). $\endgroup$ – Royi Jul 19 '14 at 7:52
  • $\begingroup$ Thank you very much.. It really works..But I am wondering whether the maximum should really be at the center. $\endgroup$ – alexyangfox Jul 19 '14 at 14:47
  • $\begingroup$ Thank you very much again . Yes,You are right.When the papers are saying The Cepstrum (Calculated with FT) has the maximum at the center,I misunderstood it with The Cepstrum calculated with DFT & IDFT has the maximum at the center $\endgroup$ – alexyangfox Jul 21 '14 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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