def test_affine_to_params():
    # TODO: test with zooms and shears
    eps = np.finfo(np.float).eps
    affine = np.eye(4)
    affine[:3, 3] = [1.1, 0.55, -.3]
    pitch = np.array([[1., 0., 0.],
                      [0., 0., 1.],
                      [0., -1., 0.]])
    roll = np.array([[cos(-pi / 3.), 0., sin(-pi / 3.)],
                     [0., 1., 0.],
                     [-sin(-pi / 3.), 0., cos(-pi / 3.)]])
    yaw = np.array([[cos(pi / 4.), sin(pi / 4.), 0.],
                    [-sin(pi / 4.), cos(pi / 4.), 0.],
                    [0., 0., 1.]])
    affine[:3, :3] = pitch.dot(roll).dot(yaw)
    params = np.array([1.1, 0.55, -.3, pi / 2., -pi / 3., pi / 4.,
                       1., 1., 1., 0., 0., 0.])
    np.testing.assert_allclose(affine_to_params(affine), params, atol=eps)

    # Test affine_to_params is the inverse of params_to_affine
    params2 = affine_to_params(params_to_affine(params))
    np.testing.assert_allclose(params2, params, atol=eps)

    # Test same result as spm_matrix function of spm
    np.testing.assert_allclose(params, spm_imatrix(affine), atol=1e4 * eps)
def test_affine_to_params():
    # TODO: test with zooms and shears
    eps = np.finfo(np.float).eps
    affine = np.eye(4)
    affine[:3, 3] = [1.1, 0.55, -0.3]
    pitch = np.array([[1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, -1.0, 0.0]])
    roll = np.array([[cos(-pi / 3.0), 0.0, sin(-pi / 3.0)], [0.0, 1.0, 0.0], [-sin(-pi / 3.0), 0.0, cos(-pi / 3.0)]])
    yaw = np.array([[cos(pi / 4.0), sin(pi / 4.0), 0.0], [-sin(pi / 4.0), cos(pi / 4.0), 0.0], [0.0, 0.0, 1.0]])
    affine[:3, :3] = pitch.dot(roll).dot(yaw)
    params = np.array([1.1, 0.55, -0.3, pi / 2.0, -pi / 3.0, pi / 4.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0])
    np.testing.assert_allclose(spm_internals.affine_to_params(affine), params, atol=eps)

    # Test affine_to_params is the inverse of params_to_affine
    params2 = spm_internals.affine_to_params(spm_internals.params_to_affine(params))
    np.testing.assert_allclose(params2, params, atol=eps)
def test_params_to_affine():
    # TODO: test with zooms and shears
    eps = np.finfo(np.float).eps
    params = np.array([.1, .5, -.6, .1, -4., 5.1,
                       1., 1., 1., 0., 0., 0.])
    affine = np.eye(4)
    affine[:3, 3] = params[:3]
    pitch = np.array([[1., 0., 0.],
                      [0., cos(.1), sin(.1)],
                      [0., -sin(.1), cos(.1)]])
    roll = np.array([[cos(-4.), 0., sin(-4.)],
                     [0., 1., 0.],
                     [-sin(-4.), 0., cos(-4.)]])
    yaw = np.array([[cos(5.1), sin(5.1), 0.],
                    [-sin(5.1), cos(5.1), 0.],
                    [0., 0., 1.]])
    affine[:3, :3] = pitch.dot(roll).dot(yaw)
    np.testing.assert_allclose(params_to_affine(params), affine)

    # Test params_to_affine is the inverse of affine_to_params
    affine2 = params_to_affine(affine_to_params(affine))
    np.testing.assert_allclose(affine2, affine)

    # Test same result as spm_matrix function of spm
    np.testing.assert_allclose(affine, spm_matrix(params), atol=eps)
示例#4
0
def test_affine_to_params():
    # TODO: test with zooms and shears
    eps = np.finfo(np.float).eps
    affine = np.eye(4)
    affine[:3, 3] = [1.1, 0.55, -.3]
    pitch = np.array([[1., 0., 0.],
                      [0., 0., 1.],
                      [0., -1., 0.]])
    roll = np.array([[cos(-pi / 3.), 0., sin(-pi / 3.)],
                     [0., 1., 0.],
                     [-sin(-pi / 3.), 0., cos(-pi / 3.)]])
    yaw = np.array([[cos(pi / 4.), sin(pi / 4.), 0.],
                    [-sin(pi / 4.), cos(pi / 4.), 0.],
                    [0., 0., 1.]])
    affine[:3, :3] = pitch.dot(roll).dot(yaw)
    params = np.array([1.1, 0.55, -.3, pi / 2., -pi / 3., pi / 4.,
                       1., 1., 1., 0., 0., 0.])
    np.testing.assert_allclose(spm_internals.affine_to_params(affine), params,
                               atol=eps)

    # Test affine_to_params is the inverse of params_to_affine
    params2 = spm_internals.affine_to_params(
        spm_internals.params_to_affine(params))
    np.testing.assert_allclose(params2, params, atol=eps)
def test_params_to_affine():
    # TODO: test with zooms and shears
    eps = np.finfo(np.float).eps
    params = np.array([0.1, 0.5, -0.6, 0.1, -4.0, 5.1, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0])
    affine = np.eye(4)
    affine[:3, 3] = params[:3]
    pitch = np.array([[1.0, 0.0, 0.0], [0.0, cos(0.1), sin(0.1)], [0.0, -sin(0.1), cos(0.1)]])
    roll = np.array([[cos(-4.0), 0.0, sin(-4.0)], [0.0, 1.0, 0.0], [-sin(-4.0), 0.0, cos(-4.0)]])
    yaw = np.array([[cos(5.1), sin(5.1), 0.0], [-sin(5.1), cos(5.1), 0.0], [0.0, 0.0, 1.0]])
    affine[:3, :3] = pitch.dot(roll).dot(yaw)
    np.testing.assert_allclose(spm_internals.params_to_affine(params), affine)

    # Test params_to_affine is the inverse of affine_to_params
    affine2 = spm_internals.params_to_affine(spm_internals.affine_to_params(affine))
    np.testing.assert_allclose(affine2, affine)
示例#6
0
def test_params_to_affine():
    # TODO: test with zooms and shears
    eps = np.finfo(np.float).eps
    params = np.array([.1, .5, -.6, .1, -4., 5.1,
                       1., 1., 1., 0., 0., 0.])
    affine = np.eye(4)
    affine[:3, 3] = params[:3]
    pitch = np.array([[1., 0., 0.],
                      [0., cos(.1), sin(.1)],
                      [0., -sin(.1), cos(.1)]])
    roll = np.array([[cos(-4.), 0., sin(-4.)],
                     [0., 1., 0.],
                     [-sin(-4.), 0., cos(-4.)]])
    yaw = np.array([[cos(5.1), sin(5.1), 0.],
                    [-sin(5.1), cos(5.1), 0.],
                    [0., 0., 1.]])
    affine[:3, :3] = pitch.dot(roll).dot(yaw)
    np.testing.assert_allclose(spm_internals.params_to_affine(params), affine)

    # Test params_to_affine is the inverse of affine_to_params
    affine2 = spm_internals.params_to_affine(
        spm_internals.affine_to_params(affine))
    np.testing.assert_allclose(affine2, affine)