Ejemplo n.º 1
0
def w_cycle_3d(n, k, delta_field, sigma_field, gradient_field, target,
             lambda_param, displacement, depth = 0):
    r'''
    Multi-resolution Gauss-Seidel solver: solves the linear system by performing
    two v-cycles at each resolution, which corresponds to the w-cycle scheme
    proposed by Bruhn and Weickert[1].
    [1] Andres Bruhn and Joachim Weickert, "Towards ultimate motion estimation:
        combining highest accuracy with real-time performance",
        10th IEEE International Conference on Computer Vision, 2005. ICCV 2005.
    '''
    #presmoothing
    for i in range(k):
        error = tf.iterate_residual_displacement_field_SSD3D(delta_field,
                                                             sigma_field,
                                                             gradient_field,
                                                             target,
                                                             lambda_param,
                                                             displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field,
                                             sigma_field,
                                             gradient_field,
                                             lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i+1, ' [first]:', energy
    if n == 0:
        return error
    residual = tf.compute_residual_displacement_field_SSD3D(delta_field,
                                                            sigma_field,
                                                            gradient_field,
                                                            target,
                                                            lambda_param,
                                                            displacement,
                                                            None)
    sub_residual = np.array(tf.downsample_displacement_field3D(residual))
    del residual
    #solve at coarcer grid
    subsigma_field = None
    if sigma_field != None:
        subsigma_field = tf.downsample_scalar_field3D(sigma_field)
    subdelta_field = tf.downsample_scalar_field3D(delta_field)
    subgradient_field = np.array(
        tf.downsample_displacement_field3D(gradient_field))
    shape = np.array(displacement.shape).astype(np.int32)
    sub_displacement = np.zeros(
        shape = ((shape[0]+1)//2, (shape[1]+1)//2, (shape[2]+1)//2, 3 ),
        dtype = np.float64)
    sublambda_param = lambda_param*0.25
    w_cycle_3d(n-1, k, subdelta_field, subsigma_field, subgradient_field,
             sub_residual, sublambda_param, sub_displacement, depth+1)
    displacement += np.array(
        tf.upsample_displacement_field3D(sub_displacement, shape))
    if printEnergy and depth == 0:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param, 
                                         displacement)
        print 'Energy after low-res iteration[first]:', energy
    #post-smoothing (second smoothing)
    for i in range(k):
        error = tf.iterate_residual_displacement_field_SSD3D(delta_field,
                                                             sigma_field,
                                                             gradient_field,
                                                             target,
                                                             lambda_param,
                                                             displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field,
                                             sigma_field,
                                             gradient_field,
                                             lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i+1, ' [second]:', energy
    residual = tf.compute_residual_displacement_field_SSD3D(delta_field,
                                                            sigma_field,
                                                            gradient_field,
                                                            target,
                                                            lambda_param,
                                                            displacement,
                                                            None)
    sub_residual = np.array(tf.downsample_displacement_field3D(residual))
    del residual
    sub_displacement[...] = 0
    w_cycle_3d(n-1, k, subdelta_field, subsigma_field, subgradient_field,
             sub_residual, sublambda_param, sub_displacement, depth+1)
    displacement += np.array(
        tf.upsample_displacement_field3D(sub_displacement, shape))
    if printEnergy and depth == 0:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
        print 'Energy after low-res iteration[second]:', energy
    for i in range(k):
        error = tf.iterate_residual_displacement_field_SSD3D(delta_field,
                                                             sigma_field,
                                                             gradient_field,
                                                             target,
                                                             lambda_param,
                                                             displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field,
                                             sigma_field,
                                             gradient_field,
                                             lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i+1, ' [third]:', energy
    try:
        energy
    except NameError:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param, 
                                         displacement)
    return energy
Ejemplo n.º 2
0
def v_cycle_3d(n, k, delta_field, sigma_field, gradient_field, target,
             lambda_param, displacement, depth = 0):
    r'''
    Multi-resolution Gauss-Seidel solver: solves the linear system by first
    filtering (GS-iterate) the current level, then solves for the residual
    at a coarcer resolution andfinally refines the solution at the current 
    resolution. This scheme corresponds to the V-cycle proposed by Bruhn and 
    Weickert[1].
    [1] Andres Bruhn and Joachim Weickert, "Towards ultimate motion estimation:
        combining highest accuracy with real-time performance",
        10th IEEE International Conference on Computer Vision, 2005.
        ICCV 2005.
    '''
    #presmoothing
    for i in range(k):
        tf.iterate_residual_displacement_field_SSD3D(delta_field,
                                                             sigma_field,
                                                             gradient_field,
                                                             target,
                                                             lambda_param,
                                                             displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field,
                                             sigma_field,
                                             gradient_field,
                                             lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i+1, ' [unique]:', energy
    if n == 0:
        try:
            energy
        except NameError:
            energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
        return energy
    #solve at coarcer grid
    residual = tf.compute_residual_displacement_field_SSD3D(delta_field,
                                                            sigma_field,
                                                            gradient_field,
                                                            target,
                                                            lambda_param,
                                                            displacement,
                                                            None)
    sub_residual = np.array(tf.downsample_displacement_field3D(residual))
    del residual
    subsigma_field = None
    if sigma_field != None:
        subsigma_field = tf.downsample_scalar_field3D(sigma_field)
    subdelta_field = tf.downsample_scalar_field3D(delta_field)
    subgradient_field = np.array(
        tf.downsample_displacement_field3D(gradient_field))
    shape = np.array(displacement.shape).astype(np.int32)
    sub_displacement = np.zeros(
        shape = ((shape[0]+1)//2, (shape[1]+1)//2, (shape[2]+1)//2, 3 ),
        dtype = np.float64)
    sublambda_param = lambda_param*0.25
    v_cycle_3d(n-1, k, subdelta_field, subsigma_field, subgradient_field,
             sub_residual, sublambda_param, sub_displacement, depth+1)
    del subdelta_field
    del subsigma_field
    del subgradient_field
    del sub_residual
    tf.accumulate_upsample_displacement_field3D(sub_displacement, displacement)
    del sub_displacement
    if printEnergy and depth == 0:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field, 
                                         gradient_field, lambda_param,
                                         displacement)
        print 'Energy after low-res iteration:', energy
    #post-smoothing
    for i in range(k):
        tf.iterate_residual_displacement_field_SSD3D(delta_field,
                                                             sigma_field,
                                                             gradient_field,
                                                             target,
                                                             lambda_param,
                                                             displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field,
                                             sigma_field,
                                             gradient_field,
                                             lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i+1, ' [unique]:', energy
    try:
        energy
    except NameError:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
    return energy
Ejemplo n.º 3
0
def single_cycle_3d(n, k, delta_field, sigma_field, gradient_field,
                    lambda_param, displacement, depth = 0):
    r'''
    One-pass multi-resolution Gauss-Seidel solver: solves the SSD-like linear
    system starting at the coarcer resolution and then refining at the finer
    resolution.
    '''
    if n == 0:
        for i in range(k):
            error = tf.iterate_residual_displacement_field_SSD3D(delta_field,
                                                                 sigma_field,
                                                                 gradient_field,
                                                                 None,
                                                                 lambda_param,
                                                                 displacement)
            if printEnergy and depth == 0:
                energy = tf.compute_energy_SSD3D(delta_field,
                                                 sigma_field,
                                                 gradient_field,
                                                 lambda_param,
                                                 displacement)
                print 'Energy after top-level iter', i+1, ' [unique]:', energy
        return error
    #solve at coarcer grid
    subsigma_field = None
    if sigma_field != None:
        subsigma_field = tf.downsample_scalar_field3D(sigma_field)
    subdelta_field = tf.downsample_scalar_field3D(delta_field)
    subgradient_field = np.array(
        tf.downsample_displacement_field3D(gradient_field))
    shape = np.array(displacement.shape).astype(np.int32)
    sub_displacement = np.zeros(
        shape = ((shape[0]+1)//2, (shape[1]+1)//2, (shape[2]+1)//2, 3 ),
        dtype = np.float64)
    sublambda_param = lambda_param*0.25
    single_cycle_3d(n-1, k, subdelta_field, subsigma_field, subgradient_field,
                  sublambda_param, sub_displacement, depth+1)
    displacement += np.array(
        tf.upsample_displacement_field3D(sub_displacement, shape))
    if printEnergy and depth == 0:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
        print 'Energy after low-res iteration:', energy
    #post-smoothing
    for i in range(k):
        error = tf.iterate_residual_displacement_field_SSD3D(delta_field,
                                                             sigma_field,
                                                             gradient_field,
                                                             None,
                                                             lambda_param,
                                                             displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field,
                                             sigma_field,
                                             gradient_field,
                                             lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i+1, ' [unique]:', energy
    try:
        energy
    except NameError:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
    return energy
Ejemplo n.º 4
0
def w_cycle_3d(n,
               k,
               delta_field,
               sigma_field,
               gradient_field,
               target,
               lambda_param,
               displacement,
               depth=0):
    r'''
    Multi-resolution Gauss-Seidel solver: solves the linear system by performing
    two v-cycles at each resolution, which corresponds to the w-cycle scheme
    proposed by Bruhn and Weickert[1].
    [1] Andres Bruhn and Joachim Weickert, "Towards ultimate motion estimation:
        combining highest accuracy with real-time performance",
        10th IEEE International Conference on Computer Vision, 2005. ICCV 2005.
    '''
    #presmoothing
    for i in range(k):
        error = tf.iterate_residual_displacement_field_SSD3D(
            delta_field, sigma_field, gradient_field, target, lambda_param,
            displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                             gradient_field, lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i + 1, ' [first]:', energy
    if n == 0:
        return error
    residual = tf.compute_residual_displacement_field_SSD3D(
        delta_field, sigma_field, gradient_field, target, lambda_param,
        displacement, None)
    sub_residual = np.array(tf.downsample_displacement_field3D(residual))
    del residual
    #solve at coarcer grid
    subsigma_field = None
    if sigma_field != None:
        subsigma_field = tf.downsample_scalar_field3D(sigma_field)
    subdelta_field = tf.downsample_scalar_field3D(delta_field)
    subgradient_field = np.array(
        tf.downsample_displacement_field3D(gradient_field))
    shape = np.array(displacement.shape).astype(np.int32)
    sub_displacement = np.zeros(shape=((shape[0] + 1) // 2,
                                       (shape[1] + 1) // 2,
                                       (shape[2] + 1) // 2, 3),
                                dtype=np.float64)
    sublambda_param = lambda_param * 0.25
    w_cycle_3d(n - 1, k, subdelta_field, subsigma_field, subgradient_field,
               sub_residual, sublambda_param, sub_displacement, depth + 1)
    displacement += np.array(
        tf.upsample_displacement_field3D(sub_displacement, shape))
    if printEnergy and depth == 0:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
        print 'Energy after low-res iteration[first]:', energy
    #post-smoothing (second smoothing)
    for i in range(k):
        error = tf.iterate_residual_displacement_field_SSD3D(
            delta_field, sigma_field, gradient_field, target, lambda_param,
            displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                             gradient_field, lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i + 1, ' [second]:', energy
    residual = tf.compute_residual_displacement_field_SSD3D(
        delta_field, sigma_field, gradient_field, target, lambda_param,
        displacement, None)
    sub_residual = np.array(tf.downsample_displacement_field3D(residual))
    del residual
    sub_displacement[...] = 0
    w_cycle_3d(n - 1, k, subdelta_field, subsigma_field, subgradient_field,
               sub_residual, sublambda_param, sub_displacement, depth + 1)
    displacement += np.array(
        tf.upsample_displacement_field3D(sub_displacement, shape))
    if printEnergy and depth == 0:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
        print 'Energy after low-res iteration[second]:', energy
    for i in range(k):
        error = tf.iterate_residual_displacement_field_SSD3D(
            delta_field, sigma_field, gradient_field, target, lambda_param,
            displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                             gradient_field, lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i + 1, ' [third]:', energy
    try:
        energy
    except NameError:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
    return energy
Ejemplo n.º 5
0
def v_cycle_3d(n,
               k,
               delta_field,
               sigma_field,
               gradient_field,
               target,
               lambda_param,
               displacement,
               depth=0):
    r'''
    Multi-resolution Gauss-Seidel solver: solves the linear system by first
    filtering (GS-iterate) the current level, then solves for the residual
    at a coarcer resolution andfinally refines the solution at the current 
    resolution. This scheme corresponds to the V-cycle proposed by Bruhn and 
    Weickert[1].
    [1] Andres Bruhn and Joachim Weickert, "Towards ultimate motion estimation:
        combining highest accuracy with real-time performance",
        10th IEEE International Conference on Computer Vision, 2005.
        ICCV 2005.
    '''
    #presmoothing
    for i in range(k):
        tf.iterate_residual_displacement_field_SSD3D(delta_field, sigma_field,
                                                     gradient_field, target,
                                                     lambda_param,
                                                     displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                             gradient_field, lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i + 1, ' [unique]:', energy
    if n == 0:
        try:
            energy
        except NameError:
            energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                             gradient_field, lambda_param,
                                             displacement)
        return energy
    #solve at coarcer grid
    residual = tf.compute_residual_displacement_field_SSD3D(
        delta_field, sigma_field, gradient_field, target, lambda_param,
        displacement, None)
    sub_residual = np.array(tf.downsample_displacement_field3D(residual))
    del residual
    subsigma_field = None
    if sigma_field != None:
        subsigma_field = tf.downsample_scalar_field3D(sigma_field)
    subdelta_field = tf.downsample_scalar_field3D(delta_field)
    subgradient_field = np.array(
        tf.downsample_displacement_field3D(gradient_field))
    shape = np.array(displacement.shape).astype(np.int32)
    sub_displacement = np.zeros(shape=((shape[0] + 1) // 2,
                                       (shape[1] + 1) // 2,
                                       (shape[2] + 1) // 2, 3),
                                dtype=np.float64)
    sublambda_param = lambda_param * 0.25
    v_cycle_3d(n - 1, k, subdelta_field, subsigma_field, subgradient_field,
               sub_residual, sublambda_param, sub_displacement, depth + 1)
    del subdelta_field
    del subsigma_field
    del subgradient_field
    del sub_residual
    tf.accumulate_upsample_displacement_field3D(sub_displacement, displacement)
    del sub_displacement
    if printEnergy and depth == 0:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
        print 'Energy after low-res iteration:', energy
    #post-smoothing
    for i in range(k):
        tf.iterate_residual_displacement_field_SSD3D(delta_field, sigma_field,
                                                     gradient_field, target,
                                                     lambda_param,
                                                     displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                             gradient_field, lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i + 1, ' [unique]:', energy
    try:
        energy
    except NameError:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
    return energy
Ejemplo n.º 6
0
def single_cycle_3d(n,
                    k,
                    delta_field,
                    sigma_field,
                    gradient_field,
                    lambda_param,
                    displacement,
                    depth=0):
    r'''
    One-pass multi-resolution Gauss-Seidel solver: solves the SSD-like linear
    system starting at the coarcer resolution and then refining at the finer
    resolution.
    '''
    if n == 0:
        for i in range(k):
            error = tf.iterate_residual_displacement_field_SSD3D(
                delta_field, sigma_field, gradient_field, None, lambda_param,
                displacement)
            if printEnergy and depth == 0:
                energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                                 gradient_field, lambda_param,
                                                 displacement)
                print 'Energy after top-level iter', i + 1, ' [unique]:', energy
        return error
    #solve at coarcer grid
    subsigma_field = None
    if sigma_field != None:
        subsigma_field = tf.downsample_scalar_field3D(sigma_field)
    subdelta_field = tf.downsample_scalar_field3D(delta_field)
    subgradient_field = np.array(
        tf.downsample_displacement_field3D(gradient_field))
    shape = np.array(displacement.shape).astype(np.int32)
    sub_displacement = np.zeros(shape=((shape[0] + 1) // 2,
                                       (shape[1] + 1) // 2,
                                       (shape[2] + 1) // 2, 3),
                                dtype=np.float64)
    sublambda_param = lambda_param * 0.25
    single_cycle_3d(n - 1, k, subdelta_field, subsigma_field,
                    subgradient_field, sublambda_param, sub_displacement,
                    depth + 1)
    displacement += np.array(
        tf.upsample_displacement_field3D(sub_displacement, shape))
    if printEnergy and depth == 0:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
        print 'Energy after low-res iteration:', energy
    #post-smoothing
    for i in range(k):
        error = tf.iterate_residual_displacement_field_SSD3D(
            delta_field, sigma_field, gradient_field, None, lambda_param,
            displacement)
        if printEnergy and depth == 0:
            energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                             gradient_field, lambda_param,
                                             displacement)
            print 'Energy after top-level iter', i + 1, ' [unique]:', energy
    try:
        energy
    except NameError:
        energy = tf.compute_energy_SSD3D(delta_field, sigma_field,
                                         gradient_field, lambda_param,
                                         displacement)
    return energy