def curvatureVSconeAnglesFigure(scnene_plotter, data_name, segment_id, result_data):
    fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(11, 5))
    font_size = 15
    fig.subplots_adjust(left=0.05, right=0.95, top=0.86, hspace=0.1, wspace=0.05)
    fig.suptitle("Curvature VS Cone Angle", fontsize=font_size)

    plt.subplot(131)
    scnene_plotter.showNormalImage()
    plt.axis("off")
    plt.title("Curvature\n", fontsize=font_size)
    plotFeatureChanges(plt, result_data["ps"], result_data["curvatures"])

    plt.subplot(132)
    scnene_plotter.showNormalImage()
    plt.axis("off")
    plt.title("Cone Angle\n", fontsize=font_size)
    plotFeatureChanges(plt, result_data["ps"], result_data["cone_angle_changes"])

    plt.subplot(133)
    scnene_plotter.showNormalImage()
    plt.axis("off")
    plt.title("Misclassification\n%5.1f %%" % (100 * result_data["misclassification_rate"]), fontsize=font_size)

    for segment in result_data["misclassification_segments"]:
        plotSegment(plt, segment, color=(0.8, 0.2, 0.2))

    result_name = "cone_vs_curvature/misclassification"
    result_dir = resultDir(result_name)

    result_file = resultFile(result_dir, data_name + "_%s" % segment_id)
    plt.savefig(result_file, transparent=True)
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)
Beispiel #3
0
def arcVSprojectFigure(scnene_plotter, data_name, segment_id, result_data):
    fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(11, 5))
    font_size = 15
    fig.subplots_adjust(left=0.15, right=0.9, top=0.86, hspace=0.1, wspace=0.05)
    fig.suptitle("Arc-Length Interpolation VS Project 3D", fontsize=font_size)

    plt.subplot(131)
    plt.title('Normal Vectors\n', fontsize=font_size)
    scnene_plotter.showNormalImage()
    plt.axis('off')

    legend_gt = ("Ground Truth", (1.0, 0.0, 0.0))
    legend_al = ("Arc-Length", (0.0, 1.0, 0.0))
    legend_3d = ("Project 3D", (0.0, 0.0, 1.0))

    plotVectors(plt, result_data["ps"], result_data["normals_gt"], color=legend_gt[1], l=70, step=2)
    plotVectors(plt, result_data["ps"], result_data["normals_al"], color=legend_al[1], l=70, step=2)
    plotVectors(plt, result_data["ps"], result_data["normals_3D"], color=legend_3d[1], l=70, step=2)

    plt.legend(bbox_to_anchor=(0.2, 1), handles=[mpatches.Patch(color=legend_gt[1], label=legend_gt[0]),
                        mpatches.Patch(color=legend_al[1], label=legend_al[0]),
                        mpatches.Patch(color=legend_3d[1], label=legend_3d[0])])
    error_max = 30.0
    error_min = 0.0

    plt.subplot(132)
    scnene_plotter.showNormalImage()
    plt.axis('off')
    plt.title('Arc-Length Error\n %5.2f $^\circ$' %np.average(result_data["normals_al_error"]), fontsize=font_size)
    error_colors = scalarToColor(result_data["normals_al_error"], vmin=error_min, vmax=error_max)
    plotSegment(plt, result_data["ps"], error_colors)

    plt.subplot(133)
    scnene_plotter.showNormalImage()
    plt.axis('off')
    plt.title('Project 3D Error\n %5.2f $^\circ$' %np.average(result_data["normals_3d_error"]), fontsize=font_size)
    error_colors = scalarToColor(result_data["normals_3d_error"], vmin=error_min, vmax=error_max)
    plotSegment(plt, result_data["ps"], error_colors)

    ax_colorbar = fig.add_axes([0.9, 0.15, 0.03, 0.7])

    scalar_map = scalarMap(error_min, error_max)
    scalar_map.set_array([error_min, error_max])
    fig.colorbar(scalar_map, cax=ax_colorbar)

    result_name = "arc_vs_project"
    result_dir = resultDir(result_name)

    result_file = resultFile(result_dir, data_name + "_%s" % segment_id)
    plt.savefig(result_file, transparent=True)
