コード例 #1
0
def test_noisy_square_image():
    im = cp.zeros((50, 50)).astype(float)
    im[:25, :25] = 1.0
    np.random.seed(seed=1234)  # result is specic to this NumPy seed
    im = im + cp.asarray(np.random.uniform(size=im.shape)) * 0.2

    # # Moravec
    # results = peak_local_max(corner_moravec(im),
    #                          min_distance=10, threshold_rel=0)
    # # undefined number of interest points
    # assert results.any()

    # Harris
    results = peak_local_max(corner_harris(im, method="k"),
                             min_distance=10,
                             threshold_rel=0)
    assert len(results) == 1
    results = peak_local_max(corner_harris(im, method="eps"),
                             min_distance=10,
                             threshold_rel=0)
    assert len(results) == 1

    # Shi-Tomasi
    results = peak_local_max(corner_shi_tomasi(im, sigma=1.5),
                             min_distance=10,
                             threshold_rel=0)
    assert len(results) == 1
コード例 #2
0
def test_square_image():
    im = cp.zeros((50, 50)).astype(float)
    im[:25, :25] = 1.0

    # # Moravec
    # results = peak_local_max(corner_moravec(im),
    #                          min_distance=10, threshold_rel=0)
    # # interest points along edge
    # assert len(results) == 57

    # Harris
    results = peak_local_max(corner_harris(im, method="k"),
                             min_distance=10,
                             threshold_rel=0)
    # interest at corner
    assert len(results) == 1

    results = peak_local_max(corner_harris(im, method="eps"),
                             min_distance=10,
                             threshold_rel=0)
    # interest at corner
    assert len(results) == 1

    # Shi-Tomasi
    results = peak_local_max(corner_shi_tomasi(im),
                             min_distance=10,
                             threshold_rel=0)
    # interest at corner
    assert len(results) == 1
コード例 #3
0
def test_rotated_img():
    """
    The harris filter should yield the same results with an image and it's
    rotation.
    """
    im = img_as_float(cp.asarray(data.astronaut().mean(axis=2)))
    im_rotated = im.T

    # # Moravec
    # results = peak_local_max(corner_moravec(im),
    #                          min_distance=10, threshold_rel=0)
    # results_rotated = peak_local_max(corner_moravec(im_rotated),
    #                                  min_distance=10, threshold_rel=0)
    # assert (cp.sort(results[:, 0]) == cp.sort(results_rotated[:, 1])).all()
    # assert (cp.sort(results[:, 1]) == cp.sort(results_rotated[:, 0])).all()

    # Harris
    threshold_rel = 1e-8
    # TODO: skimage version uses threshold_rel = 0, but that causes a minor
    #       difference in results vs. results_rotated here.
    results = peak_local_max(corner_harris(im),
                             min_distance=10,
                             threshold_rel=threshold_rel)
    results_rotated = peak_local_max(corner_harris(im_rotated),
                                     min_distance=10,
                                     threshold_rel=threshold_rel)
    assert (cp.sort(results[:, 0]) == cp.sort(results_rotated[:, 1])).all()
    assert (cp.sort(results[:, 1]) == cp.sort(results_rotated[:, 0])).all()

    # Shi-Tomasi
    results = peak_local_max(corner_shi_tomasi(im),
                             min_distance=10,
                             threshold_rel=0)
    results_rotated = peak_local_max(corner_shi_tomasi(im_rotated),
                                     min_distance=10,
                                     threshold_rel=0)
    assert (cp.sort(results[:, 0]) == cp.sort(results_rotated[:, 1])).all()
    assert (cp.sort(results[:, 1]) == cp.sort(results_rotated[:, 0])).all()
コード例 #4
0
def test_num_peaks():
    """For a bunch of different values of num_peaks, check that
    peak_local_max returns exactly the right amount of peaks. Test
    is run on the astronaut image in order to produce a sufficient number of corners"""

    img_corners = corner_harris(rgb2gray(cp.asarray(data.astronaut())))

    for i in range(20):
        n = cp.random.randint(1, 21)
        results = peak_local_max(img_corners,
                                 min_distance=10,
                                 threshold_rel=0,
                                 num_peaks=n)
        assert results.shape[0] == n
コード例 #5
0
def test_squared_dot():
    im = cp.zeros((50, 50))
    im[4:8, 4:8] = 1
    im = img_as_float(im)

    # Moravec fails

    # Harris
    results = peak_local_max(corner_harris(im),
                             min_distance=10,
                             threshold_rel=0)
    assert (results == cp.asarray([[6, 6]])).all()

    # Shi-Tomasi
    results = peak_local_max(corner_shi_tomasi(im),
                             min_distance=10,
                             threshold_rel=0)
    assert (results == cp.asarray([[6, 6]])).all()