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

How can I transform two CTs with a known affine transformation matrix? #539

Open
angolin22 opened this issue Aug 9, 2023 · 6 comments
Open

Comments

@angolin22
Copy link

hello, thanks for your excellent work! I have a problem:
I have two 3D CT images, and I know the affine transformation matrix between them. e. g.

[[ 9.92477011e-01 -8.45505280e-02  8.85471061e-02  5.05205949e+01] 
[ 8.73986445e-02  9.95757283e-01 -2.87907932e-02 -5.85686522e+00] 
[-8.57371490e-02  3.63130975e-02  9.95655814e-01 -4.96898369e+01]
[-0.00000000e+00 -0.00000000e+00 -0.00000000e+00  1.00000000e+00]]

How can I transform CT with it?
Thanks

@adalca
Copy link
Collaborator

adalca commented Aug 9, 2023

Sounds like a job for @mu40

@angolin22
Copy link
Author

May I ask if @mu40 has completed this part of the content?

@adalca
Copy link
Collaborator

adalca commented Aug 9, 2023

im not sure what you mean, but @mu40 has been spearheading our affine work and code.

@angolin22
Copy link
Author

May I ask where is the affine code and how to use it?

@mu40
Copy link
Contributor

mu40 commented Aug 9, 2023

Assuming your images moving and fixed are defined on the same voxel grid, and your matrix transforms the centered voxel coordinates of fixed to those of moving, moving moving can be as simple as

trans = matrix[..., :-1, :]
moved = vxm.layers.SpatialTransformer()((moving, trans))

where moving and fixed would have a leading batch as well as a trailing feature dimension.

For the more general case, you can pass shift_center=False to interpret matrix as a transform from zero-based voxel indices of the fixed to zero-based voxel indices of the moving image. You can also set the output shape, should your images live in different voxel spaces:

shape = fixed.shape[1:-1]
moved = vxm.layers.SpatialTransformer(shift_center=False, shape=shape)((moving, trans))

@mu40
Copy link
Contributor

mu40 commented Dec 5, 2023

If this is still relevant, @angolin22, we now have a tutorial on affine registration at w3id.org/synthmorph.

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

3 participants