首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >fftw -访问冲突错误

fftw -访问冲突错误
EN

Stack Overflow用户
提问于 2013-06-25 17:03:35
回答 3查看 1.2K关注 0票数 2

我实现了一个fftw (fftw.org)示例来使用快速傅立叶变换...这就是代码...

我加载了一个图像,并将其从uint8_t转换为double (此代码运行良好...)。

代码语言:javascript
复制
string bmpFileNameImage = "files/testDummyFFTWWithWisdom/onechannel_image.bmp"; 
BMPImage bmpImage(bmpFileNameImage);
vector<double>pixelColors; 
vector<uint8_t> image = bmpImage.copyBits();

toDouble(image,pixelColors,256,256, 1); 
int width = bmpImage.width();
int height = bmpImage.height();

我使用智慧文件来提高性能。

代码语言:javascript
复制
FILE * file = fopen("wisdom.fftw", "r");
if (file) {
    fftw_import_wisdom_from_file(file);
    fclose(file);
} 

///*  fftw variables  */
fftw_complex *out;

double *wisdomInput = (double *) fftw_malloc(sizeof(double)*width*2*(height/2 +1 ));

const fftw_plan forward =fftw_plan_dft_r2c_2d(width,height, wisdomInput,reinterpret_cast<fftw_complex *>(wisdomInput),FFTW_PATIENT);
const fftw_plan inverse = fftw_plan_dft_c2r_2d(width, height,reinterpret_cast<fftw_complex *>(wisdomInput),wisdomInput, FFTW_PATIENT);

file = fopen("wisdom.fftw", "w");

if (file) {
    fftw_export_wisdom_to_file(file);
    fclose(file);
}

最后,我执行fftw库...我收到了第一个函数(fftw_execute_dft_r2c)的访问冲突错误,但我不知道为什么...我阅读了这个教程:http://www.fftw.org/fftw3_doc/Multi_002dDimensional-DFTs-of-Real-Data.html#Multi_002dDimensional-DFTs-of-Real-Data。我做了一个(ny/2+1)如何解释的malloc……。我不明白为什么它不能工作...我在测试不同的尺寸...

代码语言:javascript
复制
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * width *(height / 2 + 1));
double *result =(double *)fftw_malloc(width * (height+2)  * sizeof(double));

fftw_execute_dft_r2c(forward,&pixelColors[0],out);
fftw_execute_dft_c2r(inverse,out,result);

致以问候。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-06-27 00:48:18

这是更正后的代码。它有几个错误:

  • 它正在读取错误的wisdom.fftw文件(从一些旧的测试中...)。现在,它总是创建一个新的fftw_plan和一个新的文件。
  • 我误解了它是如何使用in-place and out-of-place参数来工作fftw库的。我必须为“就地”更改link.

的正确填充(我在malloc函数中添加了+2 )。

  • 为了恢复镜像,我必须除以它的大小((width+2) *高度),这在这个mallocs中有解释。

`

代码语言:javascript
复制
/* load image */
string bmpFileNameImage = "files/polyp.bmp";

BMPImage bmpImage(bmpFileNameImage);

int width = bmpImage.width();
int height = bmpImage.height();

vector<double> pixelColors;
vector<uint8_t> image = bmpImage.copyBits();
//get one channel from the image
Uint8ToDouble(image,pixelColors,bmpImage.width(),bmpImage.height(),1);

//We don't reuse old wisdom.fftw... It can be corrupt 
/*
FILE * file = fopen("wisdom.fftw", "r");
if (file) {
    fftw_import_wisdom_from_file(file);
    fclose(file);
} */

double *wisdomInput = (double *) fftw_malloc(sizeof(double)*height*(width+2));

const fftw_plan forward =fftw_plan_dft_r2c_2d(width,height,wisdomInput,reinterpret_cast<fftw_complex *>(wisdomInput),FFTW_PATIENT);
const fftw_plan inverse = fftw_plan_dft_c2r_2d(width,height,reinterpret_cast<fftw_complex *>(wisdomInput),wisdomInput, FFTW_PATIENT);
double *bitsColors =(double *)fftw_malloc((width) * height * sizeof(double));

for (int y = 0; y < height; y++) {
    for (int x = 0; x < width+2; x++) {
        if (x < width) {
            int currentIndex = ((y * width) + (x));
            bitsColors[currentIndex] = (static_cast<double>(result[y * (width+2) + x])) / (height*width);
        }
    }
}
fftw_free (wisdomInput);
fftw_free (out);
fftw_free (result);
fftw_free (bitsColors);

fftw_destroy_plan(forward);
fftw_destroy_plan(inverse);
fftw_cleanup();
}

`

票数 1
EN

Stack Overflow用户

发布于 2013-06-25 17:43:04

代码语言:javascript
复制
fftw_execute_dft_r2c(forward,&pixelColors[0],out);

你在这里做什么?该数组已有一个指针。将其更改为fftw_execute_dft_r2c(forward,pixelColors[0],out);它现在应该可以工作了。

票数 0
EN

Stack Overflow用户

发布于 2013-06-25 19:04:32

也许问题出在这里(http://www.fftw.org/doc/New_002darray-Execute-Functions.html):

...满足以下条件:

  • 如果计划最初被创建为就地或非就地,则输入和输出数组相同(就地)或不同(就地)。

在计划中,您使用的是就地转换参数(具有错误的分配,BTW,因为:

代码语言:javascript
复制
double *wisdomInput = (double *) fftw_malloc(sizeof(double)*width*2*(height/2 +1 ));

应该是:

代码语言:javascript
复制
double *wisdomInput = (double *) fftw_malloc(sizeof(fftw_complex)*width*2*(height/2 +1 ));

也适用于输出)。

但是您正在使用不正确的参数调用fftw_execute_dft_r2c函数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17293212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档