def colorMapFigure(): L = normalizeVector(np.array([-0.2, 0.3, 0.7])) N_32F, A_32F = normalSphere(h=512, w=512) fig, axes = plt.subplots(figsize=(6, 4)) font_size = 15 fig.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02, hspace=0.1, wspace=0.1) fig.suptitle("", fontsize=font_size) num_rows = 4 num_cols = 6 plot_grid = SubplotGrid(num_rows, num_cols) for colormap_file in colorMapFiles(): M_32F = loadColorMap(colormap_file) C_32F = ColorMapShader(M_32F).diffuseShading(L, N_32F) plot_grid.showImage(setAlpha(C_32F, A_32F), "") file_path = os.path.join(colorMapResultsDir(), "ColorMapMaterials.png") fig.savefig(file_path, transparent=True)
def reflectanceEstimationFigure(): errorTable() M_errors = loadReflectanceErrorTable() M_error_orders = np.argsort(M_errors) print M_errors[M_error_orders] colormap_files = colorMapFiles() colormap_files = [colormap_files[M_error_order] for M_error_order in M_error_orders] colormap_files = colormap_files[0:-1:3] Ms = [] MLs = [] for colormap_file in colormap_files: M_32F = loadColorMap(colormap_file) Ms.append(M_32F) C_32F = M_32F.reshape(1, len(M_32F), 3) I_32F = np.linspace(0.0, 1.0, len(M_32F)) I_32F = I_32F.reshape(C_32F.shape[:2]) reflectance = LambertReflectanceEstimation(C_32F, I_32F) Ml = reflectance.shading(I_32F) MLs.append(Ml[0, :, :]) num_rows = 3 num_cols = len(colormap_files) 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) N_sphere, A_32F = normalSphere(h=512, w=512) Lg = normalizeVector(np.array([-0.2, 0.3, 0.6])) plot_grid = SubplotGrid(num_rows, num_cols) mi = 1 for M, Ml in zip(Ms, MLs): CM_32F = ColorMapShader(M).diffuseShading(Lg, N_sphere) CL_32F = ColorMapShader(Ml).diffuseShading(Lg, N_sphere) C_error = normVectors((CM_32F - CL_32F).reshape(-1, 3)).reshape(CL_32F.shape[:2]) C_error[A_32F < 0.5 * np.max(A_32F)] = 0.0 plot_grid.setPlot(1, mi) plot_grid.showImage(setAlpha(CM_32F, A_32F), "") plot_grid.setPlot(2, mi) plot_grid.showImage(setAlpha(CL_32F, A_32F), "") plot_grid.setPlot(3, mi) plot_grid.showColorMap(C_error, "", v_min=0.0, v_max=0.3, with_colorbar=False) mi += 1 file_path = shapeResultFile("ReflectanceEstimation", "ReflectanceEstimationError") fig.savefig(file_path, transparent=True)
def colorMapSphere(L, M_32F, h=512, w=512): N_32F, A_32F = normalSphere(h=h, w=w) C_32F = ColorMapShader(M_32F).diffuseShading(L, N_32F) C_32F = setAlpha(C_32F, A_32F) return C_32F