Commit 0cd05e86 authored by Jay's avatar Jay Committed by jay
Browse files

Update for CR

parent 5a5b2dcf
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -203,9 +203,17 @@ class CandidateGraph(nx.Graph):
                     The identifier for the source node
        destination_key : str
                          The identifier for the destination node

        outlier_algorithm : object
                            An openCV outlier detections algorithm, e.g. cv2.RANSAC
        Returns
        -------
         : tuple
        transformation_matrix : ndarray
                                The 3x3 transformation matrix

        mask : ndarray
               Boolean array of the outliers

           A tuple of the form (transformation matrix, bad entry mask)
           The returned tuple is empty if there is no edge between the source and destination nodes or
           if it exists, but has not been populated with a matches dataframe.
@@ -230,13 +238,19 @@ class CandidateGraph(nx.Graph):

                    source_keypoints.append(src_keypoint)
                    destination_keypoints.append(dest_keypoint)
                return cv2.findHomography(np.array(source_keypoints), np.array(destination_keypoints),
                                          outlier_algorithm, 5.0)
                transformation_matrix, mask = cv2.findHomography(np.array(source_keypoints),
                                                                 np.array(destination_keypoints),
                                                                 outlier_algorithm,
                                                                 5.0)
                mask = mask.astype(bool)
                return transformation_matrix, mask
            else:
                return ('', '')
        else:
            return ('','')



    def to_cnet(self, clean_keys=[]):
        """
        Generate a control network (C) object from a graph
+9 −5
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ DEFAULT_FLANN_PARAMETERS = dict(algorithm=FLANN_INDEX_KDTREE,
def pattern_match(template, image, upsampling=10,
                  func=match_template):
    """
    Call an arbitrary pattern matcher

    Parameters
    ----------
    template : ndarray
@@ -38,7 +40,7 @@ def pattern_match(template, image, upsampling=10,
        The y offset

    strength : float
               The strength of teh correlation in the range [-1, 1].
               The strength of the correlation in the range [-1, 1].



@@ -63,13 +65,15 @@ def pattern_match(template, image, upsampling=10,
    y /= upsampling

    # Offset from the UL origin to the image center
    x += (template.shape[0] / 2)
    x += (template.shape[1] / 2)
    y += (template.shape[0] / 2)

    # Compute the offset to adjust the image match point location
    ideal_center = image.shape[0] / 2
    x = ideal_center - x
    y = ideal_center - y
    ideal_y = image.shape[0] / 2
    ideal_x = image.shape[1] / 2

    x = ideal_x - x
    y = ideal_y - y

    # Find the maximum correlation
    strength = np.max(match)
+2 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ def distance_ratio(matches, ratio=0.8):
        group_size = len(group)
        # If we can not perform the ratio check because all matches are symmetrical
        if len(group['destination_idx'].unique()) == 1:
            mask[counter:counter + group_size] = False
            mask[counter:counter + group_size] = True
            counter += group_size
        else:
            # Otherwise, we can perform the ratio test
@@ -111,3 +111,4 @@ def mirroring_test(matches):
    duplicates = matches.duplicated(keep='first').values
    duplicates.astype(bool, copy=False)
    return duplicates
+1 −2
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ class TestOutlierDetector(unittest.TestCase):
        self.assertTrue(len(outlier_detector.distance_ratio(self.matches)), 13)

    def test_self_neighbors(self):
        print(self.matches[outlier_detector.self_neighbors(self.matches)])
        # returned mask should be same length as input df
        self.assertEquals(len(outlier_detector.self_neighbors(self.matches)), len(self.matches))

+1 −2
Original line number Diff line number Diff line
@@ -70,12 +70,11 @@ class TestTwoImageMatching(unittest.TestCase):

            # Perform the ratio test
            ratio_mask = od.distance_ratio(matches, ratio=0.95)
            self.assertIn(ratio_mask.sum(), range(30,40))
            self.assertIn(ratio_mask.sum(), range(30,45))
            attributes['ratio'] = ratio_mask

            mask = np.array(ratio_mask * symmetry_mask)
            self.assertIn(len(matches.loc[mask]), range(4,10))

        # Step: And create a C object
        cnet = cg.to_cnet(clean_keys=['symmetry', 'ratio'])