且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

FFT 图像变换的输入和输出应该是什么?

更新时间:2022-10-15 21:01:19

您没有提供源代码...

  1. 你的结果看起来像分辨率树

    用于递归分辨率/频率信息缩放和特征提取,而不是FFT!!!因此,可能是您的递归错误或重叠数据(就地编码 FFT 几乎是疯狂的),您应该从 1D 变换开始,然后将其用于 2D 并目视检查每个阶段(以及匹配原始数据的逆变换)

  2. 你的 FFT 输出应该有非零虚部!!!

    看这里

    I try to obtain the spectrum of an grayscale image using FFT Cooley–Tukey algorithm in Java. I don't know exactly how to form the input for the algorithm and what values from the output to use in order to form the spectrum image.

    Currently my input is an array of complex numbers, with Re = value of the pixel in 8bit grayscale domain and Im = 0; After running the algorithm I obtain another array of complex numbers with the real part having a lot of values out of [0,255] range and imaginary part 0. I have tried to create an image from the real numbers array modulo 256.

    This is how the spectrum should look:

    And this is what I've got:

    Obviously I'me doing something terrible wrong but I don't know what.

    You did not provide your source code ...

    1. your result looks like resolution tree

      used for recursive resolution/frequency information scaling and feature extraction not FFT !!! So may be your recursion is wrong or you overlap data (to code in-place FFT is almost insanity) you should start with 1D transform and then use that for 2D and visually check every stage (also the inverse transform to match original data)

    2. your FFT output should have non zero Imaginary part !!!

      look here How to compute Discrete Fourier Transform and into all sub-links in that answer of mine

    3. is your image resolution exact power of 2?

      if not zero pad it or the FFT would not work properly

    4. your example is wrong

      this is how it looks like in real:

      • left is input image (copied from your question)
      • middle is real part
      • right is imaginary part

      you can combine them to power spectrum =sqrt(Re*Re+Im*Im) the Re and Im image is amplified to be seen else just few white dots in the corners would be visible. Here some more examples:

      your expected result looks like shifted by half of the image resolution (so the center of symmetry is in center of image instead of in corners)

    [Edit1] power and wrap

    have added power and wrap functions to mine app so here is the result:

    first the power is computed so intensity=sqrt(Re^2+Im^2) and then wrap is done by shifting image by half size right and down. What is overlapping that comes from the other side back so just swap all points in all lines swap((x,y),(x+xs/2,y)) and then the same for all columns swap((x,y),(x,y+ys/2)). Now the result matches the one from OP the app is here