Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs with shear in realign and spm_imatrix #322

Open
dagra opened this issue Apr 16, 2019 · 0 comments
Open

Bugs with shear in realign and spm_imatrix #322

dagra opened this issue Apr 16, 2019 · 0 comments

Comments

@dagra
Copy link

dagra commented Apr 16, 2019

Hi,
while i was doing some experiments with realign with more parameters than the default and with spm_imatrix i found out the following problems:

  1. even though realign.py can compute more parameters than the default 6 rigid body, it returns only the first 6 and i think the problem is in this line where 6 is hardcoded, but it should be dependent on lkp, i.e. sess_rp[..., :len(self.lkp)]

  2. spm_imatrix seems incorrect and the following test case identifies the issues

    def test_spm_imatrix_with_shear():
        params = np.asarray([-3.11811347, 3.42120573, -3.67295542,  # translation
                             -0.74295001, 0.20452795, -0.98378122,  # rotation
                             1., 1., 1.,  # zoom
                             1.2, 3., 0.])  # shear
        np.testing.assert_array_almost_equal(spm_imatrix(spm_matrix(params)),
                                             params)
    

    running the above test, IndexError: index 3 is out of bounds for axis 1 with size 3 is raised in this line. Comparing it with spm's spm_imatrix i think it came up from the different indexing in matlab and it should be p[5] = np.arctan2(-rang(R1[1, 0]), rang(-R1[2, 0] / R[0, 2])). After correcting this, the test fails with

    E       AssertionError: 
    E       Arrays are not almost equal to 6 decimals
    E       
    E       (mismatch 41.6666666667%)
    E        x: array([-3.118113,  3.421206, -3.672955,  0.      ,  1.570796, -1.934645,
    E               1.      ,  1.      ,  1.      ,  0.      ,  0.      ,  0.      ])
    E        y: array([-3.118113,  3.421206, -3.672955, -0.74295 ,  0.204528, -0.983781,
    E               1.      ,  1.      ,  1.      ,  1.2     ,  3.      ,  0.      ])
    

    The reason of this error is in this line and the different flattening method where numpy.ravel by default concatenates the rows, while in matlab the columns. So, two possible solutions (i'm not sure which one is preferable) would be

    1. p[9:12] = C.ravel(order='F')[[3, 6, 7]]
    2. p[9:12] = C.T.ravel()[[3, 6, 7]]

If you agree with these issues and corresponding solutions, i can open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant