ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
625 stars 161 forks source link

Wrong transform matrix on 2D rigid transformation #464

Closed tigerhu7 closed 1 year ago

tigerhu7 commented 1 year ago

Describe the bug When conducting 2D rigid transformations, the output fwd and inv parameters turned to be the same, which is obviously wrong.

To Reproduce Code

import numpy as np
import ants
im1 = np.zeros([51, 51])
cen = 25
half_hei = 10
half_wei = 6
# fixed image
im1[cen-half_hei: cen+half_hei+1, cen-half_wei: cen+half_wei+1 ] = 1 
# moving image
im2 = skimage.transform.rotate( im1, center=[cen, cen], angle = 45 )
im2[im2>0.6] = 1
im2[im2<=0.6] = 0
img1 = ants.from_numpy( im1*1.0)
img2 = ants.from_numpy( im2*1.0)    
mytx_rigid = ants.registration(fixed=img1, moving=img2, type_of_transform = 'Rigid')
print( mytx_rigid['fwdtransforms'][0] )
print( mytx_rigid['invtransforms'][0] )

Expected behavior Get same .mat file

image

Version Info

stnava commented 1 year ago

our standard is that matrix transforms are stored as is - and the inverse is calculated on the fly. so what you report here is how we have defined things.

@cookpa - do you know where in the documentation this is covered?

cookpa commented 1 year ago

https://github.com/ANTsX/ANTs/wiki/Forward-and-inverse-warps-for-warping-images,-pointsets-and-Jacobians

Use the whichtoinvert option in ants.apply_transforms to use the inverse warp correctly.

tigerhu7 commented 1 year ago

@stnava @cookpa I see, thanks !!