def depthFromGradient(I_32F, A_8U):
    if A_8U is not None:
        I_32F = preProcess(I_32F, A_8U)

    h, w = I_32F.shape[:2]

    A_g, b_g = gradientConstraints(I_32F, w_cons=1.0)
    A_rg = l2Regularization(h*w, w_rg=0.000001)
    A_L = laplacianMatrix((h, w))

    A = A_g + A_rg
    b = b_g

    D_flat = amg_solver.solve(A, b)
    D_32F = D_flat.reshape(h, w)

    return D_32F
def depthFromGradient(I_32F, A_8U):
    if A_8U is not None:
        I_32F = preProcess(I_32F, A_8U)

    h, w = I_32F.shape[:2]

    A_g, b_g = gradientConstraints(I_32F, w_cons=1.0)
    A_rg = l2Regularization(h * w, w_rg=0.000001)
    A_L = laplacianMatrix((h, w))

    A = A_g + A_rg
    b = b_g

    D_flat = amg_solver.solve(A, b)
    D_32F = D_flat.reshape(h, w)

    return D_32F
def smoothGradient(gx):
    h, w = gx.shape[:2]
    A_L = laplacianMatrix((h, w))

    w_g = 1.0
    gx_flat = gx.flatten()
    cons_ids = np.where(gx_flat > 0.01 * np.max(0.0))
    num_verts = h * w
    diags = np.zeros(num_verts)
    diags[cons_ids] = w_g

    A = scipy.sparse.diags(diags, 0) + A_L

    b = np.zeros(num_verts, dtype=np.float32)
    b[cons_ids] = w_g * gx_flat[cons_ids]

    gx_flat = amg_solver.solve(A, b)
    gx = gx_flat.reshape(h, w)
    print gx.shape
    return np.float32(gx)
def smoothGradient(gx):
    h, w = gx.shape[:2]
    A_L = laplacianMatrix((h, w))

    w_g = 1.0
    gx_flat = gx.flatten()
    cons_ids = np.where(gx_flat > 0.01 * np.max(0.0))
    num_verts = h * w
    diags = np.zeros(num_verts)
    diags[cons_ids] = w_g

    A = scipy.sparse.diags(diags, 0) + A_L

    b = np.zeros(num_verts, dtype=np.float32)
    b[cons_ids] = w_g * gx_flat[cons_ids]

    gx_flat = amg_solver.solve(A, b)
    gx = gx_flat.reshape(h, w)
    print gx.shape
    return np.float32(gx)