From 76d45ed4d1c22ff73afa26c3f08524516de52f7e Mon Sep 17 00:00:00 2001 From: Richard Zhao Date: Fri, 12 May 2017 02:15:05 +0000 Subject: [PATCH] Remove opticalflow_aux --- src/CMakeLists.txt | 3 - src/FDF1.0.1/opticalflow_aux.cpp | 115 ------------------------------- src/FDF1.0.1/opticalflow_aux.h | 35 ---------- src/kernels/flowUtil.cu | 66 ++++++++++++++++++ src/kernels/flowUtil.h | 10 +++ src/refine_variational.cpp | 15 ++-- src/refine_variational.h | 1 - 7 files changed, 84 insertions(+), 161 deletions(-) delete mode 100644 src/FDF1.0.1/opticalflow_aux.cpp delete mode 100644 src/FDF1.0.1/opticalflow_aux.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04128e1..0802f74 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -96,12 +96,9 @@ set(COMMON set(CODEFILES run_dense.cpp oflow.cpp - # patch.cpp patchgrid.cpp refine_variational.cpp - # FDF1.0.1/image.c FDF1.0.1/image.cpp - FDF1.0.1/opticalflow_aux.cpp ) # GrayScale, Optical Flow diff --git a/src/FDF1.0.1/opticalflow_aux.cpp b/src/FDF1.0.1/opticalflow_aux.cpp deleted file mode 100644 index bc7f956..0000000 --- a/src/FDF1.0.1/opticalflow_aux.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include -#include -#include -#include - -#include "opticalflow_aux.h" -#include "../kernels/flowUtil.h" -#include "../common/timer.h" - -#include - -using namespace timer; - -#if (VECTOR_WIDTH == 4) -typedef float32x4_t v4sf; -#else -typedef float v4sf; -#endif - -#define datanorm 0.1f*0.1f//0.01f // square of the normalization factor -#define epsilon_color (0.001f*0.001f)//0.000001f -#define epsilon_grad (0.001f*0.001f)//0.000001f -#define epsilon_desc (0.001f*0.001f)//0.000001f -#define epsilon_smooth (0.001f*0.001f)//0.000001f - -/* warp a color image according to a flow. src is the input image, wx and wy, the input flow. dst is the warped image and mask contains 0 or 1 if the pixels goes outside/inside image boundaries */ -void image_warp(color_image_t *dst, image_t *mask, const color_image_t *src, const image_t *wx, const image_t *wy) -{ - - cu::warpImage(dst, mask, src, wx, wy); - -} - - -/* compute image first and second order spatio-temporal derivatives of a color image */ -void get_derivatives( - const color_image_t *im1, const color_image_t *im2, float *pDeviceKernel, - color_image_t *dx, color_image_t *dy, color_image_t *dt, - color_image_t *dxx, color_image_t *dxy, color_image_t *dyy, color_image_t *dxt, color_image_t *dyt) -{ - // derivatives are computed on the mean of the first image and the warped second image - color_image_t *tmp_im2 = color_image_new(im2->width,im2->height); - - int height = im2->height; - int width = im2->width; - int stride = im2->stride; - - cu::getMeanImageAndDiff(im1->c1, im2->c1, tmp_im2->c1, dt->c1, im1->height, im1->stride); - - // compute all other derivatives - cu::colorImageDerivative(dx->c1, tmp_im2->c1, pDeviceKernel, height, width, stride, true); // horizontal - cu::colorImageDerivative(dy->c1, tmp_im2->c1, pDeviceKernel, height, width, stride, false); - cu::colorImageDerivative(dxx->c1, dx->c1, pDeviceKernel, height, width, stride, true); - cu::colorImageDerivative(dxy->c1, dx->c1, pDeviceKernel, height, width, stride, false); - cu::colorImageDerivative(dyy->c1, dy->c1, pDeviceKernel, height, width, stride, false); - cu::colorImageDerivative(dxt->c1, dt->c1, pDeviceKernel, height, width, stride, true); - cu::colorImageDerivative(dyt->c1, dt->c1, pDeviceKernel, height, width, stride, false); - - // free memory - color_image_delete(tmp_im2); -} - - -/* compute the smoothness term */ -/* It is represented as two images, the first one for horizontal smoothness, the second for vertical - in dst_horiz, the pixel i,j represents the smoothness weight between pixel i,j and i,j+1 - in dst_vert, the pixel i,j represents the smoothness weight between pixel i,j and i+1,j */ -void compute_smoothness(image_t *dst_horiz, image_t *dst_vert, const image_t *uu, const image_t *vv, float *deriv_flow, const float quarter_alpha){ - const int width = uu->width, height = vv->height, stride = uu->stride; - int j; - image_t *ux = image_new(width,height), *vx = image_new(width,height), *uy = image_new(width,height), *vy = image_new(width,height), *smoothness = image_new(width,height); - - // compute derivatives [-0.5 0 0.5] - cu::imageDerivative(ux->c1, uu->c1, deriv_flow, height, width, stride, true); - cu::imageDerivative(vx->c1, vv->c1, deriv_flow, height, width, stride, true); - cu::imageDerivative(uy->c1, uu->c1, deriv_flow, height, width, stride, false); - cu::imageDerivative(vy->c1, vv->c1, deriv_flow, height, width, stride, false); - - cu::smoothnessTerm( - dst_horiz->c1, dst_vert->c1, smoothness->c1, - ux->c1, uy->c1, vx->c1, vy->c1, - quarter_alpha, epsilon_smooth, - height, width, stride); - - // Cleanup extra columns - for(j=0;jc1[j*stride+width-1], 0, sizeof(float)*(stride-width+1)); - } - // Cleanup last row - memset( &dst_vert->c1[(height-1)*stride], 0, sizeof(float)*stride); - - image_delete(ux); image_delete(uy); image_delete(vx); image_delete(vy); - image_delete(smoothness); -} - - - - - -/* sub the laplacian (smoothness term) to the right-hand term */ -void sub_laplacian(image_t *dst, const image_t *src, const image_t *weight_horiz, const image_t *weight_vert){ - - cu::subLaplacianHoriz(src->c1, dst->c1, weight_horiz->c1, src->height, src->width, src->stride); - - cu::subLaplacianVert(src->c1, dst->c1, weight_vert->c1, src->height, src->stride); -} - -/* compute the dataterm // REMOVED MATCHING TERM - a11 a12 a22 represents the 2x2 diagonal matrix, b1 and b2 the right hand side - other (color) images are input */ -void compute_data(image_t *a11, image_t *a12, image_t *a22, image_t *b1, image_t *b2, image_t *mask, image_t *wx, image_t *wy, image_t *du, image_t *dv, image_t *uu, image_t *vv, color_image_t *Ix, color_image_t *Iy, color_image_t *Iz, color_image_t *Ixx, color_image_t *Ixy, color_image_t *Iyy, color_image_t *Ixz, color_image_t *Iyz, const float half_delta_over3, const float half_beta, const float half_gamma_over3) -{ - return cu::dataTerm(a11, a12, a22, b1, b2, mask, wx, wy, du, dv, uu, vv, Ix, Iy, Iz, Ixx, Ixy, Iyy, Ixz, Iyz, half_delta_over3, half_beta, half_gamma_over3); -} - diff --git a/src/FDF1.0.1/opticalflow_aux.h b/src/FDF1.0.1/opticalflow_aux.h deleted file mode 100644 index f78443d..0000000 --- a/src/FDF1.0.1/opticalflow_aux.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef __OPTICALFLOW_AUX_ -#define __OPTICALFLOW_AUX_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include "image.h" - -/* warp a color image according to a flow. src is the input image, wx and wy, the input flow. dst is the warped image and mask contains 0 or 1 if the pixels goes outside/inside image boundaries */ -void image_warp(color_image_t *dst, image_t *mask, const color_image_t *src, const image_t *wx, const image_t *wy); - -/* compute image first and second order spatio-temporal derivatives of a color image */ -void get_derivatives(const color_image_t *im1, const color_image_t *im2, float *deriv, color_image_t *dx, color_image_t *dy, color_image_t *dt, color_image_t *dxx, color_image_t *dxy, color_image_t *dyy, color_image_t *dxt, color_image_t *dyt); - -/* compute the smoothness term */ -void compute_smoothness(image_t *dst_horiz, image_t *dst_vert, const image_t *uu, const image_t *vv, float *kernel, const float quarter_alpha); -// void compute_smoothness_SF(image_t *dst_horiz, image_t *dst_vert, const image_t *xx1, const image_t *xx2, const image_t *yy, const image_t *xx3, const convolution_t *deriv_flow, const float quarter_alpha); - -/* sub the laplacian (smoothness term) to the right-hand term */ -void sub_laplacian(image_t *dst, const image_t *src, const image_t *weight_horiz, const image_t *weight_vert); - -/* compute the dataterm and ... REMOVED THE MATCHING TERM - a11 a12 a22 represents the 2x2 diagonal matrix, b1 and b2 the right hand side - other (color) images are input */ -void compute_data(image_t *a11, image_t *a12, image_t *a22, image_t *b1, image_t *b2, image_t *mask, image_t *wx, image_t *wy, image_t *du, image_t *dv, image_t *uu, image_t *vv, color_image_t *Ix, color_image_t *Iy, color_image_t *Iz, color_image_t *Ixx, color_image_t *Ixy, color_image_t *Iyy, color_image_t *Ixz, color_image_t *Iyz, const float half_delta_over3, const float half_beta, const float half_gamma_over3); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/src/kernels/flowUtil.cu b/src/kernels/flowUtil.cu index fd55be5..7af150e 100644 --- a/src/kernels/flowUtil.cu +++ b/src/kernels/flowUtil.cu @@ -889,4 +889,70 @@ namespace cu { d_wx, d_wy, src->height, src->width, src->stride); } + + void computeSmoothness( + image_t *dst_horiz, image_t *dst_vert, const image_t *uu, const image_t *vv, float *deriv_flow, const float quarter_alpha) { + + const int width = uu->width, height = vv->height, stride = uu->stride; + image_t *ux = image_new(width,height), + *vx = image_new(width,height), + *uy = image_new(width,height), + *vy = image_new(width,height), + *smoothness = image_new(width,height); + + // compute derivatives [-0.5 0 0.5] + cu::imageDerivative(ux->c1, uu->c1, deriv_flow, height, width, stride, true); + cu::imageDerivative(vx->c1, vv->c1, deriv_flow, height, width, stride, true); + cu::imageDerivative(uy->c1, uu->c1, deriv_flow, height, width, stride, false); + cu::imageDerivative(vy->c1, vv->c1, deriv_flow, height, width, stride, false); + + cu::smoothnessTerm( + dst_horiz->c1, dst_vert->c1, smoothness->c1, + ux->c1, uy->c1, vx->c1, vy->c1, + quarter_alpha, epsilon_smooth, + height, width, stride); + + // Cleanup extra columns + for(int j = 0; j < height; j++){ + memset(&dst_horiz->c1[j*stride+width-1], 0, sizeof(float)*(stride-width+1)); + } + // Cleanup last row + memset( &dst_vert->c1[(height-1)*stride], 0, sizeof(float)*stride); + + image_delete(ux); image_delete(uy); image_delete(vx); image_delete(vy); + image_delete(smoothness); + } + + void getDerivatives( + const color_image_t *im1, const color_image_t *im2, float *pDeviceKernel, + color_image_t *dx, color_image_t *dy, color_image_t *dt, + color_image_t *dxx, color_image_t *dxy, color_image_t *dyy, color_image_t *dxt, color_image_t *dyt) + { + // derivatives are computed on the mean of the first image and the warped second image + color_image_t *tmp_im2 = color_image_new(im2->width,im2->height); + + int height = im2->height; + int width = im2->width; + int stride = im2->stride; + + cu::getMeanImageAndDiff(im1->c1, im2->c1, tmp_im2->c1, dt->c1, im1->height, im1->stride); + + // compute all other derivatives + cu::colorImageDerivative(dx->c1, tmp_im2->c1, pDeviceKernel, height, width, stride, true); // horizontal + cu::colorImageDerivative(dy->c1, tmp_im2->c1, pDeviceKernel, height, width, stride, false); + cu::colorImageDerivative(dxx->c1, dx->c1, pDeviceKernel, height, width, stride, true); + cu::colorImageDerivative(dxy->c1, dx->c1, pDeviceKernel, height, width, stride, false); + cu::colorImageDerivative(dyy->c1, dy->c1, pDeviceKernel, height, width, stride, false); + cu::colorImageDerivative(dxt->c1, dt->c1, pDeviceKernel, height, width, stride, true); + cu::colorImageDerivative(dyt->c1, dt->c1, pDeviceKernel, height, width, stride, false); + + // free memory + color_image_delete(tmp_im2); + } + + void subLaplacian(image_t *dst, const image_t *src, const image_t *weight_horiz, const image_t *weight_vert){ + cu::subLaplacianHoriz(src->c1, dst->c1, weight_horiz->c1, src->height, src->width, src->stride); + cu::subLaplacianVert(src->c1, dst->c1, weight_vert->c1, src->height, src->stride); + } + } diff --git a/src/kernels/flowUtil.h b/src/kernels/flowUtil.h index 1781b03..7a74c4c 100644 --- a/src/kernels/flowUtil.h +++ b/src/kernels/flowUtil.h @@ -71,6 +71,16 @@ namespace cu { void warpImage( color_image_t *dst, image_t *mask, const color_image_t *src, const image_t *wx, const image_t *wy); + void computeSmoothness( + image_t *dst_horiz, image_t *dst_vert, const image_t *uu, const image_t *vv, float *deriv_flow, const float quarter_alpha); + + void getDerivatives( + const color_image_t *im1, const color_image_t *im2, float *pDeviceKernel, + color_image_t *dx, color_image_t *dy, color_image_t *dt, + color_image_t *dxx, color_image_t *dxy, color_image_t *dyy, color_image_t *dxt, color_image_t *dyt); + + void subLaplacian(image_t *dst, const image_t *src, const image_t *weight_horiz, const image_t *weight_vert); + } #endif // end __KERNEL_FLOW_UTIL_H__ diff --git a/src/refine_variational.cpp b/src/refine_variational.cpp index 7b795a3..8d35fb0 100644 --- a/src/refine_variational.cpp +++ b/src/refine_variational.cpp @@ -165,13 +165,12 @@ namespace OFC { // warp second image auto start_image_warp = now(); - // image_warp(w_im2, mask, im2, wx, wy); cu::warpImage(w_im2, mask, im2, wx, wy); calc_print_elapsed("RefLevelOF image_warp", start_image_warp); // compute derivatives auto start_get_derivs = now(); - get_derivatives(im1, w_im2, pDeviceColorDerivativeKernel, Ix, Iy, Iz, Ixx, Ixy, Iyy, Ixz, Iyz); + cu::getDerivatives(im1, w_im2, pDeviceColorDerivativeKernel, Ix, Iy, Iz, Ixx, Ixy, Iyy, Ixz, Iyz); calc_print_elapsed("RefLevelOF get_derivatives", start_get_derivs); // erase du and dv @@ -190,17 +189,19 @@ namespace OFC { // compute robust function and system auto start_smooth = now(); - compute_smoothness(smooth_horiz, smooth_vert, uu, vv, pDeviceDerivativeKernel, vr.tmp_quarter_alpha ); + cu::computeSmoothness(smooth_horiz, smooth_vert, uu, vv, pDeviceDerivativeKernel, vr.tmp_quarter_alpha ); calc_print_elapsed(("RefLevelOF " + iterStr + " smoothness").c_str(), start_smooth); auto start_data = now(); - // compute_data(a11, a12, a22, b1, b2, mask, wx, wy, du, dv, uu, vv, Ix, Iy, Iz, Ixx, Ixy, Iyy, Ixz, Iyz, vr.tmp_half_delta_over3, vr.tmp_half_beta, vr.tmp_half_gamma_over3); - cu::dataTerm(a11, a12, a22, b1, b2, mask, wx, wy, du, dv, uu, vv, Ix, Iy, Iz, Ixx, Ixy, Iyy, Ixz, Iyz, vr.tmp_half_delta_over3, vr.tmp_half_beta, vr.tmp_half_gamma_over3); + cu::dataTerm(a11, a12, a22, b1, b2, + mask, wx, wy, du, dv, uu, vv, + Ix, Iy, Iz, Ixx, Ixy, Iyy, Ixz, Iyz, + vr.tmp_half_delta_over3, vr.tmp_half_beta, vr.tmp_half_gamma_over3); calc_print_elapsed(("RefLevelOF " + iterStr + " data").c_str(), start_data); auto start_lapalcian = now(); - sub_laplacian(b1, wx, smooth_horiz, smooth_vert); - sub_laplacian(b2, wy, smooth_horiz, smooth_vert); + cu::subLaplacian(b1, wx, smooth_horiz, smooth_vert); + cu::subLaplacian(b2, wy, smooth_horiz, smooth_vert); calc_print_elapsed(("RefLevelOF " + iterStr + " laplacian").c_str(), start_lapalcian); // solve system diff --git a/src/refine_variational.h b/src/refine_variational.h index 2c3ad30..dcdb380 100644 --- a/src/refine_variational.h +++ b/src/refine_variational.h @@ -2,7 +2,6 @@ #define VARREF_HEADER #include "FDF1.0.1/image.h" -#include "FDF1.0.1/opticalflow_aux.h" #include "oflow.h"