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

Apply transformation matrices generated by greedy to images loaded in SimpleITK #18

Open
jingxuanlim opened this issue Sep 21, 2020 · 1 comment

Comments

@jingxuanlim
Copy link

Hello

I'm having a great time using greedy.

I'm wondering what's an easy way to apply the transforms generated by greedy to images loaded in SimpleITK (Python)? I understand that one difference is that greedy (RAS) and ITK (LPS) uses a different coordinate system, so I tried two things to remedy that -- which didn't seem to work:

  • I negated some values of my greedy generated affine matrix so that they are now compatible to images in LPS coordinates, according to this article. I then applied that modified affine matrix to my image loaded in SimpleITK.

  • I transposed the image in the first two axes, applied the affine transformation, then transposed the image back.

Am I missing other differences? Or am I not, so it's probably the case that I did something wrong?

Help appreciated from anyone who has tried doing this. I'm very new to registration, so any help would be great! Thanks in advance!

Best Wishes

@beaslera
Copy link

beaslera commented Jul 2, 2021

What worked for me was to calculate how the axes changes greedy applies to the pixels (both before the transform and after) could be applied to the transform matrix to get the same result.
LPS_affine = np.loadtxt('affine.mat') * np.array( [[1, 1, -1, -1], [1, 1, -1, -1], [-1, -1, 1, 1], [1, 1, 1, 1]])
Using LPS_affine in a SimpleITK.AffineTransform gave me the same results as doing a resample with greedy.

Alternately, one could probably use the c3d tool to convert the affine matrix file, but I have not tried.

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

2 participants