void VerifCorrelCNC ( Pt2di aDec, bool Pondered, Im2D_REAL8 aCPad, REAL anEps, Im2D_REAL8 aCNC, REAL aRatioSurf ) { REAL aS_CorFFT = ImCorrFromNrFFT(aCPad,aDec); REAL aS,aS1,aS2,aS11,aS12,aS22; Symb_FNum aP ( Pondered ? trans(mPds1.in(0),aDec)*mPds2.in(0) : trans(mIm1.inside(),aDec) ); Symb_FNum aF1 (trans(mIm1.in(0),aDec)); Symb_FNum aF2 (mIm2.in(0)); ELISE_COPY ( mIm1.all_pts(), Virgule ( 1,aF1,aF2, aF1*aF1,aF1*aF2,aF2*aF2 )*aP, Virgule ( Virgule(sigma(aS) ,sigma(aS1) ,sigma(aS2)), Virgule(sigma(aS11),sigma(aS12),sigma(aS22)) ) ); if (! Pondered) BENCH_ASSERT(std::abs(aS12-aS_CorFFT )<epsilon); aS = std::max(aS,anEps); aS1 /= aS; aS2 /= aS; aS11 = aS11/aS - aS1 * aS1 ; aS12 = aS12/aS - aS1 * aS2 ; aS22 = aS22/aS - aS2 * aS2 ; REAL aCor = aS12 / sqrt(std::max(anEps,aS11*aS22)); if (aS<aRatioSurf) { aCor = -1 + (aCor+1) * (aS/aRatioSurf); } REAL aNCCorFFT = ImCorrFromNrFFT(aCNC,aDec); BENCH_ASSERT(std::abs(aCor-aNCCorFFT)<epsilon); }
cBenchCorrel (Pt2di aSz) : mIm1(aSz.x,aSz.y), mDup1(aSz.x,aSz.y), mPds1(aSz.x,aSz.y), mIm2(aSz.x,aSz.y), mDup2(aSz.x,aSz.y), mPds2(aSz.x,aSz.y) { ELISE_COPY(mIm1.all_pts(),frandr(),mIm1.out()|mDup1.out()); ELISE_COPY(mIm2.all_pts(),frandr(),mIm2.out()|mDup2.out()); ELISE_COPY(mIm1.all_pts(),frandr(),mPds1.out()); ELISE_COPY(mIm1.all_pts(),frandr(),mPds2.out()); ElFFTCorrelCirc(mDup1,mDup2); Im2D_REAL8 aCPad = ElFFTCorrelPadded(mIm1, mIm2); REAL anEps = (1+10*NRrandom3()) * 1e-2; REAL aRatioSurf = aSz.x * aSz.y * (1+NRrandom3()) / 6.0; Im2D_REAL8 aCNC = ElFFTCorrelNCPadded(mIm1, mIm2,anEps,aRatioSurf); Im2D_REAL8 aPdsCNC = ElFFTPonderedCorrelNCPadded ( mIm1.in(), mIm2.in(), aSz, mPds1.in(), mPds2.in(), anEps, aRatioSurf ); for (INT x =-1 ; x<= aSz.x ; x++) { for (INT y =-1 ; y<= aSz.y ; y++) { REAL aSElise; ELISE_COPY ( mIm1.all_pts(), mIm1.in()[Virgule(mod(FX+x,aSz.x),mod(FY+y,aSz.y))] * mIm2.in(), sigma(aSElise) ); REAL aSFFT = mDup1.data()[mod(y,aSz.y)][mod(x,aSz.x)]; BENCH_ASSERT(std::abs(aSElise-aSFFT)<epsilon); Pt2di aDec(x,y); VerifCorrelCNC(aDec,false,aCPad, anEps,aCNC,aRatioSurf); VerifCorrelCNC(aDec,true,aCPad, anEps,aPdsCNC,aRatioSurf); } } }