Commit 4f8e379b authored by jay's avatar jay
Browse files

Updates tests

parent 203257b0
Loading
Loading
Loading
Loading
+17 −30
Original line number Diff line number Diff line
@@ -154,7 +154,7 @@ class Edge(dict, MutableMapping):
        ref_feats = ref_kps[['x', 'y', 'xm', 'ym', 'zm']].values
        tar_feats = tar_kps[['x', 'y', 'xm', 'ym', 'zm']].values

        xref, xtar, pidx, ring = cpu_ring_matcher.ring_match(ref_feats, tar_feats,
        _, _, pidx, ring = cpu_ring_matcher.ring_match(ref_feats, tar_feats,
                                                           ref_desc, tar_desc,
                                                           *args, **kwargs)

@@ -187,10 +187,10 @@ class Edge(dict, MutableMapping):
        """
        skps = self.get_keypoints(self.source, index=self.matches.source_idx)
        dkps = self.get_keypoints(self.destination, index=self.matches.destination_idx)
        matches = self.matches
        matches[['source_x', 'source_y']] = skps.values
        matches[['destination_x', 'destination_y']] = dkps.values
        self.matches = matches
        self.matches['source_x'] = skps.x.values
        self.matches['source_y'] = skps.y.values
        self.matches['destination_x'] = dkps.x.values
        self.matches['destination_y'] = dkps.y.values

    def project_matches(self, semimajor, semiminor, on='source', srid=None):
        """
@@ -319,9 +319,10 @@ class Edge(dict, MutableMapping):
        """
        _, mask = self.clean(clean_keys)
        s_keypoints, d_keypoints = self.get_match_coordinates(clean_keys=clean_keys)
        
        self.fundamental_matrix, fmask = fm.compute_fundamental_matrix(s_keypoints, d_keypoints, **kwargs)
        
        print(fmask)

        if isinstance(self.fundamental_matrix, np.ndarray):
            # Convert the truncated RANSAC mask back into a full length mask
            mask[mask] = fmask
@@ -348,17 +349,14 @@ class Edge(dict, MutableMapping):
        if self.fundamental_matrix is None:
            warnings.warn('No fundamental matrix has been compute for this edge.')

        matches, _ = self.clean(clean_keys)
        matches, mask = self.clean(clean_keys)
        s_keypoints, d_keypoints = self.get_match_coordinates(clean_keys=clean_keys)
        if method == 'equality':
            error = fm.compute_fundamental_error(self.fundamental_matrix, s_keypoints, d_keypoints)
        elif method == 'projection':
            error = fm.compute_reprojection_error(self.fundamental_matrix, s_keypoints, d_keypoints)

        error = pd.Series(error, index=matches.index)
        c = self.costs
        c['fundamental_{}'.format(method)] = error.values
        self.costs = c
        self.costs.loc[mask, 'fundamental_{}'.format(method)] = error

    def compute_homography(self, method='ransac', clean_keys=[], pid=None, maskname='homography', **kwargs):
        """
@@ -477,28 +475,17 @@ class Edge(dict, MutableMapping):
            new_y[i] = d_keypoint.y - shift_y
            strengths[i] = metrics
        
        matches['shift_x'] = shifts_x
        matches['shift_y'] = shifts_y
        matches['destination_x'] = new_x
        matches['destination_y'] = new_y
        self.matches.loc[mask, 'shift_x'] = shifts_x
        self.matches.loc[mask, 'shift_y'] = shifts_y
        self.matches.loc[mask, 'destination_x'] = new_x
        self.matches.loc[mask, 'destination_y'] = new_y

        costs = self.costs
        if method == 'phase':
            costs['phase'] = [i[0] for i in strengths]
            costs['rmse'] = [i[1] for i in strengths]
            self.costs.loc[mask, 'phase'] = [i[0] for i in strengths]
            self.costs.loc[mask, 'rmse'] = [i[1] for i in strengths]
        elif method == 'template':
            costs['correlation'] = strengths

        c = self.costs
        # Set the defaults for the columns
        for column in costs.columns:
            c[column] = np.nan
        c[mask.values] = costs
        self.costs = c

        m = self.matches
        m[mask.values] = matches
        self.matches = m 
            self.costs.loc[mask, 'correlation'] = strengths
 

    def suppress(self, suppression_func=spf.correlation, clean_keys=[], maskname='suppression', **kwargs):
        """
+1 −1
Original line number Diff line number Diff line
@@ -281,7 +281,7 @@ class Node(dict, MutableMapping):
        if index is None:
            keypoints = self.keypoints[['x', 'y']]
        else:
            keypoints = self.keypoints.loc[self.keypoints.index.intersection(index)][['x', 'y']]
            keypoints = self.keypoints.loc[index][['x', 'y']]

        if homogeneous:
            keypoints['homogeneous'] = 1
+2 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ def test_read_write_npy(tmpdir, kd):
def test_read_write_hdf(tmpdir, kd):
    kps, desc = kd
    path = tmpdir.join('out.h5')
    keypoints.to_hdf(kps, desc, path.strpath)
    keypoints.to_hdf(path.strpath, keypoints=kps, descriptors=desc)
    reloaded_kps, reloaded_desc = keypoints.from_hdf(path.strpath)

    assert reloaded_kps.equals(kps)
@@ -35,7 +35,7 @@ def test_read_write_hdf_with_live_file(tmpdir, kd):
    kps, desc = kd
    path = tmpdir.join('live.h5')
    hf = io_hdf.HDFDataset(path.strpath, mode='w')
    keypoints.to_hdf(kps, desc, hf)
    keypoints.to_hdf(hf, keypoints=kps, descriptors=desc)
    reloaded_kps, reloaded_desc = keypoints.from_hdf(hf)

    assert reloaded_kps.equals(kps)
+8 −0
Original line number Diff line number Diff line
@@ -74,7 +74,12 @@ def clip_roi(img, center_x, center_y, size_x=200, size_y=200):
    clipped_img : ndarray
                  The clipped image
    """
    
    try:
        raster_size = img.raster_size
    except:
        # x,y form
        raster_size = img.shape[::-1]
    axr, ax = modf(center_x)
    ayr, ay = modf(center_y)

@@ -89,7 +94,10 @@ def clip_roi(img, center_x, center_y, size_x=200, size_y=200):

    # Read from the upper left origin
    pixels=(int(ax-size_x), int(ay-size_y), size_x * 2, size_y * 2)
    try:
        subarray = img.read_array(pixels=pixels)
    except:
        subarray = img[pixels[1]:pixels[1] + pixels[3] + 1, pixels[0]:pixels[0] + pixels[2] + 1]
    return subarray, axr, ayr

def subpixel_phase(template, search, **kwargs):
+11 −8
Original line number Diff line number Diff line
@@ -28,27 +28,30 @@ def img():

@pytest.fixture
def img_coord():
    return (482.09783936, 652.40679932)
    return 482.09783936, 652.40679932

@pytest.fixture
def template(img, img_coord):
    template = sp.clip_roi(img, img_coord, 5)
    coord_x, coord_y = img_coord
    template, _, _ = sp.clip_roi(img, coord_x, coord_y, 5, 5)
    template = rotate(template, 90)
    template = imresize(template, 1.)
    return template

@pytest.fixture
def search(img, img_coord):
    search = sp.clip_roi(img, img_coord, 21)
    coord_x, coord_y = img_coord
    search, _, _ = sp.clip_roi(img, coord_x, coord_y, 21, 21)
    search = rotate(search, 0)
    search = imresize(search, 1.)
    return search

@pytest.fixture
def offset_template(img, img_coord):
    offset = (1, 1)

    offset_template = sp.clip_roi(img, np.add(img_coord, offset), 5)
    coord_x, coord_y = img_coord
    coord_x += 1
    coord_y += 1
    offset_template, _, _ = sp.clip_roi(img, coord_x, coord_y, 5, 5)
    offset_template = rotate(offset_template, 0)
    offset_template = imresize(offset_template, 1.)

@@ -135,7 +138,7 @@ def test_rafi(template, search, rafi_thresh, radii, alpha):
                                   thresh=rafi_thresh, radii=radii, use_percentile=True,
                                   alpha=alpha)

    assert (np.floor(search.shape[0]/2), np.floor(search.shape[1]/2)) in pixels
    assert (np.floor(search.shape[0]/4), np.floor(search.shape[1]/4)) in pixels
    assert pixels.size in range(0, search.size)

# Alternate approach to the more verbose tests above - this tests all combinations
@@ -162,7 +165,7 @@ def test_tefi(template, search):
                                   thresh=tefi_thresh, use_percentile=True, alpha=math.pi/2,
                                   upsampling=10)

    assert np.equal((.5, .5), (pixel[1], pixel[0])).all()
    assert np.equal((11.5, 11.5), (pixel[1], pixel[0])).all()

@pytest.mark.parametrize("cifi_thresh, rafi_thresh, tefi_thresh, alpha, radii",[(90,90,100,math.pi/2,list(range(1, 3)))])
def test_ciratefi(template, search, cifi_thresh, rafi_thresh, tefi_thresh, alpha, radii):
Loading