Пример #1
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)
Пример #2
0
def main():
    parser = OptionParser([SceneOps(), AlgorithmOps(with_gt=True), MetaAlgorithmOps(default=[])])
    scenes, algorithms, meta_algorithms, compute_meta_algos = parser.parse_args()

    # delay imports to speed up usage response
    from toolkit import settings
    from toolkit.algorithms import MetaAlgorithm
    from toolkit.utils import log, misc, point_cloud

    if compute_meta_algos and meta_algorithms:
        MetaAlgorithm.prepare_meta_algorithms(meta_algorithms, algorithms, scenes)

    algorithms += meta_algorithms

    for scene in scenes:
        center_view = scene.get_center_view()

        for algorithm in algorithms:
            if algorithm.get_name() == "gt":
                disp_map = scene.get_gt()
            else:
                disp_map = misc.get_algo_result(algorithm, scene)

            log.info("Creating point cloud for scene '%s' with '%s' disparity map." %
                     (scene.get_name(), algorithm.get_name()))

            pc = point_cloud.convert(scene, disp_map, center_view)

            file_name = "%s_%s.ply" % (scene.get_name(), algorithm.get_name())
            file_path = op.join(settings.EVAL_PATH, "point_clouds", file_name)
            log.info("Saving point cloud to: %s" % file_path)
            point_cloud.save(pc, file_path)
def plot_pairwise_comparison(algo1,
                             algo2,
                             scenes,
                             n_scenes_per_row=4,
                             subdir="pairwise_diffs"):
    rows, cols = int(np.ceil(len(scenes) /
                             float(n_scenes_per_row))), n_scenes_per_row
    fig = plt.figure(figsize=(4 * cols, 3 * rows))

    for idx_s, scene in enumerate(scenes):
        algo_result_1 = misc.get_algo_result(algo1, scene)
        algo_result_2 = misc.get_algo_result(algo2, scene)
        gt = scene.get_gt()

        plt.subplot(rows, cols, idx_s + 1)
        cb = plt.imshow(np.abs(algo_result_1 - gt) -
                        np.abs(algo_result_2 - gt),
                        interpolation="none",
                        cmap=cm.seismic,
                        vmin=-.1,
                        vmax=.1)
        plt.colorbar(cb, shrink=0.7)
        plt.title(scene.get_display_name())

    # title
    a1 = algo1.get_display_name()
    a2 = algo2.get_display_name()
    plt.suptitle(
        "|%s - GT| - |%s - GT|\nblue: %s is better, red: %s is better" %
        (a1, a2, a1, a2))

    fig_name = "pairwise_diffs_%s_%s" % (algo1.get_name(), algo2.get_name())
    fig_path = plotting.get_path_to_figure(fig_name, subdir=subdir)
    plotting.save_tight_figure(fig,
                               fig_path,
                               hide_frames=True,
                               padding_top=0.85,
                               hspace=0.15,
                               wspace=0.15)
Пример #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_error_vs_noise(self, algorithms, subdir="stratified"):
        self.set_low_gt_scale()
        fig = plt.figure(figsize=(8, 4))

        grid = self.get_boxes()
        box_ids = sorted(list(np.unique(grid)))
        box_ids.remove(0)
        n_boxes = len(box_ids)
        mse = MSE()
        gt = self.get_gt()
        m_basic = self.get_boundary_mask()
        m_eval = self.get_background_mask() * m_basic

        x_values = np.arange(1, n_boxes + 1)

        for algorithm in algorithms:
            algo_result = misc.get_algo_result(algorithm, self)
            y_values = np.full(n_boxes, fill_value=np.nan)

            for idx_b, box_id in enumerate(box_ids):
                m_current = m_eval * (grid == box_id)
                y_values[idx_b] = mse.get_masked_score(algo_result, gt,
                                                       m_current)

            plt.plot(x_values,
                     y_values,
                     "o-",
                     color=algorithm.get_color(),
                     label=algorithm.get_display_name(),
                     lw=2,
                     alpha=0.9,
                     markeredgewidth=0)

        plt.legend(frameon=False,
                   loc="upper right",
                   ncol=1,
                   title="Algorithms:",
                   bbox_to_anchor=(1.25, 1),
                   borderaxespad=0.0)
        plt.xlabel("Cell IDs (increasing noise from left to right)")
        plt.ylabel("MSE on cell background")
        plt.title("%s: Error per Cell Background" % (self.get_display_name()))
        plotting.hide_upper_right()

        fig_path = plotting.get_path_to_figure("dots_per_box", subdir=subdir)
        plotting.save_tight_figure(fig, fig_path, remove_ticks=False)
