From db4de44e30f86f952a213b684729032aab1b5e57 Mon Sep 17 00:00:00 2001 From: Emil Martinec Date: Tue, 27 Jul 2010 12:11:50 -0500 Subject: [PATCH] Minor bugfix for AMaZE, highlight recovery issue is not addressed. --- rtengine/amaze_interpolate_RT.cc | 99 ++++++++++++-------------------- 1 file changed, 37 insertions(+), 62 deletions(-) diff --git a/rtengine/amaze_interpolate_RT.cc b/rtengine/amaze_interpolate_RT.cc index d7d66a631..fc3af8a95 100644 --- a/rtengine/amaze_interpolate_RT.cc +++ b/rtengine/amaze_interpolate_RT.cc @@ -69,7 +69,7 @@ void RawImageSource::amaze_demosaic_RT() { static const float eps=1e-5, epssq=1e-10; //tolerance to avoid dividing by zero //adaptive ratios threshold - static const float arthresh=0.75; + static const float arthresh=-0.75; //nyquist texture test threshold static const float nyqthresh=0.5; //diagonal interpolation test threshold @@ -162,7 +162,7 @@ void RawImageSource::amaze_demosaic_RT() { // assign working space buffer = (char *) malloc((34*sizeof(float)+sizeof(int))*TS*TS); //merror(buffer,"amaze_interpolate()"); - memset(buffer,0,(34*sizeof(float)+sizeof(int))*TS*TS); + //memset(buffer,0,(34*sizeof(float)+sizeof(int))*TS*TS); // rgb array rgb = (float (*)[3]) buffer; //pointers to array delh = (float (*)) (buffer + 3*sizeof(float)*TS*TS); @@ -195,7 +195,7 @@ void RawImageSource::amaze_demosaic_RT() { rbp = (float (*)) (buffer + 32*sizeof(float)*TS*TS); rbm = (float (*)) (buffer + 33*sizeof(float)*TS*TS); - nyquist = (int (*)) (buffer + 34*sizeof(float)*TS*TS); + nyquist = (int (*)) (buffer + 34*sizeof(int)*TS*TS); // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -539,10 +539,10 @@ void RawImageSource::amaze_demosaic_RT() { rbint[indx]=0; //color ratios in each cardinal direction - cru = cfa[indx-v1]*(dirwts[indx-v2][0]+dirwts[indx][0])/(eps+dirwts[indx-v2][0]*cfa[indx]+dirwts[indx][0]*cfa[indx-v2]); - crd = cfa[indx+v1]*(dirwts[indx+v2][0]+dirwts[indx][0])/(eps+dirwts[indx+v2][0]*cfa[indx]+dirwts[indx][0]*cfa[indx+v2]); - crl = cfa[indx-1]*(dirwts[indx-2][1]+dirwts[indx][1])/(eps+dirwts[indx-2][1]*cfa[indx]+dirwts[indx][1]*cfa[indx-2]); - crr = cfa[indx+1]*(dirwts[indx+2][1]+dirwts[indx][1])/(eps+dirwts[indx+2][1]*cfa[indx]+dirwts[indx][1]*cfa[indx+2]); + cru = cfa[indx-v1]*(dirwts[indx-v2][0]+dirwts[indx][0])/(dirwts[indx-v2][0]*(eps+cfa[indx])+dirwts[indx][0]*(eps+cfa[indx-v2])); + crd = cfa[indx+v1]*(dirwts[indx+v2][0]+dirwts[indx][0])/(dirwts[indx+v2][0]*(eps+cfa[indx])+dirwts[indx][0]*(eps+cfa[indx+v2])); + crl = cfa[indx-1]*(dirwts[indx-2][1]+dirwts[indx][1])/(dirwts[indx-2][1]*(eps+cfa[indx])+dirwts[indx][1]*(eps+cfa[indx-2])); + crr = cfa[indx+1]*(dirwts[indx+2][1]+dirwts[indx][1])/(dirwts[indx+2][1]*(eps+cfa[indx])+dirwts[indx][1]*(eps+cfa[indx+2])); guha=cfa[indx-v1]+0.5*(cfa[indx]-cfa[indx-v2]); gdha=cfa[indx+v1]+0.5*(cfa[indx]-cfa[indx+v2]); @@ -571,6 +571,13 @@ void RawImageSource::amaze_demosaic_RT() { //differences of interpolations in opposite directions dgintv[indx]=MIN(SQR(guha-gdha),SQR(guar-gdar)); dginth[indx]=MIN(SQR(glha-grha),SQR(glar-grar)); + + //dgintv[indx]=SQR(guar-gdar); + //dginth[indx]=SQR(glar-grar); + + //vcdsq[indx] = SQR(vcd[indx]); + //hcdsq[indx] = SQR(hcd[indx]); + //cddiffsq[indx] = SQR(vcd[indx]-hcd[indx]); } //t2_vcdhcd += clock() - t1_vcdhcd; @@ -653,16 +660,22 @@ void RawImageSource::amaze_demosaic_RT() { //compute color difference variances in cardinal directions + Dgrbvvaru = 4*(vcdsq[indx]+vcdsq[indx-v1]+vcdsq[indx-v2]+vcdsq[indx-v3])-SQR(vcd[indx]+vcd[indx-v1]+vcd[indx-v2]+vcd[indx-v3]); Dgrbvvard = 4*(vcdsq[indx]+vcdsq[indx+v1]+vcdsq[indx+v2]+vcdsq[indx+v3])-SQR(vcd[indx]+vcd[indx+v1]+vcd[indx+v2]+vcd[indx+v3]); Dgrbhvarl = 4*(hcdsq[indx]+hcdsq[indx-1]+hcdsq[indx-2]+hcdsq[indx-3])-SQR(hcd[indx]+hcd[indx-1]+hcd[indx-2]+hcd[indx-3]); Dgrbhvarr = 4*(hcdsq[indx]+hcdsq[indx+1]+hcdsq[indx+2]+hcdsq[indx+3])-SQR(hcd[indx]+hcd[indx+1]+hcd[indx+2]+hcd[indx+3]); - + + hwt = dirwts[indx-1][1]/(dirwts[indx-1][1]+dirwts[indx+1][1]); vwt = dirwts[indx-v1][0]/(dirwts[indx+v1][0]+dirwts[indx-v1][0]); - + vcdvar = epssq+vwt*Dgrbvvard+(1-vwt)*Dgrbvvaru; hcdvar = epssq+hwt*Dgrbhvarr+(1-hwt)*Dgrbhvarl; + + //vcdvar = 5*(vcdsq[indx]+vcdsq[indx-v1]+vcdsq[indx-v2]+vcdsq[indx+v1]+vcdsq[indx+v2])-SQR(vcd[indx]+vcd[indx-v1]+vcd[indx-v2]+vcd[indx+v1]+vcd[indx+v2]); + //hcdvar = 5*(hcdsq[indx]+hcdsq[indx-1]+hcdsq[indx-2]+hcdsq[indx+1]+hcdsq[indx+2])-SQR(hcd[indx]+hcd[indx-1]+hcd[indx-2]+hcd[indx+1]+hcd[indx+2]); + //compute fluctuations in up/down and left/right interpolations of colors Dgrbvvaru = (dgintv[indx])+(dgintv[indx-v1])+(dgintv[indx-v2]); @@ -680,6 +693,8 @@ void RawImageSource::amaze_demosaic_RT() { //if both agree on interpolation direction, choose the one with strongest directional discrimination; //otherwise, choose the u/d and l/r difference fluctuation weights if ((0.5-varwt)*(0.5-diffwt)>0 && fabs(0.5-diffwt)0.75) hvwt[indx]=1.0; + Dgrb[indx][0] = (hcd[indx]*(1-hvwt[indx]) + vcd[indx]*hvwt[indx]);//evaluate color differences rgb[indx][1] = cfa[indx] + Dgrb[indx][0];//evaluate G (finally!) @@ -825,51 +844,6 @@ void RawImageSource::amaze_demosaic_RT() { // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // diagonal interpolation correction - /*for (rr=8; rr3) pmwt[indx]=1; - //or not - if (areawt<2) pmwt[indx]=0; - }*/ for (rr=8; rr