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

Jacobian determinant #472

Closed devDonnn closed 6 months ago

devDonnn commented 1 year ago

Hi, ANTsPy create_jacobian_determinant_image(domain_image, tx, do_log=False, geom=False) function requires a domain image. However, ANTs command line tool CreateJacobianDeterminantImage does not require the domain image and is able to compute the jacobian using the provided warp image only. Can the create_jacobian_determinant_image function be made without requiring a domain image so the necessary info is retrieved from the warp image? The domain image appears to be redundant.

stnava commented 1 year ago

We won’t change the interface but but you can pass in the warp image itself for the domain.

On Fri, Jun 9, 2023 at 7:01 AM Don @.***> wrote:

Hi, ANTsPy create_jacobian_determinant_image(domain_image, tx, do_log=False, geom=False) function requires a domain image. However, ANTs command line tool CreateJacobianDeterminantImage does not require the domain image and is able to compute the jacobian using the provided warp image only. Can the create_jacobian_determinant_image function be made without requiring a domain image so the necessary info is retrieved from the warp image? The domain image appears to be redundant.

— Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTsPy/issues/472, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACPE7VTNEGNBTQEOOYKUGDXKL7A7ANCNFSM6AAAAAAZAPWDWI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

cookpa commented 1 year ago

Attempting to use the warp as the domain image fails for me because it attempts to clone as double, but double is not supported for multi-channel images.

This also prevents warps written from CLI antsRegistration using default params. Could I fix this by adding double types here?

https://github.com/ANTsX/ANTsPy/blob/b67c22f5896f43d3ffadbea763e57d083cc6174c/ants/lib/LOCAL_mergeChannels.cxx#L189-L210

stnava commented 1 year ago

yes - I think that would work

cookpa commented 1 year ago

OK cool. I think it would be nice to be able to read warps from ANTs into ANTsPy.

For the Jacobian use case, the image would additionally need to be split into components, so that a single-component image can be passed to the library function to store the result.

stnava commented 1 year ago

I think there must be some confusion here .... we can already read warps:

>>> i1=ants.image_read(ants.get_data("r16"))
>>> i2=ants.image_read(ants.get_data("r64"))
>>> reg=ants.registration(i1,i2,'SyN')
>>> ants.image_read( reg['fwdtransforms'][0] )
ANTsImage
     Pixel Type : float (float32)
     Components : 2
     Dimensions : (256, 256)
     Spacing    : (1.0, 1.0)
     Origin     : (0.0, 0.0)
     Direction  : [1. 0. 0. 1.]
stnava commented 1 year ago

this is how one would do it

dimg=ants.image_read( reg['fwdtransforms'][0] ).split_channels()[0]
ants.create_jacobian_determinant_image( dimg, reg['fwdtransforms'][0] )
devDonnn commented 1 year ago

this is how one would do it

dimg=ants.image_read( reg['fwdtransforms'][0] ).split_channels()[0]
ants.create_jacobian_determinant_image( dimg, reg['fwdtransforms'][0] )

Thanks, @stnava. This works well.

cookpa commented 1 year ago

I guess I took the earlier comment too literally, you can't use the warp field itself as a domain image. This fails

warp = ants.image_read(mytx['fwdtransforms'][0])
jac = ants.create_jacobian_determinant_image(warp, warp)

But you can split it yourself and use the first channel. I'll update the docs to make note of this