def _runSFS(self, C0_32F, A_8U, N0_32F, AN_8U): I0_32F = luminance(C0_32F) L = lightEstimation(I0_32F, N0_32F, A_8U) LdN = LdotN(L, N0_32F) layer_area = A_8U > 0.5 * np.max(A_8U) Cs = C0_32F[layer_area].reshape(-1, 3) Is = LdN[layer_area].flatten() M = ColorMapEstimation(Cs, Is) I_const = M.illumination(Cs) I_32F = np.array(I0_32F) I_32F[layer_area] = I_const I_32F[A_8U < 0.5 * np.max(A_8U)] = np.min(I_const) toon_sfs = ToonSFS(L, C0_32F, A_8U) toon_sfs.setInitialNormal(N0_32F) toon_sfs.run() N_32F = toon_sfs.normal() LdN_recovered = LdotN(L, N_32F) LdN_recovered[A_8U < 0.5 * np.max(A_8U)] = np.min(LdN_recovered) Is = LdN_recovered[layer_area].flatten() Cs_recovered = M.shading(Is) C_32F = np.array(C0_32F) C_32F[layer_area, :] = Cs_recovered return N_32F, L, C_32F, M
def _runColorMap(self, colormap_file, Ng_32F, N0_32F, A_8U): M_32F = loadColorMap(colormap_file) L0 = normalizeVector(np.array([-0.2, 0.3, 0.6])) L0_img = lightSphere(L0) L0_txt = 0.01 * np.int32(100 * L0) C0_32F = ColorMapShader(M_32F).diffuseShading(L0, Ng_32F) I_32F = luminance(C0_32F) L = lightEstimation(I_32F, N0_32F, A_8U) L_txt = 0.01 * np.int32(100 * L) L_img = lightSphere(L) fig, axes = plt.subplots(figsize=(11, 5)) font_size = 15 fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.12, wspace=0.05) fig.suptitle(self.name(), fontsize=font_size) num_rows = 1 num_cols = 4 plot_grid = SubplotGrid(num_rows, num_cols) plot_grid.showImage(setAlpha(C0_32F, A_8U), r'Input image: $\mathbf{c}$', font_size=font_size) plot_grid.showImage(normalToColor(N0_32F, A_8U), r'Initial normal: $\mathbf{N}_0$') plot_grid.showImage(L0_img, r'Ground trugh light: $L_g = (%s, %s, %s)$' %(L0_txt[0], L0_txt[1], L0_txt[2])) plot_grid.showImage(L_img, r'Estimated light: $L = (%s, %s, %s)$' %(L_txt[0], L_txt[1], L_txt[2])) showMaximize()
def computeErrorTables(Lg=normalizeVector(np.array([-0.2, 0.3, 0.6]))): colormap_files = colorMapFiles() shape_names = shapeNames() num_materials = len(colormap_files) num_shapes = len(shape_names) L_errors = np.zeros((num_shapes, num_materials)) Ms = [] for colormap_file in colormap_files: M_32F = loadColorMap(colormap_file) Ms.append(M_32F) for si, shape_name in enumerate(shape_names): Ng_data = shapeFile(shape_name) Ng_data = loadNormal(Ng_data) Ng_32F, A_8U = Ng_data N0_file = shapeResultFile(result_name="InitialNormal", data_name=shape_name) N0_data = loadNormal(N0_file) N0_32F, A_8U = N0_data for mi, M_32F in enumerate(Ms): C0_32F = ColorMapShader(M_32F).diffuseShading(Lg, Ng_32F) I_32F = luminance(C0_32F) L = lightEstimation(I_32F, N0_32F, A_8U) L_errors[si, mi] = angleError(Lg, L) file_path = shapeResultFile("LightEstimation", "LightEstimationError", file_ext=".npy") np.save(file_path, L_errors)
def _runLayer(self, layer_file): C0_8U = loadRGBA(layer_file) if C0_8U is None: return A_8U = alpha(C0_8U) if A_8U is None: return C0_32F = to32F(rgb(C0_8U)) I_32F = luminance(C0_32F) N0_32F, A_8U = loadNormal( self.characterResultFile("N0_d.png", data_name="BaseDetailSepration")) Nd_32F, A_8U = loadNormal( self.characterResultFile("N_d_smooth.png", data_name="BaseDetailSepration")) Nb_32F, A_8U = loadNormal( self.characterResultFile("N_b_smooth.png", data_name="BaseDetailSepration")) W_32F = np.array(Nb_32F[:, :, 2]) W_32F = W_32F W_32F[W_32F < 0.95] = 0.0 L = lightEstimation(I_32F, N0_32F, A_8U) # L = lightEstimationByVoting(I_32F, N0_32F, A_8U) L_txt = 0.01 * np.int32(100 * L) L_img = lightSphere(L) fig, axes = plt.subplots(figsize=(11, 5)) font_size = 15 fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.12, wspace=0.05) fig.suptitle(self.name(), fontsize=font_size) num_rows = 1 num_cols = 4 plot_grid = SubplotGrid(num_rows, num_cols) plot_grid.showImage(C0_8U, r'$C$') plot_grid.showImage(normalToColor(N0_32F, A_8U), r'$N$') plot_grid.showImage(setAlpha(C0_32F, W_32F), r'$Nd_z$') plot_grid.showImage( L_img, r'$L: [%s, %s, %s]$' % (L_txt[0], L_txt[1], L_txt[2])) showMaximize()
def _runLayer(self, layer_file): C0_8U = loadRGBA(layer_file) if C0_8U is None: return A_8U = alpha(C0_8U) if A_8U is None: return C0_32F = to32F(rgb(C0_8U)) I_32F = luminance(C0_32F) N0_32F, A_8U = loadNormal(self.characterResultFile("N0_d.png", data_name="BaseDetailSepration")) Nd_32F, A_8U = loadNormal(self.characterResultFile("N_d_smooth.png", data_name="BaseDetailSepration")) Nb_32F, A_8U = loadNormal(self.characterResultFile("N_b_smooth.png", data_name="BaseDetailSepration")) W_32F = np.array(Nb_32F[:, :, 2]) W_32F = W_32F W_32F[W_32F < 0.95] = 0.0 L = lightEstimation(I_32F, N0_32F, A_8U) # L = lightEstimationByVoting(I_32F, N0_32F, A_8U) L_txt = 0.01 * np.int32(100 * L) L_img = lightSphere(L) fig, axes = plt.subplots(figsize=(11, 5)) font_size = 15 fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.12, wspace=0.05) fig.suptitle(self.name(), fontsize=font_size) num_rows = 1 num_cols = 4 plot_grid = SubplotGrid(num_rows, num_cols) plot_grid.showImage(C0_8U, r'$C$') plot_grid.showImage(normalToColor(N0_32F, A_8U), r'$N$') plot_grid.showImage(setAlpha(C0_32F, W_32F), r'$Nd_z$') plot_grid.showImage(L_img, r'$L: [%s, %s, %s]$' %(L_txt[0], L_txt[1], L_txt[2])) showMaximize()
def _runColorMap(self, colormap_file, Ng_32F, N0_32F, A_8U): M_32F = loadColorMap(colormap_file) L0 = normalizeVector(np.array([-0.2, 0.3, 0.6])) L0_img = lightSphere(L0) L0_txt = 0.01 * np.int32(100 * L0) C0_32F = ColorMapShader(M_32F).diffuseShading(L0, Ng_32F) I_32F = luminance(C0_32F) L = lightEstimation(I_32F, N0_32F, A_8U) L_txt = 0.01 * np.int32(100 * L) L_img = lightSphere(L) fig, axes = plt.subplots(figsize=(11, 5)) font_size = 15 fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.12, wspace=0.05) fig.suptitle(self.name(), fontsize=font_size) num_rows = 1 num_cols = 4 plot_grid = SubplotGrid(num_rows, num_cols) plot_grid.showImage(setAlpha(C0_32F, A_8U), r'Input image: $\mathbf{c}$', font_size=font_size) plot_grid.showImage(normalToColor(N0_32F, A_8U), r'Initial normal: $\mathbf{N}_0$') plot_grid.showImage( L0_img, r'Ground trugh light: $L_g = (%s, %s, %s)$' % (L0_txt[0], L0_txt[1], L0_txt[2])) plot_grid.showImage( L_img, r'Estimated light: $L = (%s, %s, %s)$' % (L_txt[0], L_txt[1], L_txt[2])) showMaximize()
def lightEstimationFigure(): target_colormaps = [23, 0, 6, 22, 4, 12] target_shapes = ["Raptor", "Man", "Blob1", "OctaFlower", "Pulley", "Cone"] colormap_files = [colorMapFile(cmap_id) for cmap_id in target_colormaps] shape_names = target_shapes num_rows = len(shape_names) + 1 num_cols = len(colormap_files) + 1 w = 10 h = w * num_rows / num_cols fig, axes = plt.subplots(figsize=(w, h)) font_size = 15 fig.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02, hspace=0.05, wspace=0.05) fig.suptitle("", fontsize=font_size) plot_grid = SubplotGrid(num_rows, num_cols) Lg = normalizeVector(np.array([-0.2, 0.3, 0.6])) Lg_img = lightSphere(Lg) plot_grid.showImage(Lg_img, "") Ms = [] for colormap_file in colormap_files: M_32F = loadColorMap(colormap_file) Cs_32F = colorMapSphere(Lg, M_32F) plot_grid.showImage(Cs_32F, "") Ms.append(M_32F) L_errors = np.zeros((num_rows, num_cols)) for si, shape_name in enumerate(shape_names): Ng_data = shapeFile(shape_name) Ng_data = loadNormal(Ng_data) Ng_32F, A_8U = Ng_data N0_file = shapeResultFile(result_name="InitialNormal", data_name=shape_name) N0_data = loadNormal(N0_file) N0_32F, A_8U = N0_data plot_grid.showImage(normalToColor(Ng_32F, A_8U), "") for mi, M_32F in enumerate(Ms): C0_32F = ColorMapShader(M_32F).diffuseShading(Lg, Ng_32F) I_32F = luminance(C0_32F) L = lightEstimation(I_32F, N0_32F, A_8U) L_errors[si, mi] = angleError(Lg, L) L_img = lightSphereColorMap(L, v=L_errors[si, mi], v_min=0, v_max=40) plot_grid.showImage(L_img, "") L_error_min, L_error_max = np.min(L_errors), np.max(L_errors) file_path = shapeResultFile("LightEstimation", "LightEstimationError") fig.savefig(file_path, transparent=True)