Loading autocnet/matcher/outlier_detector.py +44 −0 Original line number Diff line number Diff line import cv2 import numpy as np import pandas as pd def self_neighbors(matches): Loading Loading @@ -149,4 +150,47 @@ def compute_homography(kp1, kp2, outlier_algorithm=cv2.RANSAC, reproj_threshold= mask = mask.astype(bool) return transformation_matrix, mask # TODO: CITATION and better design? def adaptive_non_max_suppression(keypoints, n=100, robust=0.9): """ Select the top n keypoints, using Adaptive Non-Maximal Suppression (see: Brown (2005) [Brown2005]_) to rank the keypoints in order of largest minimum suppression radius. A mask with only the positions of the top n keypoints set to 1 (and all else set to 0) is returned. Parameters ---------- keypoints : list List of KeyPoint objects from a node of the graph or equivalently, for 1 image. n : int The number of top-ranked keypoints to return. Returns ------- keypoint_mask : list A list containing a 1 in the positions of the top n selected keypoints and 0 in the positions of all the other keypoints. """ minimum_suppression_radius = {} for i, kp1 in enumerate(keypoints): x1, y1 = kp1.pt temp = [] for kp2 in keypoints: #includes kp1 for now if kp1.response < robust*kp2.response: x2, y2 = kp2.pt temp.append(np.sqrt((x2-x1)**2 + (y2-y1)**2)) if(len(temp) > 0): minimum_suppression_radius[i] = np.min(np.array(temp)) else: minimum_suppression_radius[i] = np.nan df = pd.DataFrame(list(minimum_suppression_radius.items()), columns=['keypoint', 'radius']) top_n = df.sort_values(by='radius', ascending=False).head(n) temp_df = df.mask(df.radius < top_n.radius.min(), other=np.nan) temp_df = temp_df.where(np.isnan(temp_df.keypoint), other=1) temp_df = temp_df.mask(np.isnan(temp_df.keypoint), other=0) return list(temp_df.radius) autocnet/matcher/subpixel.py +4 −14 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ from autocnet.matcher import matcher # TODO: look into KeyPoint.size and perhaps use to determine an appropriately-sized search/template. def clip_roi(img, center, img_size): """ Given an input image, clip a square region of interest Loading Loading @@ -47,21 +46,12 @@ def subpixel_offset(template, search, upsampling=10): Parameters ---------- template_kp : KeyPoint The KeyPoint to match the search_kp to. search_kp : KeyPoint The KeyPoint to match to the template_kp template_img : numpy array template : numpy array The entire image that the template chip to match to will be taken out of. search_img : numpy array search : numpy array The entire image that the search chip to match to the template chip will be taken out of. template_size : int The length of one side of the square subset of the template image that will actually be used for the subpixel registration. Default is 9. Must be odd. search_size : int The length of one side of the square subset of the search image that will be used for subpixel registration. Default is 13. Must be odd. upsampling: int The amount to upsample the image. Returns ------- : tuple Loading docs/conf.py +1 −1 Original line number Diff line number Diff line Loading @@ -295,7 +295,7 @@ class Mock(MagicMock): # All imported libraries should be added to this mock modules list. MOCK_MODULES = ['proj4', 'numpy', 'pandas', 'scipy', 'osgeo', 'cv2', 'scikit-image', 'skimage'] 'scikit-image', 'skimage', 'skimage.feature', 'scipy', 'scipy.misc'] sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) # NumpyDoc Options Loading docs/library/matcher/index.rst +3 −0 Original line number Diff line number Diff line Loading @@ -5,3 +5,6 @@ feature_extractor matcher outlier_detector subpixel docs/library/matcher/outlier_detector.rst 0 → 100644 +10 −0 Original line number Diff line number Diff line :mod:`matcher.outlier_detector` --- Finding outliers in both the keypoints and the matches ==================================================================== The :mod:`matcher.outlier_detector` module .. versionadded:: 0.1.0 .. automodule:: autocnet.matcher.outlier_detector :synopsis: :members: Loading
autocnet/matcher/outlier_detector.py +44 −0 Original line number Diff line number Diff line import cv2 import numpy as np import pandas as pd def self_neighbors(matches): Loading Loading @@ -149,4 +150,47 @@ def compute_homography(kp1, kp2, outlier_algorithm=cv2.RANSAC, reproj_threshold= mask = mask.astype(bool) return transformation_matrix, mask # TODO: CITATION and better design? def adaptive_non_max_suppression(keypoints, n=100, robust=0.9): """ Select the top n keypoints, using Adaptive Non-Maximal Suppression (see: Brown (2005) [Brown2005]_) to rank the keypoints in order of largest minimum suppression radius. A mask with only the positions of the top n keypoints set to 1 (and all else set to 0) is returned. Parameters ---------- keypoints : list List of KeyPoint objects from a node of the graph or equivalently, for 1 image. n : int The number of top-ranked keypoints to return. Returns ------- keypoint_mask : list A list containing a 1 in the positions of the top n selected keypoints and 0 in the positions of all the other keypoints. """ minimum_suppression_radius = {} for i, kp1 in enumerate(keypoints): x1, y1 = kp1.pt temp = [] for kp2 in keypoints: #includes kp1 for now if kp1.response < robust*kp2.response: x2, y2 = kp2.pt temp.append(np.sqrt((x2-x1)**2 + (y2-y1)**2)) if(len(temp) > 0): minimum_suppression_radius[i] = np.min(np.array(temp)) else: minimum_suppression_radius[i] = np.nan df = pd.DataFrame(list(minimum_suppression_radius.items()), columns=['keypoint', 'radius']) top_n = df.sort_values(by='radius', ascending=False).head(n) temp_df = df.mask(df.radius < top_n.radius.min(), other=np.nan) temp_df = temp_df.where(np.isnan(temp_df.keypoint), other=1) temp_df = temp_df.mask(np.isnan(temp_df.keypoint), other=0) return list(temp_df.radius)
autocnet/matcher/subpixel.py +4 −14 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ from autocnet.matcher import matcher # TODO: look into KeyPoint.size and perhaps use to determine an appropriately-sized search/template. def clip_roi(img, center, img_size): """ Given an input image, clip a square region of interest Loading Loading @@ -47,21 +46,12 @@ def subpixel_offset(template, search, upsampling=10): Parameters ---------- template_kp : KeyPoint The KeyPoint to match the search_kp to. search_kp : KeyPoint The KeyPoint to match to the template_kp template_img : numpy array template : numpy array The entire image that the template chip to match to will be taken out of. search_img : numpy array search : numpy array The entire image that the search chip to match to the template chip will be taken out of. template_size : int The length of one side of the square subset of the template image that will actually be used for the subpixel registration. Default is 9. Must be odd. search_size : int The length of one side of the square subset of the search image that will be used for subpixel registration. Default is 13. Must be odd. upsampling: int The amount to upsample the image. Returns ------- : tuple Loading
docs/conf.py +1 −1 Original line number Diff line number Diff line Loading @@ -295,7 +295,7 @@ class Mock(MagicMock): # All imported libraries should be added to this mock modules list. MOCK_MODULES = ['proj4', 'numpy', 'pandas', 'scipy', 'osgeo', 'cv2', 'scikit-image', 'skimage'] 'scikit-image', 'skimage', 'skimage.feature', 'scipy', 'scipy.misc'] sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) # NumpyDoc Options Loading
docs/library/matcher/index.rst +3 −0 Original line number Diff line number Diff line Loading @@ -5,3 +5,6 @@ feature_extractor matcher outlier_detector subpixel
docs/library/matcher/outlier_detector.rst 0 → 100644 +10 −0 Original line number Diff line number Diff line :mod:`matcher.outlier_detector` --- Finding outliers in both the keypoints and the matches ==================================================================== The :mod:`matcher.outlier_detector` module .. versionadded:: 0.1.0 .. automodule:: autocnet.matcher.outlier_detector :synopsis: :members: