Project-MONAI / MONAI

AI Toolkit for Healthcare Imaging
https://monai.io/
Apache License 2.0
5.64k stars 1.03k forks source link

Compose deformation vector fields (DVFs) #4604

Open xiaogengen-007 opened 2 years ago

xiaogengen-007 commented 2 years ago

Is your feature request related to a problem? Please describe. Does MONAI have code to compose 2 DVFs together? In image registration, we often encounter multi-stage registration. A series of DVF will be generated to warp the moving image sequentially. However, each warping will blur the image a bit due to interpolation. The best approach is to compose the DVF first and warp the image only once.

Describe the solution you'd like The TensorFlow version of voxelmorph already has this feature implemented. But not in PyTorch. It would be great if it is available in MONAI in PyTorch. The following 3 functions in voxelmorph and neurite are related to the task: https://github.com/voxelmorph/voxelmorph/blob/dev/voxelmorph/tf/utils/utils.py: def compose(transforms, interp_method='linear', shift_center=True, indexing='ij') https://github.com/voxelmorph/voxelmorph/blob/dev/voxelmorph/tf/utils/utils.py: def transform(vol, loc_shift, interp_method='linear', indexing='ij', fill_value=None) https://github.com/adalca/neurite/blob/dev/neurite/tf/utils/utils.py: def interpn(vol, loc, interp_method='linear', fill_value=None)

wyli commented 1 year ago

thanks, we take this feature request into consideration when creating https://github.com/Project-MONAI/MONAI/pull/5436, we'll follow up on this with those trainable use cases

ebrahimebrahim commented 1 year ago

What would it mean to compose DVFs?

Composing DDFs makes sense because the composite of two displacement fields is a displacement field. Resampling/warping an image via DDF $\vec{v}$ and then via DDF $\vec{u}$ is the same as resampling the image once via their composite. In MONAI this composite can be computed by

u + monai.networks.blocks.Warp(v,u)

(e.g. here)

The situation with DVFs is not so simple. Warping an image via a DVF requires first integrating to get a DDF and then resampling by that DDF. Say you have two DVFs $x_1$ and $x_2$. Then you integrate to compute DDFs $u_1$ and $u_2$ respectively. Then you warp your image via $u_1$ and then you warp again via $u_2$. Can you find a canonical DVF $x$ that corresponds to the overall operation? That is, can you define $x$ in a canonical way such that the integral of $x$ is the composite of $u_1$ and $u_2$? It's not clear to me how one would do this so I am curious what is meant by this feature request.

wyli commented 1 year ago

DVF usually means dense velocity field, but according to the title of this ticket it used as an acronym for 'deformation vector field', in my understanding that's just dense displacement field...

ebrahimebrahim commented 1 year ago

That makes a lot more sense... IDK why I assumed everyone would use the monai acronyms

xiaogengen-007 commented 1 year ago

Thank you all for the great comments! @ebrahimebrahim Yes, I was referring to composing the deformation vector fields (DDFs in monai). Thanks for the solution, it works perfectly.