c++ - fftw shift zero-frequency to image center -
i struggling on result of fftw applied on image.
i can fourier transform , inverse fourier transform on image, sure 2 functions working. trying analyze result of fourier transform , try apply filter on it, etc.
currently confusing on ft result. know the zero-frequency should on top-left corner. should shift image center if want check frequency friendly. there @ least 2 way have tested. 1 method described on fftw faq webpage, pixels in image multiplied (-1)^(i + j) before fourier transform, i, , j pixel's index.
image multiplied (-1)^(i+j), magnitude is
but ,it should (which did in imagej) fourier transform in imagej:

i tried using code switch them after calculating magnitude, got similar wrong result.
void ftshift2d(double * d, int w, int h) { int nw = w/2; int nh = h/2; if ( w%2 != 0) {nw++;} if ( h%2 != 0) {nh++;} printf("%d, %d\n", nw, nh); (int = 0; < nh ; i++) { for(int j = 0; j < nw; j++) { int t1 = * w + j; int t2 = (i + nh + 1) * w + j + nw; swapxy<double>(d[t1], d[t2]); } (int k = nw; k < w; k++) { int t1 = * w + k; int t2 = (i + nh + 1 ) * w + k - nw; swapxy<double>(d[t1], d[t2]); } } } i understood layout of ft result in fftw, described in website. checked output, layout can confirmed, top half have data, rest 0. therefore, seems explain why 2 methods used above cannot work. trying design new method shift zero-frequency image center. give me better way it?
i insist on this, aim use filter, easier understand. if zero-frequency did not shifted center, guys give me suggestion can, example, apply high gaussian filter on in frequency domain.
thanks lot.
the input image is:
the ft , ift code are
void imgr2c(double * d, fftw_complex * df, int w, int h) { fftw_plan p = fftw_plan_dft_r2c_2d(h, w, d, df, fftw_estimate); fftw_execute(p); fftw_destroy_plan(p); } void imgc2r(fftw_complex * in, double * ftreverse, int w, int h) { fftw_plan p = fftw_plan_dft_c2r_2d(h, w, in, ftreverse, fftw_estimate); fftw_execute(p); int l = w * h; (int = 0; < l; i++) { ftreverse[i] /= l; } fftw_destroy_plan(p); } [edit spektre]
this how should more or less like:
you may want check out how did here: https://github.com/kvahed/codeare/blob/master/src/matrix/ft/dft.hpp functions doing job @ bottom. if there issues, feel free contact me personally.


Comments
Post a Comment