0

私がやりたいプロセスは、FFTを画像(「imagen」に格納されている)に作成し、それをフィルター「H」で乗算することです。その後、逆FFTも実行されます。コードを以下に示します。

int ancho;
int alto;
ancho=ui.imageframe->imagereader->GetBufferedRegion().GetSize()[0];     //ancho=widht of the image
alto=ui.imageframe->imagereader->GetBufferedRegion().GetSize()[1];      //alto=height of the image

double *H ;
H =matrix2D_H(ancho,alto,eta,sigma); // H is calculated

// We want to get: F= fft(f) ; H*F ; f'=ifft(H*F)
// Inicialization of the neccesary elements for the calculation of the fft
fftw_complex *out;
fftw_plan p;

int N= (ancho/2+1)*alto; //number of points of the image
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*N);

double *in = (double*) imagen.GetPointer(); // conversion of itk.smartpointer --> double*
p = fftw_plan_dft_r2c_2d(ancho, alto, in, out, FFTW_ESTIMATE); // FFT planning
fftw_execute(p); // FFT calculation

/* Multiplication of the Output of the FFT with the Filter H*/ 
int a = alto;
int b = ancho/2 +1; // The reason for the second dimension to have this value is that when the FFT calculation of a real image is performed only the non-redundants outputs are calculated, that’s the reason for the output of the FFT and the filter ‘H’ to be equal. 

// Matrix point-by-point multiplicaction: [axb]*[axb]
fftw_complex* res ; // result will be stored here
res = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*a*b);
res = multiply_matrix_2D(out,H, a, b);

問題はここ、関数'multiply_matrix_2D'内のループにあります。

 fftw_complex*  prueba_r01::multiply_matrix_2D(fftw_complex* out, double* H, int M ,int N){
/* The matrix out[MxN] or [n0x(n1/2)+1] is the image after the FFT , and the out_H[MxN] is the filter in the frequency domain,
both are multiplied POINT TO POINT, it has to be called  twice, one for the imaginary part and another for the normal part
*/
fftw_complex *H_cast;
H_cast = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*M*N);
H_cast= reinterpret_cast<fftw_complex*> (H); // casting from double* to fftw_complex*

fftw_complex *res; // the result of the multiplication will be stored here
res = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*M*N);

//Loop for calculating the matrix point-to-point multiplication
for (int x = 0; x<M ; x++){
    for (int y = 0; y<N ; y++){
            res[x*N+y][0] = out[x*N+y][0]*(H_cast[x*N+y][0]+H_cast[x*N+y][1]); 
            res[x*N+y][1] = out[x*N+y][1]*(H_cast[x*N+y][0]+H_cast[x*N+y][1]); 
        }
}
fftw_free(H_cast);
return res;
}

x=95およびy=93の値は、M=191およびN=96です。prueba_r01.exeの0x004273abでの制御されていない例外:0xC0000005アクセス違反の読み取り0x01274000。

imagen http://img846.imageshack.us/img846/4585/accessviolationproblem.png

変数の多くの値が赤で表示されている場合、および変換の問題の場合:H_cast [] [1]の値ボックスに「Error30CXX0000:式を評価できません」があります。

どんなお手伝いもよろしくお願いします!!

アントニオ

4

2 に答える 2

1

コードのこの部分

H_cast = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*M*N);
H_cast= reinterpret_cast<fftw_complex*> (H); // casting from double* to fftw_complex*

最初に新しいバッファを割り当て、H_castすぐに元のバッファを指すように設定しHます。データをコピーするのではなく、ポインタだけをコピーします。

関数の終わりに、いくつかのバッファが解放されます

fftw_free(H_cast);

Hこれは、関数で割り当てられたバッファーではなく、が指すデータを解放するようです。

発信者に戻ると、Hそこは失われます!

于 2011-07-18T16:06:40.053 に答える
1

ITK内には、構成にcmakeのfftw(USE_FFTW)を使用できるFFTクラスがあります。このクラスは、fftwからITKrawバッファメモリを参照する方法を説明します。

PS:今後のITKv4はfftwの互換性を大幅に改善しました。

于 2011-09-23T02:26:24.903 に答える