--- src/robertson02.cpp.orig Thu Mar 16 12:22:46 2006 +++ src/robertson02.cpp Thu Jun 21 14:34:34 2007 @@ -50,7 +50,7 @@ float normalizeI( float* I, int M ); -void robertson02_applyResponse( pfs::Array2D* xj, const ExposureList &imgs, +int robertson02_applyResponse( pfs::Array2D* xj, const ExposureList &imgs, const float* I, const float* w, int M ) { // number of exposures @@ -59,6 +59,58 @@ // frame size int width = xj->getCols(); int height = xj->getRows(); + + // number of saturated pixels + int saturated_pixels = 0; + + // --- anti saturation: calculate trusted camera output range + int minM = 0; + for( int m=0 ; m0 ) + { + minM = m; + break; + } + int maxM = M-1; + for( int m=M-1 ; m>=0 ; m-- ) + if( w[m]>0 ) + { + maxM = m; + break; + } + + // --- anti ghosting: for each image i, find images with + // the immediately higher and lower exposure times + int* i_lower = new int[N]; + int* i_upper = new int[N]; + for( int i=0 ; iti && imgs[j].titi_lower ) + { + ti_lower=imgs[j].ti; + i_lower[i]=j; + } + } + if( i_lower[i]==-1 ) + i_lower[i]=i; + if( i_upper[i]==-1 ) + i_upper[i]=i; + } + // all pixels for( int j=0 ; jmaxM ) + minti = fminf(minti,ti); + if( mm || m_upper-1e6f ) + { + sum = I[minM]; + div = maxti; + } + if( div==0.0f && minti<+1e6f ) + { + sum = I[maxM]; + div = minti; + } + if( div!=0.0f ) (*xj)(j) = sum/div; else (*xj)(j) = 0.0f; } + + delete[] i_lower; + delete[] i_upper; + + return saturated_pixels; } -void robertson02_getResponse( pfs::Array2D* xj, const ExposureList &imgs, +int robertson02_getResponse( pfs::Array2D* xj, const ExposureList &imgs, float* I, const float* w, int M ) { // number of exposures @@ -105,6 +185,9 @@ int width = imgs[0].yi->getCols(); int height = imgs[0].yi->getRows(); + // number of saturated pixels + int saturated_pixels = 0; + // indexes int i,j,m; @@ -160,7 +243,7 @@ float middle_response = normalizeI( I, M ); // 3. Apply new response - robertson02_applyResponse( xj, imgs, I, w, M ); + saturated_pixels = robertson02_applyResponse( xj, imgs, I, w, M ); // 4. Check stopping condition float delta = 0.0f; @@ -198,6 +281,8 @@ delete[] Ip; delete[] cardEm; delete[] sum; + + return saturated_pixels; }