elastix icon indicating copy to clipboard operation
elastix copied to clipboard

TransformixFilter does not process non-float pixel type images

Open thewtex opened this issue 3 years ago • 4 comments

When itk::TransformixFilter is templated with a TMovingImage that does not match the internal ElastixTemplate TMovingImage, this dynamic_cast will fail:

https://github.com/SuperElastix/elastix/blob/a187f9af5d11abff558faad1aaa4605e8c15bcce/Core/Kernel/elxElastixTemplate.hxx#L100-L101

and no moving image will be detected here:

https://github.com/SuperElastix/elastix/blob/a187f9af5d11abff558faad1aaa4605e8c15bcce/Core/Kernel/elxElastixTemplate.hxx#L387-L388

and no transformation is applied here:

https://github.com/SuperElastix/elastix/blob/a187f9af5d11abff558faad1aaa4605e8c15bcce/Core/Kernel/elxTransformixMain.cxx#L145

thewtex avatar Oct 16 '20 15:10 thewtex

A simple check for this is changing the PixelType from float to double in the test added in: https://github.com/SuperElastix/elastix/pull/323

thewtex avatar Oct 16 '20 15:10 thewtex

@N-Dekker @mstaring @stefanklein is it possible to take a look at this? I think a cast of the type is intended and required somewhere, which I do not know where that should be.

thewtex avatar Oct 16 '20 15:10 thewtex

I was unaware of this as I was trying to use transformix to deform an atlas (uchar image).

dzenanz avatar Nov 30 '20 16:11 dzenanz

Current status:

  1. The pixel type of the input image should correspond with the template argument of TransformixFilter<TMovingImage>: https://github.com/SuperElastix/elastix/blob/d8e9e1b5bcd1184ca9d3b343e61ccc85857ce407/Core/Main/itkTransformixFilter.h#L58-L59 When using Python + ITKElastix, the image type may be specified in square brackets:
ImageType = itk.Image[itk.F, 2]
transformix_filter = itk.TransformixFilter[ImageType].New()
  1. The pixel type of the images may also need to be specified as parameter, to be included with the parameter map, to be added to the parameter object. In Python, something like the following (untested code):
parameter_map = 
{
  "FixedInternalImagePixelType": ("float"),
  "MovingInternalImagePixelType": ("float")
   ... [other parameters here] ...
}

parameter_object = itk.ParameterObject.New()
parameter_object.AddParameterMap(parameter_map)
transformix_filter.SetMovingImage(moving_image)
transformix_filter.SetTransformParameterObject(parameter_object)

  1. The pixel type must be included during CMake configuration of elastix (ELASTIX_IMAGE_2D_PIXEL_TYPES, ELASTIX_IMAGE_3D_PIXEL_TYPES, etc)

That's it for now! Even though it may be somewhat inconvenient, I think it works well.

N-Dekker avatar Apr 24 '23 21:04 N-Dekker