def get_score(self, algo_result, gt, scene, with_visualization=False):
        m_fattening = self.get_fattening(algo_result, gt, scene.get_fg_extrapolation())
        mask = self.get_evaluation_mask(scene) * misc.get_mask_valid(m_fattening)
        score = misc.percentage(np.sum(mask), np.sum(m_fattening * mask))

        if not with_visualization:
            return score

        vis = np.ma.masked_array(plotting.adjust_binary_vis(m_fattening), mask=~mask)
        return score, vis
    def get_score(self, algo_result, gt, scene, with_visualization=False):
        m_bad_pix = self.get_bad_pix(algo_result - gt)
        mask = self.get_evaluation_mask(scene) * misc.get_mask_valid(m_bad_pix)
        n_bad = np.sum(m_bad_pix[mask])
        score = misc.percentage(np.sum(mask), n_bad)

        if not with_visualization:
            return score

        m_bad_pix = plotting.adjust_binary_vis(m_bad_pix)
        vis = np.ma.masked_array(m_bad_pix, mask=~mask)
        return score, vis
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
    def get_score(self, algo_result, gt, scene, with_visualization=False):
        grid = scene.get_boxes()
        dots_by_size = scene.get_dots_by_size()
        bad_pix = BadPix(thresh=self.thresh)

        vis = np.zeros(np.shape(algo_result), dtype=np.bool)
        diffs = np.abs(gt - algo_result)

        box_ids = sorted(list(np.unique(grid)))
        box_ids.remove(0)
        n_boxes = np.size(box_ids)

        dot_labels = list(np.unique(dots_by_size))
        # use only the nine biggest dots per box
        dot_labels = [dl for dl in dot_labels if 0 < dl < 9]
        n_dots = len(dot_labels)
        total_dots = n_dots * n_boxes
        detected_dots = 0

        for box_id in box_ids:
            m_box = (grid == box_id)

            for idx_d in range(n_dots):
                dot_mask = (dots_by_size == idx_d+1) * m_box
                bad_pix_on_dot = bad_pix.get_score_from_diffs(diffs[dot_mask])
                if bad_pix_on_dot < self.missed_dot_bad_pix:
                    detected_dots += 1
                else:
                    vis[dot_mask] = 1

        missed_dots = total_dots - detected_dots
        score = misc.percentage(total_dots, missed_dots)

        if not with_visualization:
            return score

        vis = plotting.adjust_binary_vis(vis)
        return score, vis
    def get_score_from_diffs(self, diffs):
        if np.size(diffs) == 0:
            return np.nan

        m_bad_pix = self.get_bad_pix(diffs)
        return misc.percentage(np.size(diffs), np.sum(m_bad_pix))