コード例 #1
0
def test_propagate_up_left(array):
    """Propagating the identity transformation expects indices to propagate
    one cell at a time, here up and towards the left.
    """
    y, x = array.shape[-2:]
    matcher = FeatureMatcher(array, array)
    indices, scores = matcher.repro_target.indices, matcher.repro_target.scores
    indices.zero_()

    indices[:, 0, -1, -1] = y - 1
    indices[:, 1, -1, -1] = x - 1
    scores[:, 0, -1, -1] = 1.0

    matcher.compare_features_nearby(radius=1, split=2)
    assert (
        indices[:, :, y - 2, x - 1] == torch.tensor([y - 2, x - 1], dtype=torch.long)
    ).all()
    assert (
        indices[:, :, y - 1, x - 2] == torch.tensor([y - 1, x - 2], dtype=torch.long)
    ).all()

    matcher.compare_features_nearby(radius=1, split=2)
    assert (
        indices[:, :, y - 2, x - 2] == torch.tensor([y - 2, x - 2], dtype=torch.long)
    ).all()
コード例 #2
0
def test_propagate_down_right(array):
    """Propagating the identity transformation expects indices to propagate
    one cell at a time, this time down and towards the right.
    """
    matcher = FeatureMatcher(array, array)
    indices = matcher.repro_target.indices
    indices.zero_()

    matcher.compare_features_nearby(radius=1, split=2)
    assert (indices[:, :, 1, 0] == torch.tensor([1, 0], dtype=torch.long)).all()
    assert (indices[:, :, 0, 1] == torch.tensor([0, 1], dtype=torch.long)).all()

    matcher.compare_features_nearby(radius=1, split=2)
    assert (indices[:, :, 1, 1] == torch.tensor([1, 1], dtype=torch.long)).all()