Skip to content

Commit

Permalink
Remove backward flows from source code (cmd line arg still exists)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Zhao committed Apr 26, 2017
1 parent b188a12 commit 1f682d3
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 134 deletions.
43 changes: 2 additions & 41 deletions src/oflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -124,12 +122,9 @@ namespace OFC

if (op.verbosity>1) gettimeofday(&tv_start_all, nullptr);


// Create grids on each scale
vector<OFC::PatGridClass*> grid_fw(op.noscales);
vector<OFC::PatGridClass*> grid_bw(op.noscales); // grid for backward OF computation, only needed if 'usefbcon' is set to 1.
vector<float*> flow_fw(op.noscales);
vector<float*> flow_bw(op.noscales);
cpl.resize(op.noscales);
cpr.resize(op.noscales);
for (int sl=op.sc_f; sl>=op.sc_l; --sl)
Expand All @@ -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] );
}
}


Expand All @@ -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)
Expand All @@ -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
{
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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];
}
}


Expand Down
2 changes: 0 additions & 2 deletions src/oflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
86 changes: 0 additions & 86 deletions src/patchgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions src/patchgrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -63,8 +61,6 @@ namespace OFC
std::vector<OFC::PatClass*> pat; // Patch Objects
std::vector<Eigen::Vector2f> pt_ref; // Midpoints for reference patches
std::vector<Eigen::Vector2f> p_init; // starting parameters for query patches

const PatGridClass * cg=nullptr;
};


Expand Down
2 changes: 1 addition & 1 deletion src/run_dense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 1f682d3

Please sign in to comment.