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
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 _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 _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
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
def func(N_32F): h, w = N_32F.shape[:2] N_new = computeNz(N_32F.reshape(-1, 3)).reshape(h, w, 3) return N_new