Commit 305aba0b authored by kberry's avatar kberry
Browse files

Merge remote-tracking branch 'upstream/master' into jwbacker_visualization

parents 27e669bc 4a851f2c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
{"autocnet/examples/Apollo15/AS15-M-0297_SML.png": ["autocnet/examples/Apollo15/AS15-M-0298_SML.png",
                                                    "autocnet/examples/Apollo15/AS15-M-0299_SML.png"],
"autocnet/examples/Apollo15/AS15-M-0298_SML.png": ["autocnet/examples/Apollo15/AS15-M-0297_SML.png",
                                                   "autocnet/examples/Apollo15/AS15-M-0299_SML.png"],
"autocnet/examples/Apollo15/AS15-M-0299_SML.png": ["autocnet/examples/Apollo15/AS15-M-0297_SML.png",
                                                   "autocnet/examples/Apollo15/AS15-M-0298_SML.png"]}
+1 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ def to_isis(path, C, mode='w', version=VERSION,

            store.write(header)


class IsisStore(object):
    """
    Class to manage IO of an ISIS control network (version 2).
+66 −5
Original line number Diff line number Diff line
from functools import reduce
import operator as op
import os

import networkx as nx
@@ -14,6 +12,8 @@ from autocnet.fileio import io_json
from autocnet.fileio.io_gdal import GeoDataset
from autocnet.matcher import feature_extractor as fe # extract features from image
from autocnet.matcher import outlier_detector as od
from autocnet.matcher import subpixel as sp


class CandidateGraph(nx.Graph):
    """
@@ -269,18 +269,76 @@ class CandidateGraph(nx.Graph):
            attributes['homography'] = transformation_matrix
            attributes['ransac'] = mask

    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']
            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]
                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=[]):
        """
        Generate a control network (C) object from a graph

        Parameters
        ----------
        clean_keys : list
             of strings identifying the masking arrays to use, e.g. ratio, symmetry

        Returns
        -------
        merged_cnet : C
                      A control network object
        """

        clean_keys : list
                     of strings identifying the masking arrays to use, e.g. ratio, symmetry
        def _validate_cnet(cnet):
            """
            Once the control network is aggregated from graph edges,
            ensure that a given correspondence in a given image does
            not match multiple correspondences in a different image.

            Parameters
            ----------
            cnet : C
                   control network object

            Returns
            -------
             : C
               the cleaned control network
            """

            mask = np.zeros(len(cnet), dtype=bool)
            counter = 0
            for i, group in cnet.groupby('pid'):
                group_size = len(group)
                if len(group) != len(group['nid'].unique()):
                    mask[counter: counter + group_size] = False
                else:
                    mask[counter: counter + group_size] = True
                counter += group_size

            return cnet[mask]

        merged_cnet = None

        for source, destination, attributes in self.edges_iter(data=True):
@@ -338,6 +396,9 @@ class CandidateGraph(nx.Graph):
                merged_cnet = pd.concat([merged_cnet, cnet])
                merged_cnet.drop_duplicates(['idx', 'pid'], keep='first', inplace=True)

        # Final validation to remove any correspondence with multiple correspondences in the same image
        merged_cnet = _validate_cnet(merged_cnet)

        return merged_cnet

    def to_json_file(self, outputfile):
+0 −1
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ class TestCandidateGraph(unittest.TestCase):
        self.assertIsInstance(node['descriptors'][0], np.ndarray)
        self.assertEquals(self.graph.get_keypoints(node_number), node['keypoints'])


    def tearDown(self):
        try:
            os.remove('test_graph_to_json.json')
+0 −3
Original line number Diff line number Diff line
@@ -41,9 +41,6 @@ def pattern_match(template, image, upsampling=10,

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



    """
    if upsampling < 1:
        raise ValueError
Loading