Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TransformixFilter does not process non-float pixel type images #322

Open
thewtex opened this issue Oct 16, 2020 · 4 comments
Open

TransformixFilter does not process non-float pixel type images #322

thewtex opened this issue Oct 16, 2020 · 4 comments

Comments

@thewtex
Copy link
Contributor

thewtex commented Oct 16, 2020

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

return dynamic_cast< MovingImageType * >(
this->GetMovingImageContainer()->ElementAt( idx ).GetPointer() );

and no moving image will be detected here:

if( ( this->GetNumberOfMovingImageFileNames() > 0 )
|| ( this->GetMovingImage() != nullptr ) )

and no transformation is applied here:

errorCode = this->GetElastixBase()->ApplyTransform();

@thewtex
Copy link
Contributor Author

thewtex commented Oct 16, 2020

A simple check for this is changing the PixelType from float to double in the test added in: #323

@thewtex
Copy link
Contributor Author

thewtex commented Oct 16, 2020

@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.

@dzenanz
Copy link
Contributor

dzenanz commented Nov 30, 2020

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

@N-Dekker
Copy link
Member

Current status:

  1. The pixel type of the input image should correspond with the template argument of TransformixFilter<TMovingImage>:
    template <typename TMovingImage>
    class ITK_TEMPLATE_EXPORT TransformixFilter : public ImageSource<TMovingImage>
    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 added a commit that referenced this issue May 7, 2023
Both ElastixRegistrationMethod and TransformixFilter now convert their input images to the internal pixel type, specified by elastix/transformix parameters, "FixedInternalImagePixelType" and "MovingInternalImagePixelType" (which are "float" by default).

The conversion is performed internally by `itk::CastImageFilter`. It is only performed when the pixel type of an input image is actually different from the specified internal pixel type.

The converted images are cached in memory, to avoid repeating the very same (potentially expensive) image conversion multiple times.

GoogleTest unit tests are included.

Related to issue #322 "TransformixFilter does not process non-float pixel type images"
N-Dekker added a commit that referenced this issue May 8, 2023
Both ElastixRegistrationMethod and TransformixFilter now convert their input images to the internal pixel type, specified by elastix/transformix parameters, "FixedInternalImagePixelType" and "MovingInternalImagePixelType" (which are "float" by default).

The conversion is performed internally by `itk::CastImageFilter`. It is only performed when the pixel type of an input image is actually different from the specified internal pixel type.

The converted images are cached in memory, to avoid repeating the very same (potentially expensive) image conversion multiple times.

GoogleTest unit tests are included.

Related to issue #322 "TransformixFilter does not process non-float pixel type images"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants