示例#1
0
    def _computeInitialNormal(self):
        A_8U = self._A_8U
        h, w = A_8U.shape
        N0_32F = silhouetteNormal(A_8U)
        A, b = normalConstraints(A_8U, N0_32F)

        N_flat = amg_solver.solve(A, b)
        N_flat = normalizeVectors(N_flat)
        N_32F = N_flat.reshape(h, w, 3)
        self._N0_32F = N_32F
示例#2
0
    def _computeInitialNormal(self):
        A_8U = self._A_8U
        h, w = A_8U.shape
        N0_32F = silhouetteNormal(A_8U)
        A, b = normalConstraints(A_8U, N0_32F)

        N_flat = amg_solver.solve(A, b)
        N_flat = normalizeVectors(N_flat)
        N_32F = N_flat.reshape(h, w, 3)
        self._N0_32F = N_32F
示例#3
0
def estimateNormal(A_8U):
    h, w = A_8U.shape
    N0_32F = silhouetteNormal(A_8U)
    A, b = normalConstraints(A_8U, N0_32F)

    N_flat = amg_solver.solve(A, b)
    N_flat = computeNz(N_flat)
    N_flat = normalizeVectors(N_flat)
    N_32F = N_flat.reshape(h, w, 3)

    return N0_32F, N_32F
    def _optimize(self, A_I, b_I):
        h, w = self._I_32F.shape[:2]
        A_L = laplacianMatrix((h, w), num_elements=1)
        A_L = A_L

        A = A_L + A_I
        b = b_I

        N = amg_solver.solve(A, b).reshape(-1, 3)
        computeNz(N)
        #N = normalizeVectors(N)
        N_32F = N.reshape(h, w, 3)

        self._N_32F = N_32F
示例#5
0
    def _interpolateNormalAMG(self, N0_32F, W_32F, A_8U):
        h, w = N0_32F.shape[:2]
        A_c, b_c = normalConstraints(W_32F, N0_32F)
        A_8U = None
        if self._image.shape[2] == 4:
            A_8U = to8U(alpha(self._image))
        A_sil, b_sil = silhouetteConstraints(A_8U)

        A_L = laplacianMatrix((h, w))
        A = 10.0 * A_c + A_L + A_sil
        b = 10.0 * b_c + b_sil

        N_32F = amg_solver.solve(A, b).reshape(h, w, 3)
        N_32F = normalizeImage(N_32F)

        return N_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
示例#7
0
    def _computeLumoNormal(self):
        A_8U = self._A_8U

        if A_8U is None:
            return

        h, w = A_8U.shape[:2]
        A_c, b_c = amg_constraints.silhouetteConstraints(A_8U)

        A_L = amg_constraints.laplacianMatrix((h, w))
        A = 3.0 * A_c + A_L
        b = 3.0 * b_c

        N_32F = amg_solver.solve(A, b).reshape(h, w, 3)
        N_32F = computeNz(N_32F.reshape(-1, 3)).reshape(h, w, 3)
        N_32F = normalizeImage(N_32F)
        self._N_lumo = np.array(N_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 _computeLumoNormal(self):
        A_8U = self._A_8U

        if A_8U is None:
            return

        h, w = A_8U.shape[:2]
        A_c, b_c = amg_constraints.silhouetteConstraints(A_8U)

        A_L = amg_constraints.laplacianMatrix((h, w))
        A = 3.0 * A_c + A_L
        b = 3.0 * b_c

        N_32F = amg_solver.solve(A, b).reshape(h, w, 3)
        N_32F = computeNz(N_32F.reshape(-1, 3)).reshape(h, w, 3)
        N_32F = normalizeImage(N_32F)
        self._N_lumo = np.array(N_32F)
示例#10
0
    def _computeInitialNormal(self):
        A_8U = self._A_8U
        self._N0_32F = np.float64(silhouetteNormal(A_8U))

        return

        h, w = A_8U.shape
        A_L = laplacianMatrix((h, w), num_elements=3)
        A_sil, b_sil = silhouetteConstraints(A_8U, is_flat=True)

        A = A_L + A_sil
        b = b_sil

        N = amg_solver.solve(A, b).reshape(-1, 3)
        computeNz(N)
        N = normalizeVectors(N)
        N_32F = N.reshape(h, w, 3)
        self._N0_32F = N_32F
示例#11
0
    def _computeInitialNormal(self):
        A_8U = self._A_8U
        self._N0_32F = np.float64(silhouetteNormal(A_8U))

        return

        h, w = A_8U.shape
        A_L = laplacianMatrix((h, w), num_elements=3)
        A_sil, b_sil = silhouetteConstraints(A_8U, is_flat=True)

        A = A_L + A_sil
        b = b_sil

        N = amg_solver.solve(A, b).reshape(-1, 3)
        computeNz(N)
        N = normalizeVectors(N)
        N_32F = N.reshape(h, w, 3)
        self._N0_32F = N_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)
    def _runImp(self):
        normal_data = loadNormal(self._data_file)

        if normal_data is None:
            return

        N0_32F, A_8U = normal_data

        h, w = A_8U.shape[:2]
        A_c, b_c = amg_constraints.silhouetteConstraints(A_8U, is_flat=True)

        A_L = amg_constraints.laplacianMatrix((h, w), num_elements=3)
        A = A_c + A_L
        b = b_c

        N = amg_solver.solve(A, b).reshape(-1, 3)
        N = computeNz(N)
        N = normalizeVectors(N)
        N_32F = N.reshape(h, w, 3)

        file_path = self.resultFile(self._data_file_name)
        saveNormal(file_path, N_32F, A_8U)
    def _runImp(self):
        normal_data = loadNormal(self._data_file)

        if normal_data is None:
            return

        N0_32F, A_8U = normal_data

        h, w = A_8U.shape[:2]
        A_c, b_c = amg_constraints.silhouetteConstraints(A_8U, is_flat=True)

        A_L = amg_constraints.laplacianMatrix((h, w), num_elements=3)
        A = A_c + A_L
        b = b_c

        N = amg_solver.solve(A, b).reshape(-1, 3)
        N = computeNz(N)
        N = normalizeVectors(N)
        N_32F = N.reshape(h, w, 3)

        file_path = self.resultFile(self._data_file_name)
        saveNormal(file_path, N_32F, A_8U)
    def _computeDetailNormal(self, N0_32F):
        h, w = N0_32F.shape[:2]
        W_32F = np.zeros((h, w))

#         sigma_d = 2.0 * np.max(N0_32F[:, :, 2])
#         W_32F = 1.0 - np.exp( - (N0_32F[:, :, 2] ** 2) / (sigma_d ** 2))

        W_32F = 1.0 - N0_32F[:, :, 2]
        W_32F *= 1.0 / np.max(W_32F)
        W_32F = W_32F ** 1.5

        A_c, b_c = amg_constraints.normalConstraints(W_32F, N0_32F)

        A_L = amg_constraints.laplacianMatrix((h, w))

        lambda_d = 2.0
        A = A_c + lambda_d * A_L
        b = b_c

        N_32F = amg_solver.solve(A, b).reshape(h, w, 3)
        N_32F = computeNz(N_32F.reshape(-1, 3)).reshape(h, w, 3)
        N_32F = normalizeImage(N_32F)
        return N_32F
示例#17
0
    def _computeDetailNormal(self, N0_32F):
        h, w = N0_32F.shape[:2]
        W_32F = np.zeros((h, w))

        #         sigma_d = 2.0 * np.max(N0_32F[:, :, 2])
        #         W_32F = 1.0 - np.exp( - (N0_32F[:, :, 2] ** 2) / (sigma_d ** 2))

        W_32F = 1.0 - N0_32F[:, :, 2]
        W_32F *= 1.0 / np.max(W_32F)
        W_32F = W_32F**1.5

        A_c, b_c = amg_constraints.normalConstraints(W_32F, N0_32F)

        A_L = amg_constraints.laplacianMatrix((h, w))

        lambda_d = 2.0
        A = A_c + lambda_d * A_L
        b = b_c

        N_32F = amg_solver.solve(A, b).reshape(h, w, 3)
        N_32F = computeNz(N_32F.reshape(-1, 3)).reshape(h, w, 3)
        N_32F = normalizeImage(N_32F)
        return N_32F