Commit 00758e5d authored by Kelvin's avatar Kelvin
Browse files

updated test for ciratefi

parent c5b934d3
Loading
Loading
Loading
Loading
+5 −6
Changes for autocnet/matcher/tests/test_ciratefi.py: 5 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -142,24 +142,23 @@ class TestCiratefi(unittest.TestCase):
                print(warn)

            self.assertEqual(len(w), 0)
            self.assertIn((np.floor(self.search.shape[0]/2), np.floor(self.search.shape[1]/2)), pixel)
            self.assertTrue(pixel[0][0] == self.search_center[0] and pixel[0][1] == self.search_center[1])
            print(pixel)
            self.assertTrue(np.equal((.5, .5), (pixel[1], pixel[0])).all())

    def test_ciratefi(self):
        results = ciratefi.ciratefi(self.template, self.search, upsampling=10, cifi_thresh=self.cifi_thresh,
                                    rafi_thresh=self.rafi_thresh, tefi_thresh=self.tefi_thresh,
                                    use_percentile=self.use_percentile, alpha=self.alpha, radii=self.radii)

        self.assertEqual(len(results), 1)
        self.assertTrue(np.equal(results[0], self.search_center).all())
        self.assertEqual(len(results), 3)
        self.assertTrue((np.array(results[1], results[0]) < 1).all())

        results = ciratefi.ciratefi(self.offset_template, self.search, upsampling=self.upsampling,
                                    cifi_thresh=self.cifi_thresh, rafi_thresh=self.rafi_thresh,
                                    tefi_thresh=self.tefi_thresh,
                                    use_percentile=self.use_percentile, alpha=self.alpha, radii=self.radii)

        print(results)
        self.assertTrue(np.equal(results[0], np.add(self.search_center, list(self.offset))).all())


    def tearDown(self):
        pass
+124 −0
Changes for notebooks/.ipynb_checkpoints/Ciratefi-checkpoint.ipynb: 124 added lines, 0 removed lines.
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` python
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

from autocnet.examples import get_path
from autocnet.graph.network import CandidateGraph
from autocnet.graph.edge import Edge
from autocnet.matcher.feature import FlannMatcher
from autocnet.matcher import ciratefi


from autocnet.matcher import subpixel as sp
from scipy.misc import imresize
import math
import warnings
import cv2

from bisect import bisect_left

from scipy.ndimage.interpolation import rotate

from IPython.display import display
warnings.filterwarnings('ignore')

%matplotlib inline
%pylab inline
```

%% Cell type:markdown id: tags:

# Create Basic Structures

%% Cell type:code id: tags:

``` python
#Point to the adjacency Graph
adjacency = get_path('three_image_adjacency.json')
basepath = get_path('Apollo15')
cg = CandidateGraph.from_adjacency(adjacency, basepath=basepath)

#Apply SIFT to extract features
cg.extract_features(method='sift', extractor_parameters={'nfeatures':300})

#Match
cg.match_features()

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

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

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

cg.edge[0][2].plot(clean_keys=['symmetry', 'ratio'])
```

%% Cell type:markdown id: tags:

# Do Stuff

%% Cell type:code id: tags:

``` python
from scipy.ndimage.interpolation import zoom
from scipy.stats.stats import pearsonr

figsize(10,10)
e = cg.edge[0][2]
matches = e.matches
clean_keys = ['ratio', 'symmetry']

full_offsets = np.zeros((len(matches), 3))

if clean_keys:
    matches, mask = e.clean(clean_keys)

# Preallocate the numpy array to avoid appending and type conversion
edge_offsets = np.empty((len(matches),3))

# for each edge, calculate this for each keypoint pair
for i, (idx, row) in enumerate(matches.iterrows()):
    s_idx = int(row['source_idx'])
    d_idx = int(row['destination_idx'])
    s_kps = e.source.get_keypoints().iloc[s_idx]
    d_kps = e.destination.get_keypoints().iloc[d_idx]

    s_keypoint = e.source.get_keypoints().iloc[s_idx][['x', 'y']].values
    d_keypoint = e.destination.get_keypoints().iloc[d_idx][['x', 'y']].values

    # Get the template and search windows
    s_template = sp.clip_roi(e.source.geodata, s_keypoint, 9)
    s_template = rotate(s_template, 0)
    s_template = imresize(s_template, 1.)

    d_search = sp.clip_roi(e.destination.geodata, d_keypoint, 21)
    d_search = rotate(d_search, 0)
    d_search = imresize(d_search, 1.)

    print(sp.subpixel_offset(s_template, d_search, method='ciratefi', upsampling=16, alpha=math.pi/4,
                     cifi_thresh=70, rafi_thresh=70, tefi_thresh=100,
                     use_percentile=True, radii=list(range(1,5))))

    break
```

%% Cell type:code id: tags:

``` python

```

%% Cell type:code id: tags:

``` python
```
+6 −43

File changed.

Preview size limit exceeded, changes collapsed.