def _plot_normals_entry(scene, disp_map, gt, mask_planes, mask_contin,
                        algo_name, metric_mae_contin, metric_mae_planes, idx,
                        grid, entries_per_row, n_vis_types, cols,
                        colorbar_args, fs):

    add_ylabel = not idx % entries_per_row  # is first column
    add_colorbar = not (idx + 1) % entries_per_row  # is last column
    idx_row = (idx / entries_per_row) * n_vis_types
    idx_col = idx % entries_per_row

    idx = idx_row * cols + idx_col

    # plot disparity map
    plt.subplot(grid[idx])
    cb = plt.imshow(disp_map, **settings.disp_map_args(scene))
    plt.title(algo_name, fontsize=fs)

    if add_ylabel:
        plt.ylabel("DispMap", fontsize=fs)
    if add_colorbar:
        plotting.add_colorbar(grid[idx + 1], cb, **colorbar_args)

    # plot normal map
    plt.subplot(grid[idx + cols])
    plt.imshow(scene.get_normal_vis_from_disp_map(disp_map))

    if add_ylabel:
        plt.ylabel("Normals", fontsize=fs)

    # plot angular errors
    plt.subplot(grid[idx + 2 * cols])

    # compute angular errors
    try:
        score_contin = "%0.2f" % metric_mae_contin.get_score(
            disp_map, gt, scene)
    except IOError:
        score_contin = "-"

    try:
        score_planes = "%0.2f" % metric_mae_planes.get_score(
            disp_map, gt, scene)
    except IOError:
        score_planes = "-"

    plt.title("%s / %s" % (score_contin, score_planes), fontsize=fs)

    if add_ylabel:
        plt.ylabel("Angular Error", fontsize=fs)

    # get combined error visualization (if applicable)
    mask = mask_contin + mask_planes
    if np.sum(mask) > 0:
        score, vis_normals = metric_mae_contin.get_score_from_mask(
            disp_map, gt, scene, mask, with_visualization=True)
        cb = plt.imshow(vis_normals, **settings.metric_args(metric_mae_contin))

        if add_colorbar:
            plotting.add_colorbar(grid[idx + 2 * cols + 1], cb,
                                  **colorbar_args)
示例#2
0
def plot_scene_difficulty(scenes, subdir="overview", fs=10):

    n_scenes_per_row = 4
    rows, cols = 6, n_scenes_per_row + 1
    fig = plt.figure(figsize=(6, 9))
    grid, cb_height, cb_width = plotting.get_grid_with_colorbar(
        rows, cols, scenes[0])
    colorbar_args = {
        "height": cb_height,
        "width": cb_width,
        "colorbar_bins": 2,
        "fontsize": fs
    }

    median_algo = PerPixMedianDiff()
    best_algo = PerPixBest()

    for idx_s, scene in enumerate(scenes):
        # prepare data
        gt = scene.get_gt()
        median_result = misc.get_algo_result(median_algo, scene)
        best_result = misc.get_algo_result(best_algo, scene)

        idx_row = idx_s / n_scenes_per_row * 2
        idx_col = (idx_s % n_scenes_per_row)
        add_ylabel = not idx_s % n_scenes_per_row  # is first column
        add_colorbar = idx_col == (n_scenes_per_row - 1)  # is last column

        idx = idx_row * cols + idx_col

        # plot errors for median result
        plt.subplot(grid[idx])
        plt.title(scene.get_display_name(), fontsize=fs)
        cb = plt.imshow(np.abs(gt - median_result),
                        **settings.abs_diff_map_args())

        if add_ylabel:
            plt.ylabel("|GT - %s|" % median_algo.get_display_name(),
                       fontsize=fs - 2)
        if add_colorbar:
            plotting.add_colorbar(grid[idx + 1], cb, **colorbar_args)

        # plot error for best result
        plt.subplot(grid[idx + cols])
        cb = plt.imshow(np.abs(gt - best_result),
                        **settings.abs_diff_map_args())

        if add_ylabel:
            plt.ylabel("|GT - %s|" % best_algo.get_display_name(),
                       fontsize=fs - 2)
        if add_colorbar:
            plotting.add_colorbar(grid[idx + cols + 1], cb, **colorbar_args)

    fig_path = plotting.get_path_to_figure("scene_difficulty", subdir=subdir)
    plotting.save_tight_figure(fig,
                               fig_path,
                               hide_frames=True,
                               hspace=0.08,
                               wspace=0.03)
