Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
def test_template():
    size = 100
    # Float prefactors ensure that image range is between 0 and 1
    image = np.full((400, 400), 0.5)
    target = 0.1 * (np.tri(size) + np.tri(size)[::-1])
    target_positions = [(50, 50), (200, 200)]
    for x, y in target_positions:
        image[x:x + size, y:y + size] = target
    np.random.seed(1)
    image += 0.1 * np.random.uniform(size=(400, 400))
    image = cp.asarray(image)
    target = cp.asarray(target)

    result = match_template(image, target)
    delta = 5

    positions = peak_local_max(result, min_distance=delta)

    if len(positions) > 2:
        # Keep the two maximum peaks.
        intensities = result[tuple(positions.T)]
        i_maxsort = cp.argsort(intensities)[::-1]
        positions = positions[i_maxsort][:2]

    # Sort so that order matches `target_positions`.
    positions = positions[cp.argsort(positions[:, 0])]

    for xy_target, xy in zip(target_positions, positions):
        assert_array_almost_equal(xy, xy_target)
Exemplo n.º 4
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()
Exemplo n.º 5
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