ITK Python Image of itk.D Vectors For Composite Transform

Hello,

I am trying to convert a numpy array to an image of type itk.Image[itk.Vector[itk.D,3],3] in python ITK. The issue is that most ITK filters do not support this type. I would rather avoid having to compile my own ITK version, so I am trying to figure out if there is any workaround. Here are some things I’ve tried:

  • Use itk.image_from_array to load numpy array into itk.VectorImage type, and then use CastImageFilter to convert this to itk.Image[itk.Vector[itk.D,3],3]. Python CastImageFilter does not support this output type.
  • Use itk.image_from_array to load numpy array into three different itk.Image[itk.D,3] images and then combine them with itk.ComposeImageFilter. Again, itk.ComposeImageFilter does not support itk.Image[itk.Vector[itk.D,3],3] as an output type.

The reason I need itk.Image[itk.Vector[itk.D,3],3] is to initialize a itk.DisplacementFieldTransform object, which only appears to support images of vectors (not itk.VectorImage). Any help would be greatly appreciated!

1 Like

Have you tried casting your numpy array into 32-bit floats, then using itk.Image[itk.Vector[itk.F,3],3]? There is usually no need for such high precision for displacement fields, hence it is not pre-built.

Thank you for the reply. The reason for wanting a displacement field of type itk.Image[itk.Vector[itk.D,3],3] is that I eventually want to use the displacement field in a CompositeTransform and itk.CompositeTransform only exposes the template class for type itk.D.

Maybe a future ITK version should expose itk.CompositeTransform for itk.F to make this use case easier.

@Tom_Birdsong @Pranjal_Sahu did you run into this issue, and if so how did you solve it?

Please check this test file.

1 Like

This test does not address composite transform use of DF transform.

I ran into exactly the same issue – one can define the DisplacementField transform of a float type, but cannot add it to a composite transform since it can only be of a double precision.

@Pranjal_Sahu, I’ve checked your file, but it doesn’t cover the CompositeTransform case.

Any improvements or ideas? The only workaround I’ve found is to cast dvf through numpy, but it is ugly :frowning:

Hi,

We can also wrap Composite Transform for itk.F – here is a patch: