Нарушение доступа при временной компиляции (0xC0000005) - PullRequest
0 голосов
/ 18 июля 2011

Процесс, который я хочу сделать, состоит в том, чтобы преобразовать 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;
}

При значениях х = 95 и у = 93, равных М = 191 и N = 96; Неконтролируемое исключение в 0x004273ab в prueba_r01.exe: 0xC0000005 чтение нарушения 0x01274000.

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

Там, где множество значений переменных выделено красным цветом, и для проблемы перевода: H_cast [] [1] имеет в поле значения: «Error30CXX0000: невозможно вычислить выражение».

Я буду очень признателен за любую помощь с этим, пожалуйста!

Антонио

Ответы [ 2 ]

1 голос
/ 23 сентября 2011

Внутри ITK есть класс FFT, который может использовать fftw (USE_FFTW) из cmake для конфигурации.Этот класс описывает, как обращаться к необработанной буферной памяти ITK из fftw.

PS: Предстоящий ITKv4 значительно улучшил совместимость fftw.

1 голос
/ 18 июля 2011

Эта часть кода

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 теряется!

...