def plot(algorithms,
         scenes,
         thresh=settings.BAD_PIX_THRESH,
         subdir="error_heatmaps",
         fs=18,
         max_per_row=4):

    # prepare figure
    n_scenes = len(scenes)
    cols = min(n_scenes, max_per_row) + 1  # + 1 for colorbars
    rows = int(np.ceil(n_scenes / float(cols - 1)))
    fig = plt.figure(figsize=(2.7 * cols, 3 * rows))
    grid, cbh, cbw = plotting.get_grid_with_colorbar(rows,
                                                     cols,
                                                     scenes[0],
                                                     hscale=1,
                                                     wscale=9)
    colorbar_args = {
        "height": cbh,
        "width": cbw,
        "colorbar_bins": 5,
        "fontsize": 10,
        "scale": 0.8
    }

    # plot heatmaps
    idx_scene = 0
    for idx in range(rows * cols):

        if (idx + 1) % cols:
            # plot error heatmap for scene
            scene = scenes[idx_scene]
            idx_scene += 1

            plt.subplot(grid[idx])
            bad_count = get_bad_count(scene,
                                      algorithms,
                                      thresh,
                                      percentage=True)
            cm = plt.imshow(bad_count, vmin=0, vmax=100, cmap="inferno")
            plt.ylabel(scene.get_display_name(), fontsize=fs, labelpad=2.5)
        else:
            # plot colorbar
            plotting.add_colorbar(grid[idx], cm, **colorbar_args)

        if idx_scene >= n_scenes:
            if idx % cols or n_scenes == 1:
                plotting.add_colorbar(grid[idx + 1], cm, **colorbar_args)
            break

    plt.suptitle(
        "Per Pixel: Percentage of %d Algorithms with abs(gt-algo) > %0.2f" %
        (len(algorithms), thresh),
        fontsize=fs)

    fig_name = ("error_heatmaps_%.3f" % thresh).replace(".", "")
    fig_path = plotting.get_path_to_figure(fig_name, subdir=subdir)
    plotting.save_tight_figure(fig, fig_path, hide_frames=True, hspace=0.02)
示例#4
0
def plot_normals_explanation(algorithm, scene, fs=14, subdir="overview"):
    # prepare figure
    rows, cols = 1, 4
    fig = plt.figure(figsize=(10, 4))
    grid, cb_height, cb_width = plotting.get_grid_with_colorbar(
        rows, cols, scene)

    # prepare metrics
    normals_contin = MAEContinSurf()
    normals_planes = MAEPlanes()

    # prepare data
    gt = scene.get_gt()
    algo_result = misc.get_algo_result(algorithm, scene)
    mask = normals_contin.get_evaluation_mask(
        scene) + normals_planes.get_evaluation_mask(scene)
    score_normals, vis_normals = normals_contin.get_score_from_mask(
        algo_result, gt, scene, mask, with_visualization=True)

    # plot ground truth normals
    plt.subplot(grid[0])
    plt.imshow(scene.get_normal_vis_from_disp_map(gt))
    plt.title("Ground Truth Normals", fontsize=fs)

    # plot algorithm normals
    plt.subplot(grid[1])
    plt.imshow(scene.get_normal_vis_from_disp_map(algo_result))
    plt.title("Algorithm Normals", fontsize=fs)

    # plot median angular error with colorbar
    plt.subplot(grid[2])
    cb = plt.imshow(vis_normals, **settings.metric_args(normals_contin))
    plt.title("Median Angular Error: %0.1f" % score_normals, fontsize=fs)
    plt.subplot(grid[3])
    plotting.add_colorbar(grid[3],
                          cb,
                          cb_height,
                          cb_width,
                          colorbar_bins=4,
                          fontsize=fs)

    # save figure
    fig_name = "metrics_%s_%s" % (scene.get_name(), algorithm.get_name())
    fig_path = plotting.get_path_to_figure(fig_name, subdir=subdir)
    plotting.save_tight_figure(fig,
                               fig_path,
                               hide_frames=False,
                               hspace=0.04,
                               wspace=0.03)
