def visualize_error_function(camera_parameters, I0, D0, I1, xi_pred):

    def generate_error_curve(i, start, stop, n):
        xi = np.copy(xi_pred)
        vs = (xi[i] + np.linspace(start, stop, n))
        errors = []
        for v in vs:
            xi[i] = v
            DG = exp_se3(xi)
            (estimated, mask) = warp(camera_parameters, I1, D0, DG)
            errors.append(error(I0, estimated, mask))
        errors = np.array(errors)
        return (vs, errors)
    from matplotlib import pyplot as plt
    fig = plt.figure()
    for (xi_index, ax_index) in enumerate([1, 3, 5, 2, 4, 6]):
        ax = fig.add_subplot(3, 2, ax_index)
        (vs, errors) = generate_error_curve(xi_index, start=(- 0.1), stop=0.1, n=101)
        ax.set_title('Axis {}'.format((xi_index + 1)))
        ax.axvline(vs[np.argmin(errors)], label='ground truth')
        ax.axvline(xi_pred[xi_index], color='red', label='prediction')
        ax.legend()
        ax.plot(vs, errors)
    plt.show()
def visualize_error_function(camera_parameters, I0, D0, I1, xi_pred):

    def generate_error_curve(i, start, stop, n):
        xi = np.copy(xi_pred)
        vs = (xi[i] + np.linspace(start, stop, n))
        errors = []
        for v in vs:
            xi[i] = v
            DG = exp_se3(xi)
            (estimated, mask) = warp(camera_parameters, I1, D0, DG)
            errors.append(error(I0, estimated, mask))
        errors = np.array(errors)
        return (vs, errors)
    from matplotlib import pyplot as plt
    fig = plt.figure()
    for (xi_index, ax_index) in enumerate([1, 3, 5, 2, 4, 6]):
        ax = fig.add_subplot(3, 2, ax_index)
        (vs, errors) = generate_error_curve(xi_index, start=(- 0.1), stop=0.1, n=101)
        ax.set_title('Axis {}'.format((xi_index + 1)))
        ax.axvline(vs[np.argmin(errors)], label='ground truth')
        ax.axvline(xi_pred[xi_index], color='red', label='prediction')
        ax.legend()
        ax.plot(vs, errors)
    plt.show()