Commit 37f4818d authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by GitHub
Browse files

Merge pull request #144 from jlaura/master

Fixes Suppression
parents 7a15387c 68572b9f
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -251,8 +251,10 @@ class Node(dict, MutableMapping):

        allkps = pd.DataFrame(data=clean_kps, columns=columns, index=index)

        if 'response' in allkps.columns:
            self._keypoints = allkps.sort_values(by='response', ascending=False)

        elif 'size' in allkps.columns:
            self._keypoints = allkps.sort_values(by='size', ascending=False)
        if isinstance(in_path, str):
            hdf = None

@@ -299,7 +301,7 @@ class Node(dict, MutableMapping):
        if isinstance(out_path, str):
            hdf = None

    def group_correspondences(self, cg, *args, clean_keys=['fundamental'], deepen=False, **kwargs):
    def group_correspondences(self, cg, *args, deepen=False, **kwargs):
        """

        Parameters
@@ -319,6 +321,11 @@ class Node(dict, MutableMapping):
             # TODO: Add dangling correspondences to control network anyway.  Subgraphs handle this segmentation if req.
            return

        try:
            clean_keys = kwargs['clean_keys']
        except:
            clean_keys = []

        # Grab all the incident edge matches and concatenate into a group match set.
        # All share the same source node
        edge_matches = []
@@ -460,4 +467,3 @@ class Node(dict, MutableMapping):
        mask = panel[clean_keys].all(axis=1)
        matches = self._keypoints[mask]
        return matches, mask
+13 −12
Original line number Diff line number Diff line
@@ -166,7 +166,6 @@ class SpatialSuppression(Observable):
    def nvalid(self):
        return self.mask.sum()


    @property
    def error_k(self):
        return self._error_k
@@ -186,22 +185,30 @@ class SpatialSuppression(Observable):
            self.k = len(self.df)
            result = self.df.index
            process = False
        search_space = np.linspace(self.min_radius, self.max_radius, 100)
        nsteps = max(self.domain) * 0.95
        search_space = np.linspace(self.min_radius, self.max_radius, nsteps)
        cell_sizes = search_space / math.sqrt(2)
        min_idx = 0
        max_idx = len(search_space) - 1

        prev_min = None
        prev_max = None

        while process:
            # Setup to store results
            result = []

            mid_idx = int((min_idx + max_idx) / 2)

            if min_idx == mid_idx or mid_idx == max_idx:
                warnings.warn('Unable to optimally solve.  Returning with {} points'.format(len(result)))
                process = False

            cell_size = cell_sizes[mid_idx]
            n_x_cells = int(self.domain[0] / cell_size)
            n_y_cells = int(self.domain[1] / cell_size)
            grid = np.zeros((n_x_cells, n_y_cells), dtype=np.bool)

            # Setup to store results
            result = []

            # Assign all points to bins
            x_edges = np.linspace(0, self.domain[0], n_x_cells)
            y_edges = np.linspace(0, self.domain[1], n_y_cells)
@@ -245,11 +252,10 @@ class SpatialSuppression(Observable):
                    grid[y_min: y_max,
                         x_min: x_max] = True


            #  Check break conditions
            if self.k - self.k * self.error_k <= len(result) <= self.k + self.k * self.error_k:
                process = False
            elif len(result) < self.k:
            elif len(result) < self.k - self.k * self.error_k:
                # The radius is too large
                max_idx = mid_idx
                if max_idx == 0:
@@ -258,10 +264,6 @@ class SpatialSuppression(Observable):
                    process = False
                if min_idx == max_idx:
                    process = False
            elif min_idx == mid_idx or mid_idx == max_idx:
                warnings.warn('Unable to optimally solve.  Returning with {} points'.format(len(result)))
                process = False

        self.mask = pd.Series(False, self.df.index)
        self.mask.loc[list(result)] = True
        state_package = {'mask': self.mask,
@@ -319,4 +321,3 @@ def mirroring_test(matches):
    """
    duplicate_mask = matches.duplicated(subset=['source_idx', 'destination_idx', 'distance'], keep='last')
    return duplicate_mask
+1 −1
Original line number Diff line number Diff line
@@ -29,6 +29,6 @@ def error(row, edge):
    """
    key = row.name
    try:
        return 1 / edge.fundamental_matrix.error.iloc[key]
        return 1 / edge.fundamental_matrix.error.loc[key]
    except:
        return np.NaN
+1 −6
Original line number Diff line number Diff line
@@ -95,11 +95,6 @@ class testSuppressionRanges(unittest.TestCase):
    def setUpClass(cls):
        cls.r = np.random.RandomState(12345)

    def test_one_by_one(self):
        df = pd.DataFrame(self.r.uniform(0,1,(500, 3)), columns=['x', 'y', 'strength'])
        sup = SpatialSuppression(df, (1,1), k = 1)
        self.assertRaises(ValueError, sup.suppress())

    def test_min_max(self):
        df = pd.DataFrame(self.r.uniform(0,2,(500, 3)), columns=['x', 'y', 'strength'])
        sup = SpatialSuppression(df, (1.5,1.5), k = 1)
@@ -110,7 +105,7 @@ class testSuppressionRanges(unittest.TestCase):
        df = pd.DataFrame(self.r.uniform(0,15,(500, 3)), columns=['x', 'y', 'strength'])
        sup = SpatialSuppression(df, (15,15), k = 200)
        sup.suppress()
        self.assertEqual(len(df[sup.mask]), 70)
        self.assertEqual(len(df[sup.mask]), 69)

    def test_small_distribution(self):
        df = pd.DataFrame(self.r.uniform(0,25,(500, 3)), columns=['x', 'y', 'strength'])