在试图计算2幅图像的FFT(快速傅里叶变换)时发生访问冲突
Access violation while trying to compute FFT (fast Fourier transform) of 2 images
我正在尝试对两个原始图像进行FFT。但是我得到了unhandled exception (access violation)
——我不知道为什么。我正在使用fftw库。首先我读取两个图像,然后我计算FFT。但是在开始计算之前,会产生访问冲突错误。
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include "fftw3.h"
#define Width 2280
#define Height 170
unsigned char im2[170*2280];
unsigned char im1[170*2280];
float image1[170*2280];
float image2[170*2280];
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
FILE* fp1, *fp2;
//Read two images
fp1 = fopen ("image1.raw" , "r");
fread(im1, sizeof(unsigned char), Width* Height, fp1);
fp2 = fopen ("image2.raw" , "r");
fread(im2, sizeof(unsigned char), Width* Height, fp2);
fclose(fp2);
fclose(fp1);
//Typecasting two images into float
for (int i = 0; i < Width* Height; i++)
{
image1[i]= (float)im1[i];
image2[i] = (float)im2[i];
}
fftwf_plan fplan1, fplan2;
fftwf_complex fft1[((Width/2)+1)*2];
fftwf_complex fft2[((Width/2)+1)*2];
fplan1 = fftwf_plan_dft_r2c_2d(Height, Width, (float*)image1, fft1, FFTW_ESTIMATE);
fftwf_execute(fplan1);
fftwf_destroy_plan(fplan1);
fplan2 = fftwf_plan_dft_r2c_2d(Height,Width, image2, (fftwf_complex*)fft2, FFTW_ESTIMATE);
fftwf_execute(fplan2);
fftwf_destroy_plan(fplan2);
_getch();
return 0;
}
fft1
和fft2
仅足够容纳一个输出行-您需要Height
行。你可能也想动态分配它们,因为一旦你有了正确的大小,它们很可能对堆栈来说太大了,例如
fftwf_complex *fft1 = new fftwf_complex[((Width/2)+1)*2*Height];
fftwf_complex *fft2 = new fftwf_complex[((Width/2)+1)*2*Height];
注意:以后不要忘记调用delete []
来释放这些
相关文章:
- OpenCV 傅里叶变换复杂输出问题
- 离散傅立叶变换C++
- 函数已知时的傅里叶变换
- DFT(离散傅里叶变换)与C++代码
- 快速傅里叶变换:第一个元素是正确的,但其余元素不正确
- 应用傅里叶逆变换OpenCV后构建图像
- 傅里叶变换高斯滤波器误差
- 复数和朴素傅里叶变换 (C++).
- 通过使用FFTW3库在二维中进行快速傅里叶余弦变换
- DFT(离散傅里叶变换)与C++ STL
- 使用 CIMg 和 C++ 的傅里叶滤波
- 如何在c++中执行二维快速傅里叶变换
- 如何执行FFT2D(快速傅里叶变换2D) R, G, B颜色分量
- 傅里叶反变换FFT3W
- 在试图计算2幅图像的FFT(快速傅里叶变换)时发生访问冲突
- 离散傅里叶变换中复数的c++表示
- 在短时间傅里叶变换中得到特定频率的值
- Qt中的基本图像处理,如何将图像分解为数组,准备对其执行傅里叶变换
- 如何使用fftw3将一个数组傅里叶变换成另一个不同大小的数组
- 使用快速傅里叶变换模糊矩阵