def estimateResultFunc(data_name, target_name, N_32F, L_g, I_32F, A_8U, method_name, estimate_func): L_g = normalizeVector(L_g) silhouette_curve, S_8U = silhoutteCurve(A_8U) N_sil = silhouetteNormal(A_8U) silhouette_curve.setNormalImage(N_sil) N_sil = silhouette_curve.normals() cvs_sil = silhouette_curve.CVs() I_sil = np.array([I_32F[cv[1], cv[0]] for cv in cvs_sil]) input_data = {"N_sil": N_sil, "I_sil": I_sil, "cvs_sil": cvs_sil, "I": I_32F, "A": A_8U} fig = plt.figure(figsize=(8, 8)) fig.suptitle("Light estimation: %s" % method_name) fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.82, wspace=0.02, hspace=0.4) plt.subplot(2, 2, 1) plt.title("Ground truth") showLightSphere(plt, L_g) plt.axis("off") plt.subplot(2, 2, 2) plt.title("Illumination") A_32F = to32F(A_8U) I_org = I_32F * A_32F plt.gray() plt.imshow(I_org) plt.axis("off") output_data = estimate_func(input_data) L = output_data["L"] L = normalizeVector(L) L_error = angleError(L_g, L) plt.subplot(2, 2, 3) plt.title("Estimated error\n %4.1f $^\circ$" % L_error) showLightSphere(plt, L) plt.axis("off") I_est = lambert.diffuse(N_32F, L) * A_32F plt.subplot(2, 2, 4) plt.gray() plt.imshow(I_est) plt.axis("off") result_dir = resultDir("LightEstimation/%s" % data_name) result_file = resultFile(result_dir, "%s_%s" % (target_name, method_name)) plt.savefig(result_file)
def normalToIsophoteFile(normal_file, scene_file, L1=np.array([-0.5, 0.5, 0.2]), L2=np.array([0.5, 0.5, 0.2])): N_32F, A_8U = loadNormal(normal_file) silhoutte_curve, S_8U = silhoutteCurve(A_8U) silhoutte_curve.setNormalImage(N_32F) I1_32F, isophotes1 = computeIsophoteCurves(N_32F, L1, S_8U) I2_32F, isophotes2 = computeIsophoteCurves(N_32F, L2, S_8U) isophote_curves = [] isophote_curves.extend(isophotes1) isophote_curves.extend(isophotes2) isophote_mesh = IsophoteMesh(silhoutte_curve, isophote_curves) scene = Scene(isophote_mesh, normal_file) saveSceneData(scene_file, scene)