def curvatureVSconeAnglesNormal(scnene_plotter, data_name, segment_id, result_data):
    fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(11, 5))
    font_size = 15
    fig.subplots_adjust(left=0.05, right=0.9, top=0.86, hspace=0.1, wspace=0.05)
    fig.suptitle("Arc-Length Interpolation", fontsize=font_size)

    plt.subplot(131)
    scnene_plotter.showNormalImage()
    plt.axis("off")
    plt.title("Ground Truth\n", fontsize=font_size)
    plotSegment(plt, result_data["ps"], color=(0.5, 0.1, 0.1))
    # plotVectors(plt, result_data["ps"], result_data["normals_gt"], step=5)

    plt.subplot(132)
    scnene_plotter.showNormalImage()
    plt.axis("off")
    plt.title("Interpolated Normal\n", fontsize=font_size)
    plotNormalColors(plt, result_data["ps"], result_data["normals_al"])

    plt.subplot(133)
    plt.title("Interpolation Error\n %4.1f $^\circ$" % np.max(result_data["normals_al_error"]), fontsize=font_size)
    scnene_plotter.showNormalImage()
    plt.axis("off")

    error_min = 0.0
    error_max = 30.0
    # error_max = np.max([0.0, np.max(result_data["normals_al_error"])])
    error_colors = scalarToColor(result_data["normals_al_error"], vmin=error_min, vmax=error_max)
    plotSegment(plt, result_data["ps"], error_colors)

    ax_colorbar = fig.add_axes([0.9, 0.15, 0.03, 0.7])

    scalar_map = scalarMap(error_min, error_max)
    scalar_map.set_array([error_min, error_max])
    fig.colorbar(scalar_map, cax=ax_colorbar)

    result_name = "cone_vs_curvature/normal"
    result_dir = resultDir(result_name)

    result_file = resultFile(result_dir, data_name + "_%s" % segment_id)
    plt.savefig(result_file, transparent=True)
def curvatureVSconeAnglesSignal(scnene_plotter, data_name, segment_id, result_data):
    fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(11, 5))
    font_size = 15
    fig.subplots_adjust(left=0.05, right=0.9, top=0.86, hspace=0.1, wspace=0.05)
    fig.suptitle("Curvature VS Cone Angle", fontsize=font_size)

    plt.subplot(131)
    scnene_plotter.showNormalImage()
    plt.axis("off")
    plt.title("Curvature", fontsize=font_size)
    curvature_colors = scalarToColor(result_data["curvatures"], vmin=-1.0, vmax=1.0)
    plotSegment(plt, result_data["ps"], curvature_colors)

    plt.subplot(132)
    scnene_plotter.showNormalImage()
    plt.axis("off")
    plt.title("Cone Angle", fontsize=font_size)
    cone_colors = scalarToColor(result_data["cone_angle_changes"], vmin=-1.0, vmax=1.0)
    plotSegment(plt, result_data["ps"], cone_colors)

    plt.subplot(133)
    plt.title("Signals", fontsize=font_size)
    xs = np.arange(len(result_data["curvatures"]))
    curvatures = result_data["curvatures"]
    cone_angle_changes = result_data["cone_angle_changes"]
    rescaled_curvatures = rescaleCurvature(curvatures, [cone_angle_changes[0], cone_angle_changes[-1]])
    plt.plot(xs, curvatures, label="Curvature")
    plt.plot(xs, cone_angle_changes, label="Cone Angle")
    # plt.plot(xs, rescaled_curvatures, label='Rescaled Curvatures')
    plt.legend()

    result_name = "cone_vs_curvature/signal"
    result_dir = resultDir(result_name)

    result_file = resultFile(result_dir, data_name + "_%s" % segment_id)
    plt.savefig(result_file, transparent=True)