C中的2D傅立叶变换 [英] 2D Fourier Transformation in C
问题描述
我使用此站点中的公式实现了二维DFT和IDFT
http://homepages.inf.ed.ac.uk/rbf/HIPR2/fourier.htm
我认为这些是正确的,并得到了很好的解释。
实现看起来像这样:
I implemented 2D DFT and IDFT using equation from this site http://homepages.inf.ed.ac.uk/rbf/HIPR2/fourier.htm I think these are correct and nicely explained. Implementation looks like that:
for(int i=0;i<inImage.width;i++)
{
for(int j=0;j<inImage.height;j++)
{
float ak=0;
float bk=0;
for(int ii=0;ii<inImage.width;ii++)
{
for(int jj=0;jj<inImage.height;jj++)
{
float x=-2.0*PI*i*ii/(float)inImage.width;
float y=-2.0*PI*j*jj/(float)inImage.height;
// ak+=inImage.pixels[i][j]*(cos(x)*cos(y)-sin(x)*sin(y));
// bk+=inImage.pixels[i][j]*(sin(x)*cos(y)+sin(y)*cos(x));
ak+=inImage.pixels[i][j]*cos(x+y);
bk+=inImage.pixels[i][j]*1.0*sin(x+y);
}
}
DFTImageRE.pixels[i][j]=ak;
DFTImageIM.pixels[i][j]=bk;
}
}
频域(sqrt(ak * ak + bk * bk))看起来不理想,并且图像重建(忽略虚部)在原始图像附近没有任何作用。 [0] [0]处的更多像素具有极高的值,并且没有像素在原始像素的范围内从0到255。我在做什么错?
The frequency domain (sqrt(ak * ak+bk * bk)) doesnt look as it should, and the image reconstruction (ignoring the imaginary parts) doesnt make anything near the original image. What is more pixel at [0][0] have extremely high value and no pixels range from 0 to 255 as the original one. What am i doing wrong?
其他信息:
- inImage和DFTImages是
- 我不能使用任何类(如虚数)来构造普通的* .pgm图像,因此可以保存和加载图像,因为此实现将在GPU端进行,
谢谢
推荐答案
我发现了一个解决我的问题。这只是索引问题。总和中使用ii和jj来找到傅里叶变换
I found a solution for my problem. It was just indexing problem. Use ii and jj in sum to find a Fourier Transform
for(int i=0;i<inImage.width;i++)
{
for(int j=0;j<inImage.height;j++)
{
float ak=0;
float bk=0;
for(int ii=0;ii<inImage.width;ii++)
{
for(int jj=0;jj<inImage.height;jj++)
{
float x=-2.0*PI*i*ii/(float)inImage.width;
float y=-2.0*PI*j*jj/(float)inImage.height;
ak+=inImage.pixels[ii][jj]*cos(x+y);
bk+=inImage.pixels[ii][jj]*1.0*sin(x+y);
}
}
DFTImageRE.pixels[i][j]=ak;
DFTImageIM.pixels[i][j]=bk;
}
}
这篇关于C中的2D傅立叶变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!