Exemple #1
0
    def test_three_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path('three_image_adjacency.json')
        basepath = get_path('Apollo15')
        cg = CandidateGraph.from_adjacency(adjacency, basepath)
        self.assertEqual(3, cg.number_of_nodes())
        self.assertEqual(3, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(extractor_parameters={'nfeatures':500})
        for i, node, in cg.nodes_iter(data=True):
            self.assertIn(node.nkeypoints, range(490, 511))

        cg.match_features(k=5)
        cg.symmetry_checks()
        cg.ratio_checks()

        cg.apply_func_to_edges("compute_homography", clean_keys=['symmetry', 'ratio'])
        cg.compute_fundamental_matrices(clean_keys=['symmetry', 'ratio'])

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

        # Step: Create a fromlist to go with the cnet and write it to a file
        filelist = cg.to_filelist()
        write_filelist(filelist, 'TestThreeImageMatching_fromlist.lis')

        # Step: Create a correspondence network
        cg.generate_cnet(clean_keys=['ransac'], deepen=True)

        to_isis('TestThreeImageMatching.net', cg.cn, mode='wb',
                networkid='TestThreeImageMatching', targetname='Moon')
Exemple #2
0
    def setUpClass(cls):
        cls.npts = 5
        serial_times = {
            295: '1971-07-31T01:24:11.754',
            296: '1971-07-31T01:24:36.970'
        }
        cls.serials = {
            i: 'APOLLO15/METRIC/{}'.format(j)
            for i, j in enumerate(serial_times.values())
        }
        columns = [
            'id', 'pointType', 'serialnumber', 'measureType', 'sample', 'line',
            'image_index'
        ]

        data = []
        for i in range(cls.npts):
            data.append((i, 2, cls.serials[0], 2, 0, 0, 0))
            data.append((i, 2, cls.serials[1], 2, 0, 0, 1))

        df = pd.DataFrame(data, columns=columns)

        cls.creation_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        cls.modified_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        io_controlnetwork.to_isis(df, 'test.net', mode='wb', targetname='Moon')

        cls.header_message_size = 78
        cls.point_start_byte = 65614  # 66949
def test_create_point(cnet_dataframe, tmpdir):
    # Write the cnet
    io_controlnetwork.to_isis(cnet_dataframe,
                              tmpdir.join('test.net'),
                              mode='wb',
                              targetname='Moon')
    with open(tmpdir.join('test.net'), 'rb') as f:
        f.seek(cnet_dataframe.point_start_byte)
        for i, length in enumerate(cnet_dataframe.measure_size):
            point_protocol = cnf.ControlPointFileEntryV0002()
            raw_point = f.read(length)
            point_protocol.ParseFromString(raw_point)
            assert str(i) == point_protocol.id
            assert 2 == point_protocol.type

            assert i % 2 == point_protocol.referenceIndex

            if i == cnet_dataframe.npts - 1:
                assert point_protocol.aprioriCovar == [
                    1.0, 1.0, 1.0, 1.0, 1.0, 1.0
                ]
            for j, m in enumerate(point_protocol.measures):
                assert m.serialnumber in cnet_dataframe.serials.values()
                assert 2 == m.type
                assert len(m.log) == j  # Only the second measure has a message
Exemple #4
0
    def test_two_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path('two_image_adjacency.json')
        basepath = get_path('Apollo15')
        cg = CandidateGraph.from_adjacency(adjacency, basepath=basepath)
        self.assertEqual(2, cg.number_of_nodes())
        self.assertEqual(1, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(method='sift', extractor_parameters={"nfeatures":500})
        for i, node in cg.nodes_iter(data=True):
            self.assertIn(node.nkeypoints, range(490, 511))

        # Step: Compute the coverage ratios
        truth_ratios = [0.95351579,
                        0.93595664]
        for i, node in cg.nodes_iter(data=True):
            ratio = node.coverage_ratio()
            self.assertIn(round(ratio, 8), truth_ratios)

        cg.match_features(k=2)

        # Perform the symmetry check
        cg.symmetry_checks()
        # Perform the ratio check
        cg.ratio_checks(clean_keys=['symmetry'], single=True)
        # Create fundamental matrix
        cg.compute_fundamental_matrices(clean_keys = ['symmetry', 'ratio'])

        for source, destination, edge in cg.edges_iter(data=True):

            # Perform the symmetry check
            self.assertIn(edge.masks['symmetry'].sum(), range(400, 600))
            # Perform the ratio test
            self.assertIn(edge.masks['ratio'].sum(), range(225, 275))

            # Range needs to be set
            self.assertIn(edge.masks['fundamental'].sum(), range(200, 250))

        # Step: Compute the homographies and apply RANSAC
        cg.compute_homographies(clean_keys=['symmetry', 'ratio'])

        # Apply AMNS
        cg.suppress(k=30, suppression_func=error)

        # Step: Compute subpixel offsets for candidate points
        cg.subpixel_register(clean_keys=['suppression'])


        # Step: And create a C object
        cg.generate_cnet(clean_keys=['subpixel'])

        # Step: Create a fromlist to go with the cnet and write it to a file
        filelist = cg.to_filelist()
        write_filelist(filelist, path="fromlis.lis")

        # Step: Output a control network
        to_isis('TestTwoImageMatching.net', cg.cn, mode='wb',
                networkid='TestTwoImageMatching', targetname='Moon')
Exemple #5
0
    def test_create_buffer_header(self):
        npts = 5
        serial_times = {
            295: '1971-07-31T01:24:11.754',
            296: '1971-07-31T01:24:36.970'
        }
        serials = {
            i: 'APOLLO15/METRIC/{}'.format(j)
            for i, j in enumerate(serial_times.values())
        }
        columns = [
            'id', 'pointType', 'serialnumber', 'measureType', 'sample', 'line',
            'image_index'
        ]

        data = []
        for i in range(self.npts):
            data.append((i, 2, serials[0], 2, 0, 0, 0))
            data.append((i, 2, serials[1], 2, 0, 0, 1))

        df = pd.DataFrame(data, columns=columns)

        self.creation_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        self.modified_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        io_controlnetwork.to_isis(df, 'test.net', mode='wb', targetname='Moon')

        self.header_message_size = 78
        self.point_start_byte = 65614  # 66949

        with open('test.net', 'rb') as f:
            f.seek(io_controlnetwork.HEADERSTARTBYTE)
            raw_header_message = f.read(self.header_message_size)
            header_protocol = cnf.ControlNetFileHeaderV0002()
            header_protocol.ParseFromString(raw_header_message)
            #Non-repeating
            #self.assertEqual('None', header_protocol.networkId)
            self.assertEqual('Moon', header_protocol.targetName)
            self.assertEqual(io_controlnetwork.DEFAULTUSERNAME,
                             header_protocol.userName)
            self.assertEqual(self.creation_date, header_protocol.created)
            self.assertEqual('None', header_protocol.description)
            self.assertEqual(self.modified_date, header_protocol.lastModified)
            #Repeating
            self.assertEqual([135] * self.npts,
                             header_protocol.pointMessageSizes)
def cnet_dataframe(tmpdir):
    npts = 5
    serial_times = {
        295: '1971-07-31T01:24:11.754',
        296: '1971-07-31T01:24:36.970'
    }
    serials = {
        i: 'APOLLO15/METRIC/{}'.format(j)
        for i, j in enumerate(serial_times.values())
    }
    columns = [
        'id', 'pointType', 'serialnumber', 'measureType', 'sample', 'line',
        'image_index', 'pointLog', 'measureLog', 'aprioriCovar',
        'referenceIndex'
    ]

    data = []
    for i in range(npts):
        aprioriCovar = None
        if i == npts - 1:
            aprioriCovar = np.ones((2, 3))
        reference_idx = i % 2
        data.append((i, 2, serials[0], 2, 0, 0, 0, [], [], aprioriCovar,
                     reference_idx))
        data.append(
            (i, 2, serials[1], 2, 0, 0, 1, [],
             [io_controlnetwork.MeasureLog(2,
                                           0.5)], aprioriCovar, reference_idx))

    df = pd.DataFrame(data, columns=columns)

    df.creation_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    df.modified_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    io_controlnetwork.to_isis(df,
                              tmpdir.join('test.net'),
                              mode='wb',
                              targetname='Moon')

    df.header_message_size = 78
    df.point_start_byte = 65614  # 66949
    df.npts = npts
    df.measure_size = [149, 149, 149, 149,
                       200]  # Size of each measure in bytes
    df.serials = serials
    return df
def test_create_point_wo_reference_index(cnet_dataframe, tmpdir):
    # cnet_dataframe has 5 points. Set the reference on one of those to be
    # the second measure.
    reference_idx = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    new_cnet_dataframe = cnet_dataframe.drop(columns='referenceIndex')
    cnet_file = tmpdir.join('test_w_reference.net')

    # Check that the warn is raised properly
    with pytest.warns(UserWarning,
                      match='Unable to identify referenceIndex (.*)'):
        io_controlnetwork.to_isis(new_cnet_dataframe,
                                  cnet_file,
                                  mode='wb',
                                  targetname='Moon')

    # Check that nothing in == zeros out
    test_cnet = io_controlnetwork.from_isis(cnet_file)
    assert (test_cnet.referenceIndex == reference_idx).all()
def test_create_pvl_header(cnet_dataframe, tmpdir):
    # Write the cnet
    io_controlnetwork.to_isis(cnet_dataframe,
                              tmpdir.join('test.net'),
                              mode='wb',
                              targetname='Moon')
    with open(tmpdir.join('test.net'), 'rb') as stream:
        pvl_header = pvl.load(stream, grammar=pvl.grammar.ISISGrammar())
    npoints = find_in_dict(pvl_header, 'NumberOfPoints')
    assert 5 == npoints

    mpoints = find_in_dict(pvl_header, 'NumberOfMeasures')
    assert 10 == mpoints

    points_bytes = find_in_dict(pvl_header, 'PointsBytes')
    assert 796 == points_bytes

    points_start_byte = find_in_dict(pvl_header, 'PointsStartByte')
    assert cnet_dataframe.point_start_byte == points_start_byte
def test_create_buffer_header(cnet_dataframe, tmpdir):
    # Write the cnet
    io_controlnetwork.to_isis(cnet_dataframe,
                              tmpdir.join('test.net'),
                              mode='wb',
                              targetname='Moon')
    with open(tmpdir.join('test.net'), 'rb') as f:

        f.seek(io_controlnetwork.HEADERSTARTBYTE)
        raw_header_message = f.read(cnet_dataframe.header_message_size)
        header_protocol = cnf.ControlNetFileHeaderV0002()
        header_protocol.ParseFromString(raw_header_message)
        #Non-repeating
        #self.assertEqual('None', header_protocol.networkId)
        assert 'Moon' == header_protocol.targetName
        assert io_controlnetwork.DEFAULTUSERNAME == header_protocol.userName
        assert cnet_dataframe.creation_date == header_protocol.created
        assert 'None' == header_protocol.description
        assert cnet_dataframe.modified_date == header_protocol.lastModified
        #Repeating
        assert cnet_dataframe.measure_size == header_protocol.pointMessageSizes
Exemple #10
0
def test_to_isis_wo_targetname(cnet_dataframe, tmpdir):
    with pytest.warns(UserWarning, match="Users should provide a targetname"):
        io_controlnetwork.to_isis(cnet_dataframe,
                                  tmpdir.join('test.net'),
                                  mode='wb',
                                  targetname='None')  # 'None' is the default.