Пример #6
0
def get_bad_count(scene, algorithms, thresh, percentage=False):
    bad_count = np.zeros(scene.get_shape())
    gt = scene.get_gt()

    for algorithm in algorithms:
        algo_result = misc.get_algo_result(algorithm, scene)
        abs_diffs = np.abs(gt - algo_result)

        with np.errstate(invalid="ignore"):
            bad = abs_diffs > thresh
            bad += misc.get_mask_invalid(abs_diffs)

        bad_count += bad

    if percentage:
        bad_count = misc.percentage(len(algorithms), bad_count)

    return bad_count
Пример #7
0
    def plot_metric_rows(self, grids, algorithms, metrics, offset, fontsize):
        gt = self.get_gt()
        center_view = self.get_center_view()

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

            # add algorithm disparity map
            plt.sca(grids[0][idx_a + 1])
            cm = plt.imshow(algo_result, **settings.disp_map_args(self))
            plt.title(algorithm.get_display_name(), fontsize=fontsize)

            # add colorbar to last disparity map in row
            if idx_a == (len(algorithms) - 1):
                plotting.create_colorbar(cm, cax=grids[0].cbar_axes[0],
                                         colorbar_bins=7, fontsize=fontsize)

            # add algorithm metric visualizations
            for idx_m, metric in enumerate(metrics):
                log.info(metric.get_display_name())
                mask = metric.get_evaluation_mask(self)

                plt.sca(grids[idx_m + offset + 1][idx_a + 1])
                cm = self.plot_algo_vis_for_metric(metric, algo_result, gt, mask,
                                                   self.hidden_gt(), fontsize)

                # add colorbar to last metric visualization in row
                if idx_a == len(algorithms) - 1:
                    plotting.create_colorbar(cm, cax=grids[idx_m + offset + 1].cbar_axes[0],
                                             colorbar_bins=metric.colorbar_bins, fontsize=fontsize)

                # add mask visualizations as 1st column
                if idx_a == 0:
                    plt.sca(grids[idx_m + offset + 1][0])
                    plotting.plot_img_with_transparent_mask(center_view, mask,
                                                            alpha=0.7, color=settings.MASK_COLOR)
                    plt.ylabel(metric.get_short_name(), fontsize=fontsize)
                    plt.title("Region Mask", fontsize=fontsize)
Пример #8
0
def compute_scores(algorithms,
                   scenes,
                   thresholds=THRESHOLDS,
                   penalize_missing_pixels=True):
    percentages_algo_thresh = np.full((len(algorithms), len(thresholds)),
                                      fill_value=np.nan)
    bad_pix_metric = BadPix()
    max_diff = np.max(thresholds)

    for idx_a, algorithm in enumerate(algorithms):
        combined_diffs = np.full(0, fill_value=np.nan)
        log.info('Computing BadPix scores for: %s' %
                 algorithm.get_display_name())

        for scene in scenes:
            gt = scene.get_gt()
            algo_result = misc.get_algo_result(algorithm, scene)
            diffs = np.abs(algo_result - gt)

            mask_valid = misc.get_mask_valid(
                algo_result) * misc.get_mask_valid(diffs)
            mask_eval = bad_pix_metric.get_evaluation_mask(scene)

            if penalize_missing_pixels:
                # penalize all invalid algorithm pixels with maximum error
                diffs[~mask_valid] = max_diff + 100
                diffs = diffs[mask_eval]
            else:
                diffs = diffs[mask_eval * mask_valid]

            combined_diffs = np.concatenate((combined_diffs, diffs))

        # compute BadPix score for each threshold
        for idx_t, t in enumerate(thresholds):
            bad_pix_metric.thresh = t
            bad_pix_score = bad_pix_metric.get_score_from_diffs(combined_diffs)
            percentages_algo_thresh[idx_a, idx_t] = 100 - bad_pix_score

    return percentages_algo_thresh
