Example #1
0
def test_affine_transformation():
    x = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])

    # list of transformations to be tested
    T = np.eye(3)
    I = np.eye(3)
    S = np.eye(3)
    A = np.eye(3)
    translations = []
    isometries = []
    similarities = []
    affinities = []

    for i in xrange(100):
        translations.append(T)
        isometries.append(I)
        similarities.append(S)
        affinities.append(A)
        T[0:2, 2] = np.random.random(2)
        I = rotation_matrix(2 * np.pi * np.random.random_sample())
        I[0:2, 2] = np.random.random(2)
        S = similarity_matrix(2 * np.pi * np.random.random_sample(),
                              np.random.random_sample())
        S[0:2, 2] = 100 * np.random.random(2)
        A[0:2, :] = np.random.random((2, 3))

    for B in translations + isometries + similarities + affinities:
        xx = common.points_apply_homography(B, x)
        E = estimation.affine_transformation(x, xx)
        assert_array_almost_equal(E, B)
Example #2
0
def test_affine_transformation():
    x =  np.array([[0, 0], [0, 1], [1, 0], [1, 1]])

    # list of transformations to be tested
    T = np.eye(3)
    I = np.eye(3)
    S = np.eye(3)
    A = np.eye(3)
    translations = []
    isometries = []
    similarities = []
    affinities = []

    for i in xrange(100):
        translations.append(T)
        isometries.append(I)
        similarities.append(S)
        affinities.append(A)
        T[0:2, 2] = np.random.random(2)
        I = rotation_matrix(2*np.pi * np.random.random_sample())
        I[0:2, 2] = np.random.random(2)
        S = similarity_matrix(2*np.pi * np.random.random_sample(),
                np.random.random_sample())
        S[0:2, 2] = 100 * np.random.random(2)
        A[0:2, :] = np.random.random((2, 3))

    for B in translations + isometries + similarities + affinities:
        xx = common.points_apply_homography(B, x)
        E = estimation.affine_transformation(x, xx)
        assert_array_almost_equal(E, B)
Example #3
0
def global_from_local(tiles):
    """
    Computes the pointing correction of a full roi using local corrections on
    tiles.

    Args:
        tiles: list of paths to folders associated to each tile

    Returns:
        the estimated pointing correction for the specified tile

    In each folder we expect to find the files pointing.txt and center.txt. The
    file pointing.txt contains the local correction (a projective transform
    given in homogeneous coordinates), and the file center.txt contains the
    coordinates of the mean of the keypoints of the secondary image.
    """
    # lists of matching points
    x  = []
    xx = []

    # loop over all the tiles
    for f in tiles:
        center = os.path.join(f, 'center_keypts_sec.txt')
        pointing = os.path.join(f, 'pointing.txt')
        if os.path.isfile(center) and os.path.isfile(pointing):
            A = np.loadtxt(pointing)
            p = np.loadtxt(center)
            if A.shape == (3, 3) and p.shape == (2,):
                q = np.dot(A, np.array([p[0], p[1], 1]))
                x.append(p)
                xx.append(q[0:2])

    if not x:
        return np.eye(3)
    elif len(x) == 1:
        return A
    elif len(x) == 2:
        #TODO: replace translation with similarity
        return estimation.translation(np.array(x), np.array(xx))
    else:
        # estimate an affine transformation transforming x in xx
        return estimation.affine_transformation(np.array(x), np.array(xx))