示例#5
0
def plot_discont_overview(algorithms,
                          scene,
                          n_rows=2,
                          fs=15,
                          subdir="overview",
                          xmin=150,
                          ymin=230,
                          ww=250):

    # prepare figure grid
    n_vis_types = 2
    n_entries_per_row = int(np.ceil((len(algorithms) + 1) / float(n_rows)))
    rows, cols = (n_vis_types * n_rows), n_entries_per_row + 1

    fig = plt.figure(figsize=(cols * 1.7, 1.45 * rows * 1.5))
    grid, cb_height, cb_width = plotting.get_grid_with_colorbar(
        rows, cols, scene)
    colorbar_args = {
        "height": cb_height,
        "width": cb_width,
        "colorbar_bins": 7,
        "fontsize": fs
    }

    # prepare data
    median_algo = PerPixMedianDiff()
    gt = scene.get_gt()
    median_result = misc.get_algo_result(median_algo, scene)
    center_view = scene.get_center_view()

    # center view
    plt.subplot(grid[0])
    plt.imshow(center_view[ymin:ymin + ww, xmin:xmin + ww])
    plt.title("Center View", fontsize=fs)
    plt.ylabel("DispMap", fontsize=fs)
    plt.subplot(grid[cols])
    plt.ylabel("MedianDiff", fontsize=fs)

    for idx_a, algorithm in enumerate(algorithms):
        algo_result = misc.get_algo_result(algorithm, scene)
        idx = idx_a + 1

        add_ylabel = not idx % n_entries_per_row  # is first column
        add_colorbar = not (idx + 1) % n_entries_per_row  # is last column
        idx_row = (idx / n_entries_per_row) * n_vis_types
        idx_col = idx % n_entries_per_row

        idx = idx_row * cols + idx_col

        # top row with algorithm disparity map
        plt.subplot(grid[idx])
        algo_result_crop = algo_result[ymin:ymin + ww, xmin:xmin + ww]
        cb_depth = plt.imshow(algo_result_crop,
                              **settings.disp_map_args(scene))
        plt.title(algorithm.get_display_name(), fontsize=fs)

        if add_ylabel:
            plt.ylabel("DispMap", fontsize=fs)
        if add_colorbar:
            plotting.add_colorbar(grid[idx + 1], cb_depth, **colorbar_args)

        # second row with median diff
        plt.subplot(grid[idx + cols])
        diff = (np.abs(median_result - gt) -
                np.abs(algo_result - gt))[ymin:ymin + ww, xmin:xmin + ww]
        cb_error = plt.imshow(diff,
                              interpolation="none",
                              cmap=cm.RdYlGn,
                              vmin=-.05,
                              vmax=.05)

        if add_ylabel:
            plt.ylabel("MedianDiff", fontsize=fs)
        if add_colorbar:
            plotting.add_colorbar(grid[idx + cols + 1], cb_error,
                                  **colorbar_args)

    fig_path = plotting.get_path_to_figure("discont_%s" % scene.get_name(),
                                           subdir=subdir)
    plotting.save_tight_figure(fig,
                               fig_path,
                               hide_frames=True,
                               hspace=0.03,
                               wspace=0.03,
                               dpi=100)
def plot_general_overview(algorithms,
                          scenes,
                          metrics,
                          fig_name=None,
                          subdir=SUBDIR,
                          fs=11):
    n_vis_types = len(metrics)

    # prepare figure grid
    rows, cols = len(scenes) * n_vis_types, len(algorithms) + 1
    fig = plt.figure(figsize=(cols * 1.4, 1.15 * rows * 1.6))
    grid, cb_height, cb_width = plotting.get_grid_with_colorbar(
        rows, cols, scenes[0])

    for idx_s, scene in enumerate(scenes):
        gt = scene.get_gt()
        applicable_metrics = scene.get_applicable_metrics(metrics)

        for idx_a, algorithm in enumerate(algorithms):
            algo_result = misc.get_algo_result(algorithm, scene)

            for idx_m, metric in enumerate(metrics):
                idx = (n_vis_types * idx_s + idx_m) * cols + idx_a
                ylabel = metric.get_display_name()
                plt.subplot(grid[idx])

                if metric in applicable_metrics:
                    score, vis = metric.get_score(algo_result,
                                                  gt,
                                                  scene,
                                                  with_visualization=True)

                    cb = plt.imshow(vis, **settings.metric_args(metric))

                    # add algorithm name and metric score on top row
                    if idx_s == 0 and idx_m == 0:
                        plt.title("%s\n%0.2f" %
                                  (algorithm.get_display_name(), score),
                                  fontsize=fs)
                    else:
                        plt.title("%0.2f" % score, fontsize=fs)

                    # add colorbar to last column
                    if idx_a == len(algorithms) - 1:
                        plotting.add_colorbar(
                            grid[idx + 1],
                            cb,
                            cb_height,
                            cb_width,
                            colorbar_bins=metric.colorbar_bins,
                            fontsize=fs)

                    # add metric name to first column
                    if idx_a == 0:
                        plt.ylabel(ylabel)

                else:
                    if idx_a == 0:
                        log.warning("Metric %s not applicable for scene %s." %
                                    (metric.get_display_name(),
                                     scene.get_display_name()))
                        plt.ylabel(ylabel + "\n(not applicable)")

    # save figure
    if fig_name is None:
        fig_name = "metric_overview_%s_%s" % ("_".join(
            metric.get_id()
            for metric in metrics), "_".join(scene.get_name()
                                             for scene in scenes))

    fig_path = plotting.get_path_to_figure(fig_name, subdir=subdir)
    plotting.save_tight_figure(fig,
                               fig_path,
                               hide_frames=True,
                               hspace=0.01,
                               wspace=0.01)
