def shapeList(): num_rows = 1 num_cols = len(shapeNames()) w = 20 h = w * num_rows / num_cols cmap_id = 10 colormap_file = colorMapFile(cmap_id) M_32F = loadColorMap(colormap_file) L = normalizeVector(np.array([-0.4, 0.5, 0.6])) fig, axes = plt.subplots(figsize=(w, h)) font_size = 15 fig.subplots_adjust(left=0.02, right=0.98, top=0.96, bottom=0.04, hspace=0.15, wspace=0.1) fig.suptitle("", fontsize=font_size) plot_grid = SubplotGrid(num_rows, num_cols) for shape_name in shapeNames(): Ng_data = shapeFile(shape_name) Ng_data = loadNormal(Ng_data) Ng_32F, A_8U = Ng_data C0_32F = ColorMapShader(M_32F).diffuseShading(L, Ng_32F) plot_grid.showImage(setAlpha(C0_32F, to32F(A_8U)), "") file_path = shapeResultFile("ShapeEstimation", "ShapeList") fig.savefig(file_path, transparent=True)
def errorInfo(): shape_names = shapeNames() file_path = shapeResultFile("ShapeEstimation", "ShadingError", file_ext=".npy") C_errors = np.load(file_path) C_error_orders = np.argsort(C_errors) print "Small Shading Error: ", np.min(C_errors) for C_error_order in C_error_orders[:5]: print " ", shape_names[C_error_order] print "Large Shading Error: ", np.max(C_errors) for C_error_order in C_error_orders[-5:]: print " ", shape_names[C_error_order] file_path = shapeResultFile("ShapeEstimation", "NormalError", file_ext=".npy") N_errors = np.load(file_path) N_error_orders = np.argsort(N_errors) print "Small Normal Error: ", np.min(N_errors) for N_error_order in N_error_orders[:5]: print " ", shape_names[N_error_order] print "Large Normal Error: ", np.max(N_errors) for N_error_order in N_error_orders[-5:]: print " ", shape_names[N_error_order]
def errorInfo(): colormap_files = colorMapFiles() shape_names = shapeNames() num_materials = len(colormap_files) num_shapes = len(shape_names) file_path = shapeResultFile("LightEstimation", "LightEstimationError", file_ext=".npy") L_errors = np.load(file_path) shape_errors = np.zeros(num_shapes) for si, shape_name in enumerate(shape_names): shape_errors[si] = np.average(L_errors[si, :]) shape_error_orders = np.argsort(shape_errors) print shape_error_orders print shape_error_orders[:3] print shape_error_orders[-3:] for shape_error_order in shape_error_orders[:3]: print shape_names[shape_error_order] for shape_error_order in shape_error_orders[-3:]: print shape_names[shape_error_order] material_errors = np.zeros(num_materials) for mi in xrange(num_materials): material_errors[mi] = np.average(L_errors[:, mi]) material_error_orders = np.argsort(material_errors) print material_error_orders[:3] print material_error_orders[-3:]
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 computeLambertShadingError(): shape_names = shapeNames() L = normalizeVector(np.array([-0.2, 0.3, 0.6])) C_errors = np.zeros(len(shape_names)) N_errors = np.zeros(len(shape_names)) 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 C0_32F = LambertShader().diffuseShading(L, Ng_32F) sfs_method = ToonSFS(L, C0_32F, A_8U) sfs_method.setInitialNormal(N0_32F) sfs_method.setNumIterations(iterations=60) sfs_method.run() N_32F = sfs_method.normal() C_32F = sfs_method.shading() C_error = sfs_method.shadingError() C_error[A_8U < 0.5 * np.max(A_8U)] = 0.0 C_errors[si] = np.average(C_error[A_8U > 0.5 * np.max(A_8U)]) h, w = A_8U.shape[:2] N_error = angleErros(N_32F.reshape(-1, 3), Ng_32F.reshape(-1, 3)).reshape(h, w) N_error[A_8U < 0.5 * np.max(A_8U)] = 0.0 N_errors[si] = np.average(N_error[A_8U > 0.5 * np.max(A_8U)]) file_path = shapeResultFile("ShapeEstimation", "ShadingError", file_ext=".npy") np.save(file_path, C_errors) file_path = shapeResultFile("ShapeEstimation", "NormalError", file_ext=".npy") np.save(file_path, N_errors)
def shapeErrorTable(): cmap_id = 10 colormap_file = colorMapFile(cmap_id) M_32F = loadColorMap(colormap_file) L = normalizeVector(np.array([-0.4, 0.5, 0.6])) num_shapes = len(shapeNames()) C_errors = np.zeros((num_shapes, 3)) N_errors = np.zeros((num_shapes, 3)) I_errors = np.zeros((num_shapes, 3)) for si, shape_name in enumerate(shapeNames()): 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 A_8U = cv2.bilateralFilter(A_8U, 0, 5, 2) C0_32F = ColorMapShader(M_32F).diffuseShading(L, Ng_32F) toon_sfs = ToonSFS(L, C0_32F, A_8U) toon_sfs.setInitialNormal(N0_32F) toon_sfs.setNumIterations(iterations=20) toon_sfs.setWeights(w_lap=9.0) toon_sfs.run() N_toon = toon_sfs.normal() C_toon = toon_sfs.shading() C_lumo, N_lumo = lumoSFS(C0_32F, L, N0_32F, A_8U) C_wu, N_wu = wuSFS(C0_32F, L, N0_32F, A_8U) C_error_toon, N_error_toon, I_error_toon = computeErrors( L, C0_32F, C_toon, Ng_32F, N_toon, A_8U) C_error_lumo, N_error_lumo, I_error_lumo = computeErrors( L, C0_32F, C_lumo, Ng_32F, N_lumo, A_8U) C_error_wu, N_error_wu, I_error_wu = computeErrors( L, C0_32F, C_wu, Ng_32F, N_wu, A_8U) C_errors[si, 0] = np.mean(C_error_toon) C_errors[si, 1] = np.mean(C_error_lumo) C_errors[si, 2] = np.mean(C_error_wu) I_errors[si, 0] = np.mean(I_error_toon) I_errors[si, 1] = np.mean(I_error_lumo) I_errors[si, 2] = np.mean(I_error_wu) N_errors[si, 0] = np.mean(N_error_toon) N_errors[si, 1] = np.mean(N_error_lumo) N_errors[si, 2] = np.mean(N_error_wu) file_path = shapeResultFile("ShapeEstimation", "ShapeShadingError", file_ext=".npy") np.save(file_path, C_errors) file_path = shapeResultFile("ShapeEstimation", "ShapeNormalError", file_ext=".npy") np.save(file_path, N_errors) file_path = shapeResultFile("ShapeEstimation", "ShapeIlluminationErrorShape", file_ext=".npy") np.save(file_path, I_errors) showShapeErrorTable()
def shapeErrorTable(): cmap_id = 10 colormap_file = colorMapFile(cmap_id) M_32F = loadColorMap(colormap_file) L = normalizeVector(np.array([-0.4, 0.5, 0.6])) num_shapes = len(shapeNames()) C_errors = np.zeros((num_shapes, 3)) N_errors = np.zeros((num_shapes, 3)) I_errors = np.zeros((num_shapes, 3)) for si, shape_name in enumerate(shapeNames()): 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 A_8U = cv2.bilateralFilter(A_8U, 0, 5, 2) C0_32F = ColorMapShader(M_32F).diffuseShading(L, Ng_32F) toon_sfs = ToonSFS(L, C0_32F, A_8U) toon_sfs.setInitialNormal(N0_32F) toon_sfs.setNumIterations(iterations=20) toon_sfs.setWeights(w_lap=9.0) toon_sfs.run() N_toon = toon_sfs.normal() C_toon = toon_sfs.shading() C_lumo, N_lumo = lumoSFS(C0_32F, L, N0_32F, A_8U) C_wu, N_wu = wuSFS(C0_32F, L, N0_32F, A_8U) C_error_toon, N_error_toon, I_error_toon = computeErrors(L, C0_32F, C_toon, Ng_32F, N_toon, A_8U) C_error_lumo, N_error_lumo, I_error_lumo = computeErrors(L, C0_32F, C_lumo, Ng_32F, N_lumo, A_8U) C_error_wu, N_error_wu, I_error_wu = computeErrors(L, C0_32F, C_wu, Ng_32F, N_wu, A_8U) C_errors[si, 0] = np.mean(C_error_toon) C_errors[si, 1] = np.mean(C_error_lumo) C_errors[si, 2] = np.mean(C_error_wu) I_errors[si, 0] = np.mean(I_error_toon) I_errors[si, 1] = np.mean(I_error_lumo) I_errors[si, 2] = np.mean(I_error_wu) N_errors[si, 0] = np.mean(N_error_toon) N_errors[si, 1] = np.mean(N_error_lumo) N_errors[si, 2] = np.mean(N_error_wu) file_path = shapeResultFile("ShapeEstimation", "ShapeShadingError", file_ext=".npy") np.save(file_path, C_errors) file_path = shapeResultFile("ShapeEstimation", "ShapeNormalError", file_ext=".npy") np.save(file_path, N_errors) file_path = shapeResultFile("ShapeEstimation", "ShapeIlluminationErrorShape", file_ext=".npy") np.save(file_path, I_errors) showShapeErrorTable()