Commit f580a4c7 authored by kberry's avatar kberry
Browse files

Created new homography branch without outlier changes

parent ac07e880
Loading
Loading
Loading
Loading
+0 −67
Original line number Diff line number Diff line
@@ -89,70 +89,3 @@ class FlannMatcher(object):
                                i.distance))
        return pd.DataFrame(matched, columns=['matched_to', 'queryIdx',
                                              'trainIdx', 'distance'])

#don't throw anything out, just have dataframes and masks
#TODO: decide on a consistent mask format to output. Do we want to also accept existing masks and just mask more things?
#consider passing in the matches and source_node to __init__
class MatchOutlierDetector(object):
    """
    Documentation
    """
    def __init__(self, ratio=0.8):
        #0.8 is Lowe's paper value -- can be changed.
        self.distance_ratio = ratio

    # return mask with self-neighbors set to zero. (query only takes care of literal self-matches on a keypoint basis, not self-matches for the whole image)
    #TODO: turn this into a mask-style thing. just returns a mask of bad values
    def find_self_neighbors(self, source_node, matches):
        """
        Returns a df containing self-neighbors that must be removed.
        (temporary return val?)

        Parameters
        ----------
        matches : dataframe
                  The pandas dataframe output by FlannMatcher.query()
                  containing matched points with columns containing:
                  matched image name, query index, train index, and
                  descriptor distance

        source_node: a string used as the key of the matched node

        Returns
        -------
        """
        mask = []
        self_matches = matches.loc[matches['matched_to'] == source_node]
        return mask

    def distance_ratio_test(self, matches):
        """
        Compute and return a mask for the matches dataframe returned by FlannMatcher.query()
        using the ratio test and distance_ratio set during initialization.

        Parameters
        ----------
        matches : dataframe
                  The pandas dataframe output by FlannMatcher.query()
                  containing matched points with columns containing:
                  matched image name, query index, train index, and
                  descriptor distance

        Returns
        -------
        mask : list
               a list of the same size as the matches dataframe
               with value = [1] if that entry in the df should be included
               and [0] if that entry in the df should be excluded
        """
        mask = []
        for key, group in matches.groupBy('queryIdx'):
            #won't work if there's only 1 match for each queryIdx
            if len(group) < 2:
                pass
            else:
                if group['distance'].iloc[0] < self.distance_ratio * group['distance'].iloc[1]:
                    mask.append([1])
                else:
                    mask.append([0])
        return mask