Beispiel #1
0
def test_sift_non_float_descriptors():
    i = half_img.copy()
    frames, descriptors = sift(i, compute_descriptor=True)

    assert_allclose(frames[0], [2.16217, 128.056, 2.13029, 5.9325], rtol=1e-3)
    assert_allclose(descriptors[0, 84:88], [4,  14,  32, 137])
    assert frames.shape[0] == 358
Beispiel #2
0
def test_sift_non_float_descriptors():
    i = half_img.copy()
    frames, descriptors = sift(i, compute_descriptor=True)

    assert_allclose(frames[0], [2.16217, 128.056, 2.13029, -4.3617], rtol=1e-3)
    assert_allclose(descriptors[0, 47:52], [53, 131, 137, 32, 14])
    assert frames.shape[0] == 358
Beispiel #3
0
def test_sift_non_float_descriptors():
    i = half_img.copy()
    frames, descriptors = sift(i, compute_descriptor=True)

    assert_allclose(frames[0], [2.16217, 128.056, 2.13029, -4.3617], rtol=1e-3)
    assert_allclose(descriptors[0, 47:52], [53, 131, 137, 32, 14])
    assert frames.shape[0] == 358
Beispiel #4
0
def test_dsift_sift(window_size):
    bin_size = 4
    magnif = 3
    scale = bin_size / magnif
    img_smooth = gaussian(img, sigma=sqrt(scale**2 - 0.25))
    f, d = dsift(img_smooth,
                 size=bin_size,
                 step=10,
                 window_size=window_size,
                 float_descriptors=True)
    num_keypoints = f.shape[0]
    f_ = np.column_stack([
        f,
        np.ones(shape=(num_keypoints, )) * scale,
        np.zeros(shape=(num_keypoints, ))
    ])
    f_, d_ = sift(img,
                  magnification=magnif,
                  frames=f_,
                  first_octave=-1,
                  n_levels=5,
                  compute_descriptor=True,
                  float_descriptors=True,
                  window_size=window_size)
    err = np.std(d - d_) / np.std(d)

    assert err < 0.1
Beispiel #5
0
def test_sift_shape(compute_descriptor):
    result = sift(img, compute_descriptor=compute_descriptor)
    if compute_descriptor:
        assert result[0].shape[1] == 4
        assert result[1].shape[1] == 128
        assert result[0].shape[0] == result[1].shape[0]
    else:
        assert result.shape[1] == 4
Beispiel #6
0
def test_sift_sort_user_defined_scales():
    i = half_img.copy()
    frames = np.array([[4., 5., 3., 0], [3., 2., 2., np.pi / 2],
                       [8., 6., 1., 1.]])
    new_frames, descriptors = sift(i, frames=frames, compute_descriptor=True)

    assert_allclose(new_frames[0], frames[-1], rtol=1e-3)
    assert_allclose(descriptors[0, -5:], [46, 14,  0,  0,  0])
    assert new_frames.shape[0] == 3
Beispiel #7
0
def test_sift_force_orientations():
    i = half_img.copy()
    frames = np.array([[4., 5., 2., 0], [3., 2., 3., np.pi / 2],
                       [8., 6., 4., 1.]])
    new_frames, descriptors = sift(i, frames=frames, compute_descriptor=True,
                                   force_orientations=True)

    assert_allclose(new_frames[0], [4, 5, 2, 4.6239], rtol=1e-3)
    assert_allclose(descriptors[0, :5], [5, 1, 0, 0, 1])
    assert new_frames.shape[0] == 3
Beispiel #8
0
def test_sift_force_orientations():
    frames = np.array([[6.90227, 242.036, 1.84193, 2.63054],
                       [5.28098, 342.099, 1.90079, 5.07138],
                       [22.1369, 273.583, 2.06255, 1.56508]])
    new_frames, descriptors = sift(img,
                                   frames=frames,
                                   compute_descriptor=True,
                                   force_orientations=True)

    assert new_frames.shape[0] == 4
    assert_allclose(new_frames[0], [6.90227, 242.036, 1.84193, 2.63051],
                    rtol=1e-3)
    assert_allclose(descriptors[0, :10],
                    [107, 171, 0, 0, 0, 0, 0, 11, 144, 171])
Beispiel #9
0
def test_sift_sort_user_defined_scales():
    frames = np.array([[5.28098, 342.099, 1.90079, 5.07138],
                       [6.90227, 242.036, 1.84193, 2.63054],
                       [22.1369, 273.583, 2.06255, 1.56508]])
    new_frames, descriptors = sift(img, frames=frames, compute_descriptor=True)

    assert new_frames.shape[0] == 3
    assert_allclose(new_frames[0], frames[1], rtol=1e-3)
    assert_allclose(new_frames[1], frames[0], rtol=1e-3)
    assert_allclose(new_frames[2], frames[2], rtol=1e-3)
    assert_allclose(descriptors[0, :10],
                    [107, 171, 0, 0, 0, 0, 0, 11, 144, 171])
    assert_allclose(descriptors[1, :10], [17, 0, 0, 11, 20, 1, 16, 73, 95, 11])
    assert_allclose(descriptors[2, :10], [134, 15, 0, 0, 1, 1, 0, 0, 134, 73])
Beispiel #10
0
def test_sift_detector():
    f = sift(img, first_octave=-1, peak_thresh=0.01)
    frames = actual_frames.copy()
    # scale the components so that 1 pixel erro in x,y,z is equal to a
    # 10-th of angle
    scale = (20 / np.pi)
    frames[:, -1] = np.mod(frames[:, -1], np.pi * 2) * scale
    f[:, -1] = np.mod(f[:, -1], np.pi * 2) * scale
    D2 = cdist(frames, f)
    d2 = D2.min(axis=1)
    d2.sort()
    err = np.sqrt(d2)
    quant80 = round(0.8 * f.shape[0])

    # check for less than one pixel error at 80% quantile
    assert err[quant80] < 1
Beispiel #11
0
def test_sift_user_defined_frames():
    frames, descriptors = sift(img,
                               frames=actual_frames,
                               first_octave=-1,
                               compute_descriptor=True,
                               float_descriptors=True,
                               norm_thresh=0,
                               verbose=False)
    D2 = cdist(actual_frames, frames)
    index = D2.argmin(axis=1)
    descriptors = descriptors[index, :]
    t1 = np.mean(np.sqrt(np.sum((actual_descriptors - descriptors)**2,
                                axis=1)))
    t2 = np.mean(np.sqrt(np.sum(actual_descriptors**2, axis=1)))
    err = t1 / t2

    assert err < 0.1
Beispiel #12
0
def test_sift_n_frames():
    i = img.copy()
    frames = sift(i)
    assert_allclose(frames[0], [2.16217, 128.056, 2.13029, 5.9325], rtol=1e-3)
    assert frames.shape[0] == 730
Beispiel #13
0
def test_sift_non_float_descriptors():
    frames, descriptors = sift(img, compute_descriptor=True)

    assert_allclose(frames[0], [5.28098, 342.099, 1.90079, 5.07138], rtol=1e-3)
    assert_allclose(descriptors[0, :5], [17, 0, 0, 11, 20])
    assert frames.shape[0] == 797