pyushkevich / greedy

Very fast greedy diffeomorphic registration code
GNU General Public License v3.0
59 stars 16 forks source link

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

Open jingxuanlim opened 3 years ago

jingxuanlim commented 3 years ago

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:

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 commented 3 years ago

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.