/* Copyright (C) 2004 Caltech Written by Lexing Ying */ #include "fdct_wrapping.hpp" #include "fdct_wrapping_inline.hpp" FDCT_WRAPPING_NS_BEGIN_NAMESPACE int fdct_wrapping_invsepangle(double XL1, double XL2, int nbangle, vector& csc, CpxOffMat& Xhgh); int fdct_wrapping_invwavelet(vector& csc, CpxOffMat& Xhgh); //------------------------------------------------------------------------------- int ifdct_wrapping(int N1, int N2, int nbscales, int nbangles_coarse, int allcurvelets, vector< vector >& c, CpxNumMat& x) { assert(nbscales==c.size() && nbangles_coarse==c[1].size()); int F1 = N1/2; int F2 = N2/2; //-------------------------------------------angles to Xhgh vector nbangles(nbscales); vector Xhghs; Xhghs.resize(nbscales); if(allcurvelets==1) { //---- nbangles[0] = 1; for(int sc=1; sc0; sc--) { fdct_wrapping_invsepangle(XL1, XL2, nbangles[sc], c[sc], Xhghs[sc]); XL1 /= 2; XL2 /= 2; } fdct_wrapping_invwavelet(c[0], Xhghs[0]); } else { //---- nbangles[0] = 1; for(int sc=1; sc0; sc--) { fdct_wrapping_invsepangle(XL1, XL2, nbangles[sc], c[sc], Xhghs[sc]); XL1 /= 2; XL2 /= 2; } fdct_wrapping_invwavelet(c[0], Xhghs[0]); } //-------------------------------------------xhghs to O //combine CpxOffMat X; if(allcurvelets==1) { double XL1 = 4.0*N1/3.0; double XL2 = 4.0*N2/3.0; //range int XS1, XS2; int XF1, XF2; double XR1, XR2; fdct_wrapping_rangecompute(XL1, XL2, XS1, XS2, XF1, XF2, XR1, XR2); X.resize(XS1, XS2); } else { X.resize(N1, N2); } double XL1 = 4.0*N1/3.0; double XL2 = 4.0*N2/3.0; int XS1, XS2; int XF1, XF2; double XR1, XR2; fdct_wrapping_rangecompute(XL1, XL2, XS1, XS2, XF1, XF2, XR1, XR2); for(int sc=nbscales-1; sc>0; sc--) { double XL1n = XL1/2; double XL2n = XL2/2; int XS1n, XS2n; int XF1n, XF2n; double XR1n, XR2n; fdct_wrapping_rangecompute(XL1n, XL2n, XS1n, XS2n, XF1n, XF2n, XR1n, XR2n); DblOffMat lowpass(XS1n, XS2n); fdct_wrapping_lowpasscompute(XL1n, XL2n, lowpass); DblOffMat hghpass(XS1n, XS2n); for(int j=-XF2n; j<-XF2n+XS2n; j++) for(int i=-XF1n; i<-XF1n+XS1n; i++) hghpass(i,j) = sqrt(1-lowpass(i,j)*lowpass(i,j)); for(int j=-XF2n; j<-XF2n+XS2n; j++) for(int i=-XF1n; i<-XF1n+XS1n; i++) Xhghs[sc](i,j) *= hghpass(i,j); for(int j=-XF2n; j<-XF2n+XS2n; j++) for(int i=-XF1n; i<-XF1n+XS1n; i++) Xhghs[sc-1](i,j) *= lowpass(i,j); CpxOffMat& G = Xhghs[sc]; for(int j=G.t(); j(N1-1)/2) t1(i) = i-int(N1); else t1(i) = i; IntOffVec t2(XS2); for(int i=-XF2; i<-XF2+XS2; i++) if( i<-N2/2) t2(i) = i+int(N2); else if(i>(N2-1)/2) t2(i) = i-int(N2); else t2(i) = i; for(int j=-XF2; j<-XF2+XS2; j++) for(int i=-XF1; i<-XF1+XS1; i++) O(t1(i), t2(j)) += X(i,j); } else { O = X; } //------------------------------------------------------------ CpxNumMat T(N1,N2); fdct_wrapping_ifftshift(O, T); fftwnd_plan p = fftw2d_create_plan(N2, N1, FFTW_BACKWARD, FFTW_ESTIMATE | FFTW_IN_PLACE); fftwnd_one(p, (fftw_complex*)T.data(), NULL); fftwnd_destroy_plan(p); double sqrtprod = sqrt(double(N1*N2)); //scale for(int i=0; i& csc, CpxOffMat& Xhgh) { typedef pair intpair; map planmap; int XS1, XS2; int XF1, XF2; double XR1, XR2; fdct_wrapping_rangecompute(XL1, XL2, XS1, XS2, XF1, XF2, XR1, XR2); Xhgh.resize(XS1, XS2); int nbquadrants = 4; int nd = nbangle / 4; int wcnt = 0; //backup CpxOffMat Xhghb(Xhgh); double XL1b = XL1; double XL2b = XL2; int qvec[] = {2,1,0,3}; for(int qi=0; qi=0; w--) { double xs = XR1/4 - (XW1/2)/4; double xe = XR1; double ys = -XR2 + (w-0.5)*XW2; double ye = -XR2 + (w+1.5)*XW2; //x range int xn = int(ceil(xe-xs)); int yn = int(ceil(ye-ys)); //MAKE THEM ODD if(xn%2==0) xn++; if(yn%2==0) yn++; int xf = int(ceil(xs)); //int yf = int(ceil(ys)); //theta double thts, thtm, thte; //y direction if(w==0) { thts = atan2(-1.0, 1.0-1.0/nd); thtm = atan2(-1.0+1.0/nd, 1.0); thte = atan2(-1.0+3.0/nd, 1.0); } else if(w==nd-1) { thts = atan2(-1.0+(2.0*w-1.0)/nd, 1.0); thtm = atan2(-1.0+(2.0*w+1.0)/nd, 1.0); thte = atan2(1.0, 1.0-1.0/nd); } else { thts = atan2(-1.0+(2.0*w-1.0)/nd, 1.0); thtm = atan2(-1.0+(2.0*w+1.0)/nd, 1.0); thte = atan2(-1.0+(2.0*w+3.0)/nd, 1.0); } int xh = xn/2; int yh = yn/2; //half length CpxOffMat wpdata(xn,yn); { //load int xn = csc[wcnt].m(); int yn = csc[wcnt].n(); CpxNumMat tpdata(csc[wcnt]); //fft fftwnd_plan p = NULL; map::iterator mit=planmap.find( intpair(xn,yn) ); if(mit!=planmap.end()) { p = (*mit).second; } else { p = fftw2d_create_plan(yn, xn, FFTW_FORWARD, FFTW_ESTIMATE | FFTW_IN_PLACE); planmap[ intpair(xn, yn) ] = p; } fftwnd_one(p, (fftw_complex*)tpdata.data(), NULL); double sqrtprod = sqrt(double(xn*yn)); for(int i=0; i=-xh+xn) tmpx-=xn; int tmpy = ycur%yn; if(tmpy<-yh) tmpy+=yn; if(tmpy>=-yh+yn) tmpy-=yn; //partition of unity double thtcur = atan2(ycur/XR2, xcur/XR1); double wtht; if(thtcur::iterator mit=planmap.begin(); mit!=planmap.end(); mit++) { fftwnd_plan p = (*mit).second; fftwnd_destroy_plan(p); } return 0; } //--------------------- int fdct_wrapping_invwavelet(vector& csc, CpxOffMat& Xhgh) { assert(csc.size()==1); CpxNumMat& C = csc[0]; int N1 = C.m(); int N2 = C.n(); CpxNumMat T(C); //CpxNumMat T(N1, N2); fdct_wrapping_ifftshift(N1, N2, F1, F2, C, T); fftwnd_plan p = fftw2d_create_plan(N2, N1, FFTW_FORWARD, FFTW_ESTIMATE | FFTW_IN_PLACE); fftwnd_one(p, (fftw_complex*)T.data(), NULL); fftwnd_destroy_plan(p); double sqrtprod = sqrt(double(N1*N2)); for(int j=0; j