Loading autocnet/graph/network.py +15 −8 Original line number Diff line number Diff line Loading @@ -249,24 +249,31 @@ class CandidateGraph(nx.Graph): attributes['homography'] = transformation_matrix attributes['ransac'] = mask # TODO: finish me!!! def compute_subpixel_offsets(self): """ For the entire graph, compute the subpixel offsets using pattern-matching and add the result as an attribute to each edge of the graph. Returns ------- subpixel_offsets : ndarray A numpy array containing all the subpixel offsets for the entire graph. """ subpixel_offsets = [] for source, destination, attributes in self.edges_iter(data=True): #for each edge matches = attributes['matches'] #grab the matches src_image = self.node[source]['image'] dest_image = self.node[destination]['image'] tmp_lst = [] edge_offsets = [] for i, (idx, row) in enumerate(matches.iterrows()): #for each edge, calculate this for each keypoint pair s_idx = int(row['source_idx']) d_idx = int(row['destination_idx']) src_keypoint = self.node[source]['keypoints'][s_idx] dest_keypoint = self.node[destination]['keypoints'][d_idx] tmp_lst.append(sp.subpixel_offset(src_keypoint, dest_keypoint, src_image, dest_image)) print(tmp_lst) return edge_offsets.append(sp.subpixel_offset(src_keypoint, dest_keypoint, src_image, dest_image)) attributes['subpixel_offsets'] = np.array(edge_offsets) subpixel_offsets.append(np.array(edge_offsets)) return subpixel_offsets def to_cnet(self, clean_keys=[]): """ Loading autocnet/matcher/subpixel.py +39 −8 Original line number Diff line number Diff line import pandas as pd from autocnet.matcher import matcher # docs # operates on one set of (src, dest) (kp, image)s # error if passed in size is even. Don't do this.... # calculate an (x,y, strength) for each keypoint match in edge # can we assume templates are square? # look into the keypoint size and something with the descriptors to check physical area.... # TODO: look into KeyPoint.size and perhaps use to determine an appropriately-sized search/template. # TODO: do not allow even sizes """ Uses a pattern-matcher on subsets of two images determined from the passed-in keypoints and optional sizes to compute an x and y offset from the search keypoint to the template keypoint and an associated strength. 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 The entire image that the template chip to match to will be taken out of. search_img : 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. Returns ------- : tuple The returned tuple is of form: (x_offset, y_offset, strength). The offsets are from the search to the template keypoint. """ def subpixel_offset(template_kp, search_kp, template_img, search_img, template_size=9, search_size=27): # Get the x,y coordinates temp_x, temp_y = map(int, template_kp.pt) Loading @@ -20,5 +43,13 @@ def subpixel_offset(template_kp, search_kp, template_img, search_img, template_s template = template_img[temp_y-t:temp_y+t, temp_x-t:temp_x+t] search = search_img[search_y-s:search_y+s, search_x-s:search_x+s] # actually do the pattern match return matcher.pattern_match(template, search) results = (None, None, None) try: results = matcher.pattern_match(template, search) except ValueError: # the match fails if the template or search point is near an edge of the image # TODO: come up with a better solution? print('Template Keypoint ({},{}) cannot be pattern matched'.format(str(temp_x), str(temp_y))) return results autocnet/matcher/tests/test_subpixel.pydeleted 100644 → 0 +0 −17 Original line number Diff line number Diff line import os import sys import unittest sys.path.append(os.path.abspath('..')) from .. import subpixel class TestSubpixel(unittest.TestCase): def setUp(self): pass def test_subpixel(self): self.assertTrue(False) def tearDown(self): pass No newline at end of file functional_tests/test_two_image.py +4 −1 Original line number Diff line number Diff line Loading @@ -77,8 +77,11 @@ class TestTwoImageMatching(unittest.TestCase): self.assertIn(len(matches.loc[mask]), range(75,101)) cg.compute_homographies(clean_keys=['symmetry', 'ratio']) cg.compute_subpixel_offsets() #compute subpixel offsets for the entire graph offsets = cg.compute_subpixel_offsets() self.assertEqual(len(offsets), cg.number_of_edges()) # TODO: actually do something with this # Step: And create a C object cnet = cg.to_cnet(clean_keys=['symmetry', 'ratio', 'ransac']) Loading Loading
autocnet/graph/network.py +15 −8 Original line number Diff line number Diff line Loading @@ -249,24 +249,31 @@ class CandidateGraph(nx.Graph): attributes['homography'] = transformation_matrix attributes['ransac'] = mask # TODO: finish me!!! def compute_subpixel_offsets(self): """ For the entire graph, compute the subpixel offsets using pattern-matching and add the result as an attribute to each edge of the graph. Returns ------- subpixel_offsets : ndarray A numpy array containing all the subpixel offsets for the entire graph. """ subpixel_offsets = [] for source, destination, attributes in self.edges_iter(data=True): #for each edge matches = attributes['matches'] #grab the matches src_image = self.node[source]['image'] dest_image = self.node[destination]['image'] tmp_lst = [] edge_offsets = [] for i, (idx, row) in enumerate(matches.iterrows()): #for each edge, calculate this for each keypoint pair s_idx = int(row['source_idx']) d_idx = int(row['destination_idx']) src_keypoint = self.node[source]['keypoints'][s_idx] dest_keypoint = self.node[destination]['keypoints'][d_idx] tmp_lst.append(sp.subpixel_offset(src_keypoint, dest_keypoint, src_image, dest_image)) print(tmp_lst) return edge_offsets.append(sp.subpixel_offset(src_keypoint, dest_keypoint, src_image, dest_image)) attributes['subpixel_offsets'] = np.array(edge_offsets) subpixel_offsets.append(np.array(edge_offsets)) return subpixel_offsets def to_cnet(self, clean_keys=[]): """ Loading
autocnet/matcher/subpixel.py +39 −8 Original line number Diff line number Diff line import pandas as pd from autocnet.matcher import matcher # docs # operates on one set of (src, dest) (kp, image)s # error if passed in size is even. Don't do this.... # calculate an (x,y, strength) for each keypoint match in edge # can we assume templates are square? # look into the keypoint size and something with the descriptors to check physical area.... # TODO: look into KeyPoint.size and perhaps use to determine an appropriately-sized search/template. # TODO: do not allow even sizes """ Uses a pattern-matcher on subsets of two images determined from the passed-in keypoints and optional sizes to compute an x and y offset from the search keypoint to the template keypoint and an associated strength. 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 The entire image that the template chip to match to will be taken out of. search_img : 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. Returns ------- : tuple The returned tuple is of form: (x_offset, y_offset, strength). The offsets are from the search to the template keypoint. """ def subpixel_offset(template_kp, search_kp, template_img, search_img, template_size=9, search_size=27): # Get the x,y coordinates temp_x, temp_y = map(int, template_kp.pt) Loading @@ -20,5 +43,13 @@ def subpixel_offset(template_kp, search_kp, template_img, search_img, template_s template = template_img[temp_y-t:temp_y+t, temp_x-t:temp_x+t] search = search_img[search_y-s:search_y+s, search_x-s:search_x+s] # actually do the pattern match return matcher.pattern_match(template, search) results = (None, None, None) try: results = matcher.pattern_match(template, search) except ValueError: # the match fails if the template or search point is near an edge of the image # TODO: come up with a better solution? print('Template Keypoint ({},{}) cannot be pattern matched'.format(str(temp_x), str(temp_y))) return results
autocnet/matcher/tests/test_subpixel.pydeleted 100644 → 0 +0 −17 Original line number Diff line number Diff line import os import sys import unittest sys.path.append(os.path.abspath('..')) from .. import subpixel class TestSubpixel(unittest.TestCase): def setUp(self): pass def test_subpixel(self): self.assertTrue(False) def tearDown(self): pass No newline at end of file
functional_tests/test_two_image.py +4 −1 Original line number Diff line number Diff line Loading @@ -77,8 +77,11 @@ class TestTwoImageMatching(unittest.TestCase): self.assertIn(len(matches.loc[mask]), range(75,101)) cg.compute_homographies(clean_keys=['symmetry', 'ratio']) cg.compute_subpixel_offsets() #compute subpixel offsets for the entire graph offsets = cg.compute_subpixel_offsets() self.assertEqual(len(offsets), cg.number_of_edges()) # TODO: actually do something with this # Step: And create a C object cnet = cg.to_cnet(clean_keys=['symmetry', 'ratio', 'ransac']) Loading