From 1f682d3407525440e4d334dcbe12caee43c1de70 Mon Sep 17 00:00:00 2001 From: Richard Zhao Date: Wed, 26 Apr 2017 17:35:22 -0400 Subject: [PATCH] Remove backward flows from source code (cmd line arg still exists) --- src/oflow.cpp | 43 ++---------------------- src/oflow.h | 2 -- src/patchgrid.cpp | 86 ----------------------------------------------- src/patchgrid.h | 4 --- src/run_dense.cpp | 2 +- 5 files changed, 3 insertions(+), 134 deletions(-) diff --git a/src/oflow.cpp b/src/oflow.cpp index aab088c..95fb9ea 100644 --- a/src/oflow.cpp +++ b/src/oflow.cpp @@ -46,7 +46,6 @@ namespace OFC const float res_thresh_in, const int p_samp_s_in, const float patove_in, - const bool usefbcon_in, const int costfct_in, const int noc_in, const int patnorm_in, @@ -87,7 +86,6 @@ namespace OFC op.res_thresh = res_thresh_in; op.steps = std::max(1, (int)floor(op.p_samp_s*(1-op.patove))); op.novals = noc_in * (p_samp_s_in)*(p_samp_s_in); - op.usefbcon = usefbcon_in; op.costfct = costfct_in; op.noc = noc_in; op.patnorm = patnorm_in; @@ -124,12 +122,9 @@ namespace OFC if (op.verbosity>1) gettimeofday(&tv_start_all, nullptr); - // Create grids on each scale vector grid_fw(op.noscales); - vector grid_bw(op.noscales); // grid for backward OF computation, only needed if 'usefbcon' is set to 1. vector flow_fw(op.noscales); - vector flow_bw(op.noscales); cpl.resize(op.noscales); cpr.resize(op.noscales); for (int sl=op.sc_f; sl>=op.sc_l; --sl) @@ -156,15 +151,6 @@ namespace OFC flow_fw[i] = new float[op.nop * cpl[i].width * cpl[i].height]; grid_fw[i] = new OFC::PatGridClass(&(cpl[i]), &(cpr[i]), &op); - if (op.usefbcon) // for merging forward and backward flow - { - flow_bw[i] = new float[op.nop * cpr[i].width * cpr[i].height]; - grid_bw[i] = new OFC::PatGridClass(&(cpr[i]), &(cpl[i]), &op); - - // Make grids known to each other, necessary for AggregateFlowDense(); - grid_fw[i]->SetComplGrid( grid_bw[i] ); - grid_bw[i]->SetComplGrid( grid_fw[i] ); - } } @@ -187,11 +173,6 @@ namespace OFC // Initialize grid (Step 1 in Algorithm 1 of paper) grid_fw[ii]-> InitializeGrid(im_ao[sl], im_ao_dx[sl], im_ao_dy[sl]); grid_fw[ii]-> SetTargetImage(im_bo[sl], im_bo_dx[sl], im_bo_dy[sl]); - if (op.usefbcon) - { - grid_bw[ii]->InitializeGrid(im_bo[sl], im_bo_dx[sl], im_bo_dy[sl]); - grid_bw[ii]->SetTargetImage(im_ao[sl], im_ao_dx[sl], im_ao_dy[sl]); - } // Timing, Grid construction if (op.verbosity>1) @@ -206,10 +187,6 @@ namespace OFC if (sl < op.sc_f) { grid_fw[ii]->InitializeFromCoarserOF(flow_fw[ii+1]); // initialize from flow at previous coarser scale - - // Initialize backward flow - if (op.usefbcon) - grid_bw[ii]->InitializeFromCoarserOF(flow_bw[ii+1]); } else if (sl == op.sc_f && initflow != nullptr) // initialization given input flow { @@ -228,9 +205,6 @@ namespace OFC // Dense Inverse Search. (Step 3 in Algorithm 1 of paper) grid_fw[ii]->Optimize(); - if (op.usefbcon) - grid_bw[ii]->Optimize(); - // Timing, DIS if (op.verbosity>1) @@ -250,9 +224,6 @@ namespace OFC grid_fw[ii]->AggregateFlowDense(tmp_ptr); - if (op.usefbcon && sl > op.sc_l ) // skip at last scale, backward flow no longer needed - grid_bw[ii]->AggregateFlowDense(flow_bw[ii]); - // Timing, Densification if (op.verbosity>1) @@ -269,13 +240,8 @@ namespace OFC if (op.usetvref) { OFC::VarRefClass varref_fw(im_ao[sl], im_ao_dx[sl], im_ao_dy[sl], - im_bo[sl], im_bo_dx[sl], im_bo_dy[sl] - ,&(cpl[ii]), &(cpr[ii]), &op, tmp_ptr); - - if (op.usefbcon && sl > op.sc_l ) // skip at last scale, backward flow no longer needed - OFC::VarRefClass varref_bw(im_bo[sl], im_bo_dx[sl], im_bo_dy[sl], - im_ao[sl], im_ao_dx[sl], im_ao_dy[sl] - ,&(cpr[ii]), &(cpl[ii]), &op, flow_bw[ii]); + im_bo[sl], im_bo_dx[sl], im_bo_dy[sl], + &(cpl[ii]), &(cpr[ii]), &op, tmp_ptr); } // Timing, Variational Refinement @@ -296,11 +262,6 @@ namespace OFC delete[] flow_fw[sl-op.sc_l]; delete grid_fw[sl-op.sc_l]; - if (op.usefbcon) - { - delete[] flow_bw[sl-op.sc_l]; - delete grid_bw[sl-op.sc_l]; - } } diff --git a/src/oflow.h b/src/oflow.h index 964c59d..8efca09 100644 --- a/src/oflow.h +++ b/src/oflow.h @@ -41,7 +41,6 @@ typedef struct float res_thresh; // if (mean absolute) residual falls below this threshold, terminate iterations on current scale, IGNORES MIN_ITER , SET TO LOW (1e-10) TO DISABLE int patnorm; // Use patch mean-normalization int verbosity; // Verbosity, 0: plot nothing, 1: final internal timing 2: complete iteration timing, (UNCOMMENTED -> 3: Display flow scales, 4: Display flow scale iterations) - bool usefbcon; // use forward-backward flow merging int costfct; // Cost function: 0: L2-Norm, 1: L1-Norm, 2: PseudoHuber-Norm bool usetvref; // TV parameters float tv_alpha; @@ -97,7 +96,6 @@ class OFClass const float res_thresh_in, const int padval_in, const float patove_in, - const bool usefbcon_in, const int costfct_in, const int noc_in, const int patnorm_in, diff --git a/src/patchgrid.cpp b/src/patchgrid.cpp index 2272a51..953996d 100644 --- a/src/patchgrid.cpp +++ b/src/patchgrid.cpp @@ -84,12 +84,6 @@ namespace OFC delete pat[i]; } - void PatGridClass::SetComplGrid(PatGridClass *cg_in) - { - cg = cg_in; - } - - void PatGridClass::InitializeGrid(const float * im_ao_in, const float * im_ao_dx_in, const float * im_ao_dy_in) { im_ao = im_ao_in; @@ -249,86 +243,6 @@ namespace OFC } } - // if complementary (forward-backward merging) is given, integrate negative backward flow as well - if (cg) - { - Eigen::Vector4f wbil; // bilinear weight vector - Eigen::Vector4i pos; - -#ifdef USE_PARALLEL_ON_FLOWAGGR -#pragma omp parallel for schedule(static) -#endif - for (int ip = 0; ip < cg->nopatches; ++ip) - { - if (cg->pat[ip]->IsValid()) - { - const Eigen::Vector2f* fl = (cg->pat[ip]->GetParam()); // flow displacement of this patch - Eigen::Vector2f flnew; - - const Eigen::Vector2f rppos = cg->pat[ip]->GetPointPos(); // get patch position after optimization - const float * pweight = cg->pat[ip]->GetpWeightPtr(); // use image error as weight - - Eigen::Vector2f resid; - - // compute bilinear weight vector - pos[0] = ceil(rppos[0] +.00001); // make sure they are rounded up to natural number - pos[1] = ceil(rppos[1] +.00001); // make sure they are rounded up to natural number - pos[2] = floor(rppos[0]); - pos[3] = floor(rppos[1]); - - resid[0] = rppos[0] - pos[2]; - resid[1] = rppos[1] - pos[3]; - wbil[0] = resid[0]*resid[1]; - wbil[1] = (1-resid[0])*resid[1]; - wbil[2] = resid[0]*(1-resid[1]); - wbil[3] = (1-resid[0])*(1-resid[1]); - - int lb = -op->p_samp_s/2; - int ub = op->p_samp_s/2-1; - - - for (int y = lb; y <= ub; ++y) - { - for (int x = lb; x <= ub; ++x, ++pweight) - { - - int yt = y + pos[1]; - int xt = x + pos[0]; - if (xt >= 1 && yt >= 1 && xt < (cpt->width-1) && yt < (cpt->height-1)) - { - - float absw = 1.0f / (float)(std::max(op->minerrval ,*pweight)); - - flnew = (*fl) * absw; - - int idxcc = xt + yt *cpt->width; - int idxfc = (xt-1) + yt *cpt->width; - int idxcf = xt + (yt-1)*cpt->width; - int idxff = (xt-1) + (yt-1)*cpt->width; - - we[idxcc] += wbil[0] * absw; - we[idxfc] += wbil[1] * absw; - we[idxcf] += wbil[2] * absw; - we[idxff] += wbil[3] * absw; - - flowout[2*idxcc ] -= wbil[0] * flnew[0]; // use reversed flow - flowout[2*idxcc+1] -= wbil[0] * flnew[1]; - - flowout[2*idxfc ] -= wbil[1] * flnew[0]; - flowout[2*idxfc+1] -= wbil[1] * flnew[1]; - - flowout[2*idxcf ] -= wbil[2] * flnew[0]; - flowout[2*idxcf+1] -= wbil[2] * flnew[1]; - - flowout[2*idxff ] -= wbil[3] * flnew[0]; - flowout[2*idxff+1] -= wbil[3] * flnew[1]; - } - } - } - } - } - } - #pragma omp parallel for schedule(static, 100) // normalize each pixel by dividing displacement by aggregated weights from all patches for (int yi = 0; yi < cpt->height; ++yi) diff --git a/src/patchgrid.h b/src/patchgrid.h index a8af4f1..d50b1d2 100644 --- a/src/patchgrid.h +++ b/src/patchgrid.h @@ -33,8 +33,6 @@ namespace OFC //Optimize each patch in grid for one iteration, visualize displacement vector, repeat //void OptimizeAndVisualize(const float sc_fct_tmp); // needed for verbosity >= 3, DISVISUAL - void SetComplGrid(PatGridClass *cg_in); - inline const int GetNoPatches() const { return nopatches; } inline const int GetNoph() const { return noph; } inline const int GetNopw() const { return nopw; } @@ -63,8 +61,6 @@ namespace OFC std::vector pat; // Patch Objects std::vector pt_ref; // Midpoints for reference patches std::vector p_init; // starting parameters for query patches - - const PatGridClass * cg=nullptr; }; diff --git a/src/run_dense.cpp b/src/run_dense.cpp index 39db4f5..e2c039b 100644 --- a/src/run_dense.cpp +++ b/src/run_dense.cpp @@ -324,7 +324,7 @@ int main( int argc, char** argv ) nullptr, // pointer to n-band input float array of size of first (coarsest) scale, pass as nullptr to disable sz.width, sz.height, lv_f, lv_l, maxiter, miniter, mindprate, mindrrate, minimgerr, patchsz, poverl, - usefbcon, costfct, nochannels, patnorm, + costfct, nochannels, patnorm, usetvref, tv_alpha, tv_gamma, tv_delta, tv_innerit, tv_solverit, tv_sor, verbosity);