Пример #9
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)
Пример #10
0
def plot_normals(algorithms, scenes, n_rows=2, subdir=SUBDIR, fs=15):

    # prepare figure grid
    n_vis_types = 3
    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

    # initialize metrics
    metric_mae_contin = MAEContinSurf()
    metric_mae_planes = MAEPlanes()

    for scene in scenes:
        h, w = scene.get_shape()

        # prepare figure and colorbar size
        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
        }

        # some scenes have no evaluation mask for planar, non-planar or both surfaces
        try:
            mask_contin = metric_mae_contin.get_evaluation_mask(scene)
        except IOError:
            log.warning("No evaluation mask found for non-planar "
                        "continuous surfaces on: %s" %
                        scene.get_display_name())
            mask_contin = np.zeros((h, w), dtype=np.bool)
        try:
            mask_planes = metric_mae_planes.get_evaluation_mask(scene)
        except IOError:
            log.warning("No evaluation mask found for planar "
                        "continuous surfaces on: %s" %
                        scene.get_display_name())
            mask_planes = np.zeros((h, w), dtype=np.bool)

        # plot ground truth column
        gt = scene.get_gt()
        _plot_normals_entry(scene,
                            gt,
                            gt,
                            mask_planes,
                            mask_contin,
                            "GT",
                            metric_mae_contin,
                            metric_mae_planes,
                            0,
                            grid,
                            n_entries_per_row,
                            n_vis_types,
                            cols,
                            colorbar_args,
                            fs=fs)

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

            _plot_normals_entry(scene,
                                algo_result,
                                gt,
                                mask_planes,
                                mask_contin,
                                algorithm.get_display_name(),
                                metric_mae_contin,
                                metric_mae_planes,
                                idx_a + 1,
                                grid,
                                n_entries_per_row,
                                n_vis_types,
                                cols,
                                colorbar_args,
                                fs=fs)

        plt.suptitle("Angular Error: non-planar / planar surfaces",
                     fontsize=fs)

        # save figure
        fig_path = plotting.get_path_to_figure("normals_%s" % scene.get_name(),
                                               subdir=subdir)
        plotting.save_tight_figure(fig,
                                   fig_path,
                                   hide_frames=True,
                                   hspace=0.03,
                                   wspace=0.03)
Пример #11
0
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)
Пример #12
0
    def plot_algo_disp_vs_gt_disp(self, algorithms, subdir="stratified"):
        self.set_low_gt_scale()

        # prepare data
        gt = self.get_gt()
        m_eval = self.get_boundary_mask()
        mask_names = ["Sphere In", "Sphere Out"]
        masks = [self.get_sphere_in()*m_eval, self.get_sphere_out()*m_eval]

        factor = 1000.0
        gt_rounded = np.asarray(gt * factor, dtype=np.int)
        disp_values = np.unique(gt_rounded)
        n_values = np.size(disp_values)

        # prepare figure
        fig = plt.figure(figsize=(14, 6))
        rows, cols = 1, 2
        fontsize = 14
        legend_lines = []
        legend_labels = []

        for algorithm in algorithms:
            algo_result = misc.get_algo_result(algorithm, self)

            # go through ground truth disparity values
            for idx_d in range(n_values):
                current_disp = disp_values[idx_d]
                m_disp = (gt_rounded == current_disp)

                # find median disparity of algorithm result at image regions
                # of given ground truth disparity value
                for idx_m, (mask, mask_name) in enumerate(zip(masks, mask_names)):
                    algo_disps = algo_result[m_disp * mask]

                    if np.size(algo_disps) > 0:
                        median = np.median(algo_disps)
                        plt.subplot(rows, cols, idx_m+1)
                        s = plt.scatter(current_disp/factor, median,
                                        marker="o", c=algorithm.get_color(), alpha=0.8, s=5, lw=0)

            legend_lines.append(s)
            legend_labels.append(algorithm.get_display_name())

        # finalize figure attributes
        for idx_m, (mask, mask_name) in enumerate(zip(masks, mask_names)):
            plt.subplot(rows, cols, idx_m+1)
            vmin = np.min(gt_rounded[mask]) / factor
            vmax = np.max(gt_rounded[mask]) / factor
            plt.xlim([vmin, vmax])
            plt.ylim([vmin, vmax])
            plt.xlabel("Ground truth disparities", fontsize=fontsize)
            plt.ylabel("Algorithm disparities", fontsize=fontsize)
            plt.title(mask_name, fontsize=fontsize)
            plotting.hide_upper_right()

        legend = plt.legend(legend_lines, legend_labels, frameon=False, ncol=1, scatterpoints=1,
                            title="Algorithms:", bbox_to_anchor=(1.25, .85), borderaxespad=0.0)
        for idx in range(len(legend.legendHandles)):
            legend.legendHandles[idx]._sizes = [22]
        plt.suptitle("Ground Truth Disparities vs. Algorithm Disparities", fontsize=fontsize)

        fig_path = plotting.get_path_to_figure("pyramids_disp_disp", subdir=subdir)
        plotting.save_tight_figure(fig, fig_path, remove_ticks=False,
                                   hspace=0.2, wspace=0.3, padding_top=0.88)
Пример #13
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)
Пример #14
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)