Vector Image To Image of Vectors

Hi all,

In discussion on the ITKStrain remote module we recently encountered a question of handling vector-valued image data in the ITK Python wrapping. I’ve worked with itk.VectorImage and itk.Image[itk.Vector[t,d],d] types separately, but I’m hoping someone can clarify the best way to convert between the two.

In my experience so far it seems that the Python wrapping favors importing vector-valued data from outside sources into itk.VectorImage objects given their ability to accommodate itk.VariableLengthVectors of arbitrary length, as opposed to greatly increasing the wrapping coverage for itk.Vector. However, wrappings for ITK filter classes typically favor itk.Images with fixed-length itk.Vector pixel types, such as in the case of the itk.StrainImageFilter under discussion in the original thread. The ITK Software Guide also favors the itk.Image type with little discussion of itk.VectorImages. The itk.VectorImage documentation emphasizes that the formats differ in their memory organization, so they are not directly interchangeable. As expected, attempting to cast directly between an itk.Image and itk.VectorImage fails.

The brute force solution this problem is to allocate and iteratively fill a new object, but that seems poorly optimized. Is there a recommended method for moving vector data between an itk.Image and itk.VectorImage of the same size and vector length, both in c++ and Python?

Thank you!

Duplicator probably will not work for conversion. But Paste and RegionOfInterest might.

PasteImageFilter and RegionOfInterestImageFilter are not currently wrapped for itk.VectorImage to/from itk.Image[itk.Vector] types, we can add that wrapping if one of these would be the best route.

I noticed that itkImageToImageFilterA.wrap contains a basis for VectorImage <-> Vector transformation, I’m not sure if there is a class already inheriting from this that could provide conversion.

Ah, CastImageFilter. It is probably better than Paste or RoI filters.

1 Like

Perfect, cast_image_filter is already wrapped and ready to go. Thanks @dzenanz.