fftw将零频移到图像中心 [英] fftw shift zero-frequency to image center

查看:252
本文介绍了fftw将零频移到图像中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力将FFTW应用于图像.

I am struggling on the result of FFTW applied on image.

我可以对图像执行傅立叶变换和傅立叶逆变换,我确信这两个函数都可以正常工作.现在,我正在尝试分析傅立叶变换的结果,并尝试对其应用过滤器,等等.

I can do the Fourier transform and inverse Fourier transform on image, I am sure the two functions are working. Now I am trying to analyze the result of Fourier transform and try to apply a filter on it, etc.

目前,我对FT的结果感到困惑.据我所知,零频率应该在左上角.如果要检查频率友好,应将其移至图像中心.我测试了至少两种方法. FFTW FAQ网页上介绍了一种方法,在傅立叶变换之前,将图像中的所有像素都乘以(-1)^(i + j),其中i和j是像素的索引.

Currently I am confusing on the FT result. As I know the the zero-frequency should be on the top-left corner. I should shift it to the image center if I want to check frequency friendly. There are at least two way I have tested. one method is described on the FFTW FAQ webpage, all the pixels in the image were multiplied by (-1)^(i + j) before Fourier transform, where i, and j are the pixel's index.

图像乘以(-1)^(i+j),则其大小为

但是实际上,它应该是这样的(我在imagej中做过)在imagej中进行傅立叶变换:

but actually ,it should be like this (which I did in imagej) Fourier transform in imagej:

我还尝试使用自己的代码在计算其幅度之后切换它们,但是得到了类似的错误结果.

I also tried using my code to switch them after calculating its magnitude, but got the similar wrong result.

void ftShift2D(double * d, int w, int h)
{

    int nw = w/2;
    int nh = h/2;
    if ( w%2 != 0) {nw++;}
    if ( h%2 != 0) {nh++;}

        printf("%d, %d\n", nw, nh);
        for (int i = 0; i < nh ; i++)
        {
                for(int j = 0; j < nw; j++)
                {
                        int t1 = i * w + j;
                        int t2 = (i + nh + 1) * w + j + nw;
                        swapXY<double>(d[t1], d[t2]);
                }

                for (int k = nw; k < w; k++)
                {
                        int t1 = i  * w + k;
                        int t2 = (i + nh + 1 ) * w + k - nw;
                        swapXY<double>(d[t1], d[t2]);
                }
        }
}

我了解FFTW中FT结果的布局,如其网站中所述. 我还检查了输出,可以确认此布局,只有上半部分有数据,其余为0.因此,似乎可以解释为什么上面使用的两种方法无法正常工作.我正在尝试设计一种将零频移到图像中心的新方法.你能给我一个更好的方法吗?

I understood the layout of FT result in FFTW, as is described in their website. I also checked the output, this layout can be confirmed, only top half have data, the rest is 0. therefore, it seems explain why the two methods used above cannot work. I am trying to design new method to shift the zero-frequency to image center. could you give me a better way to do it?

我坚持这一点,旨在使用过滤器,这样会更容易理解.如果零频率没有移到中心,那么你们能不能再给我一个建议,例如,我可以在频域上对其应用高斯高斯滤波器.

I insist on this, aim to use the filter, it will be easier to understand. if the zero-frequency did not be shifted to center, could you guys give me another suggestion that I can, for example, apply a high Gaussian filter on it in frequency domain.

非常感谢.

输入图像为:

FT和IFT代码是

    void Imgr2c(double * d, fftw_complex * df, int w, int h)
{
        fftw_plan p = fftw_plan_dft_r2c_2d(h, w, d, df, FFTW_ESTIMATE);
        fftw_execute(p);

        fftw_destroy_plan(p);

}


void Imgc2r(fftw_complex * in, double * ftReverse, int w, int h)
{
        fftw_plan p = fftw_plan_dft_c2r_2d(h, w, in, ftReverse, FFTW_ESTIMATE);
        fftw_execute(p);

        int l = w * h;
        for (int i = 0; i < l; i++)
        {
                ftReverse[i] /= l;
        }

        fftw_destroy_plan(p);
}

[由Spektre编辑]

这应该或多或少是这样的:

This is how it should more or less look like:

推荐答案

我发现了我的问题所在!我对FFTW中DFT的输出布局不甚了解.经过一些测试,我发现宽度的尺寸应为w/2 + 1,高度的尺寸没有变化.进行FT,IFT和平移原点的代码没有问题.我需要做的是在尝试访问尺寸时进行更改.

I found what is my problem! I did not understand the output layout of DFT in FFTW deeply. After some tests, I found the the dimension in width should w/2 + 1, and the dimension in height did not changed. the code to do FT, IFT, and shift the origin have no problem. what I need to do is changing the dimension when try to access it.

DFT后的幅度

移动原点后的幅度 欢呼声,

瑶王

这篇关于fftw将零频移到图像中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