示例#7
0
def plot(algorithms,
         scenes,
         meta_algo,
         subdir="meta_algo_comparisons",
         fig_name=None,
         with_gt_row=False,
         fs=12):

    # prepare figure
    rows, cols = len(algorithms) + int(with_gt_row), len(scenes) * 3 + 1
    fig = plt.figure(figsize=(cols * 1.3, rows * 1.5))
    grid, cb_height, cb_width = plotting.get_grid_with_colorbar(
        rows, cols, scenes[0])
    colorbar_args = {
        "height": cb_height * 0.8,
        "width": cb_width,
        "colorbar_bins": 4,
        "fontsize": fs
    }

    for idx_s, scene in enumerate(scenes):
        gt = scene.get_gt()
        meta_algo_result = misc.get_algo_result(meta_algo, scene)
        add_label = idx_s == 0  # is first column
        add_colorbar = idx_s == len(scenes) - 1  # is last column

        # plot one row per algorithm
        for idx_a, algorithm in enumerate(algorithms):
            algo_result = misc.get_algo_result(algorithm, scene)
            add_title = idx_a == 0  # is top row

            idx = idx_a * cols + 3 * idx_s

            # disparity map
            plt.subplot(grid[idx])
            plt.imshow(algo_result, **settings.disp_map_args(scene))
            if add_title:
                plt.title("DispMap", fontsize=fs)
            if add_label:
                plt.ylabel(algorithm.get_display_name(), fontsize=fs)

            # error map: gt - algo
            plt.subplot(grid[idx + 1])
            cb1 = plt.imshow(gt - algo_result,
                             **settings.diff_map_args(vmin=-.1, vmax=.1))
            if add_title:
                plt.title("GT-Algo", fontsize=fs)

            # error map: |meta-gt| - |algo-gt|
            plt.subplot(grid[idx + 2])
            median_diff = np.abs(meta_algo_result - gt) - np.abs(algo_result -
                                                                 gt)
            cb2 = plt.imshow(median_diff,
                             interpolation="none",
                             cmap=cm.RdYlGn,
                             vmin=-.05,
                             vmax=.05)
            if add_title:
                plt.title(meta_algo.get_display_name().replace("PerPix", ""),
                          fontsize=fs)

            if add_colorbar:
                if idx_a % 2 == 0:
                    plotting.add_colorbar(grid[idx + 3], cb1, **colorbar_args)
                else:
                    plotting.add_colorbar(grid[idx + 3], cb2, **colorbar_args)

        if with_gt_row:
            idx = len(algorithms) * cols + 3 * idx_s

            plt.subplot(grid[idx])
            plt.imshow(gt, **settings.disp_map_args(scene))
            plt.xlabel("GT", fontsize=fs)

            if add_label:
                plt.ylabel("Reference")

            plt.subplot(grid[idx + 1])
            cb1 = plt.imshow(np.abs(gt - meta_algo_result),
                             **settings.abs_diff_map_args())
            plt.xlabel("|GT-%s|" % meta_algo.get_display_name(),
                       fontsize=fs - 2)

            if add_colorbar:
                plotting.add_colorbar(grid[idx + 3], cb1, **colorbar_args)

    if fig_name is None:
        scene_names = "_".join(s.get_name() for s in scenes)
        fig_name = "%s_comparison_%s" % (meta_algo.get_name(), scene_names)
    fig_path = plotting.get_path_to_figure(fig_name, subdir=subdir)
    plotting.save_tight_figure(fig,
                               fig_path,
                               hide_frames=True,
                               hspace=0.02,
                               wspace=0.0)
    def plot_algo_overview(self,
                           algorithms,
                           with_metric_vis=True,
                           subdir="algo_overview",
                           fs=14):
        self.set_scale_for_algo_overview()
        metrics = self.get_scene_specific_metrics()
        n_metrics = len(metrics)

        if not with_metric_vis:
            rows, cols = 2 + n_metrics, len(algorithms) + 2
            fig = plt.figure(figsize=(2.6 * len(algorithms), 4.9))
            offset = 0
        else:
            rows, cols = 2 + 2 * n_metrics, len(algorithms) + 2
            fig = plt.figure(figsize=(2.6 * len(algorithms), rows + 3))
            offset = n_metrics

        labelpad = -15
        hscale, wscale = 7, 5
        width_ratios = [wscale] * (len(algorithms) + 1) + [1]
        height_ratios = [hscale] * (rows - n_metrics) + [1] * n_metrics
        gs = gridspec.GridSpec(rows,
                               cols,
                               height_ratios=height_ratios,
                               width_ratios=width_ratios)

        gt = self.get_gt()
        dummy = np.ones((self.get_height() / hscale, self.get_width()))
        cb_height, w = np.shape(gt)
        cb_width = w / float(wscale)

        # first column (gt, center view, ...)
        plt.subplot(gs[0])
        plt.imshow(gt, **settings.disp_map_args(self))
        plt.title("Ground Truth", fontsize=fs)
        plt.ylabel("Disparity Map", fontsize=fs)

        plt.subplot(gs[cols])
        plt.imshow(self.get_center_view())
        plt.ylabel("diff: GT - Algo", fontsize=fs)

        for idx_m, metric in enumerate(metrics):
            plt.subplot(gs[(2 + idx_m + offset) * cols])
            plt.xlabel(metric.get_short_name(), labelpad=labelpad, fontsize=fs)
            plt.imshow(dummy, cmap="gray_r")

        # algorithm columns
        for idx_a, algorithm in enumerate(algorithms):
            log.info("Processing algorithm: %s" % algorithm)
            algo_result = misc.get_algo_result(algorithm, self)

            # algorithm disparities
            plt.subplot(gs[idx_a + 1])
            plt.title(algorithm.get_display_name(), fontsize=fs)
            cm1 = plt.imshow(algo_result, **settings.disp_map_args(self))

            # algorithm diff map
            plt.subplot(gs[cols + idx_a + 1])
            cm2 = plt.imshow(gt - algo_result, **settings.diff_map_args())

            # add colorbar if last column
            if idx_a == (len(algorithms) - 1):
                plotting.add_colorbar(gs[idx_a + 2],
                                      cm1,
                                      cb_height,
                                      cb_width,
                                      colorbar_bins=5,
                                      fontsize=fs - 4)
                plotting.add_colorbar(gs[cols + idx_a + 2],
                                      cm2,
                                      cb_height,
                                      cb_width,
                                      colorbar_bins=5,
                                      fontsize=fs - 4)

            # score and background color for metrics
            for idx_m, metric in enumerate(metrics):

                if with_metric_vis:
                    plt.subplot(gs[(2 + idx_m) * cols + idx_a + 1])
                    score, vis = metric.get_score(algo_result,
                                                  gt,
                                                  self,
                                                  with_visualization=True)
                    cm3 = plt.imshow(vis, **settings.metric_args(metric))

                    if idx_a == 0:
                        plt.ylabel(metric.get_short_name(), fontsize=fs)
                    elif idx_a == (len(algorithms) - 1):
                        plotting.add_colorbar(
                            gs[(2 + idx_m) * cols + idx_a + 2],
                            cm3,
                            cb_height,
                            cb_width,
                            colorbar_bins=metric.colorbar_bins,
                            fontsize=fs - 4)

                else:
                    score = metric.get_score(algo_result, gt, self)

                plt.subplot(gs[(2 + idx_m + offset) * cols + idx_a + 1])
                plt.imshow(
                    dummy * score,
                    **settings.score_color_args(vmin=metric.vmin,
                                                vmax=metric.vmax))
                plt.xlabel(metric.format_score(score),
                           labelpad=labelpad,
                           fontsize=fs)

        fig_name = "algo_overview_" + self.get_name(
        ) + with_metric_vis * "_vis"
        fig_path = plotting.get_path_to_figure(fig_name, subdir=subdir)
        plotting.save_tight_figure(fig,
                                   fig_path,
                                   wspace=0.04,
                                   hide_frames=True)