void __fastcall TForm1::FFTW(TObject *Sender)
{
fftw_complex* in, * dft;
fftw_plan plan_f, plan_i;
int i, j, k, w, h, N;
int outwidth;
//wczytanie parametrów
w = Bufor->Picture->Bitmap->Width;
h = Bufor->Picture->Bitmap->Height;
N = w * h;
outwidth = w/2+1;
//alokacja pamieci
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
dft = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
ProgressBar1->Max = Obraz->Picture->Bitmap->Width;
plan_f = fftw_plan_dft_2d(w, h, in, dft, FFTW_FORWARD, FFTW_ESTIMATE);
for (i = 0, k = 0; i < h; i++)
{
for (j = 0; j < w; j++, k++)
{
in[k][0] = Obraz->Picture->Bitmap->Canvas->Pixels[((Obraz->Picture->Bitmap->Canvas->Pixels[ i][j] + i * Obraz->Picture->Bitmap->Width))][j]; // <----
in[k][1] = 0.;
ProgressBar1->Position = i;
}
}
ProgressBar1->Position = 0 ;
fftw_execute(plan_f);
//filtr dolnoprzepustowy
LowPass(dft,outwidth,h,3);
// fft odwrotna
plan_i = fftw_plan_dft_2d(w, h, dft, in, FFTW_BACKWARD, FFTW_ESTIMATE);
fftw_execute(plan_i);
wczytanie wartości po filtracji
for (i = 0, k = 0; i < h; i++)
{
for (j = 0; j < w; j++, k++)
Wynik->Picture->Bitmap->Canvas->Pixels[((Wynik->Picture->Bitmap->Canvas->Pixels[i][j] + i * Wynik->Picture->Bitmap->Width))][j] = dft[k][0]; // <----
fftw_destroy_plan(plan_f);
fftw_destroy_plan(plan_i);
fftw_free(in);
fftw_free(dft);
}}
LowPass(fftw_complex *outp, int outwidth, int height, int spacing)
{
int w,h;
float fh,fw,f;
float invcutx = 1.0 / (2.0*(float)(spacing)*outwidth);
float invcuty = 1.0 / (2.0*(float)(spacing)*height);
for (h=0; h < height/2; h++) {
{
fh = float(h)*invcuty;
fh *= fh;
for (w = 0; w < outwidth; w++) {
fw = float(w)*invcutx;
fw *= fw;
f = 1/(1 + fh + fw);
outp[w][0] *= f;
outp[w][1] *= f;
}
}
outp += outwidth;
}
for (h=height/2; h < height; h++) {
{
fh = float(height-h-1)*invcuty;
fh *= fh;
for (w = 0; w < outwidth; w++) {
fw = float(w)*invcutx;
fw *= fw;
f = 1/(1 + fh + fw);
outp[w][0] *= f;
outp[w][1] *= f;
}
}
outp += outwidth;
}
}