[ITK-users] Apply rigid transform by changing image information

Johnson, Hans J hans-johnson at uiowa.edu
Fri Feb 19 17:26:07 EST 2016


Emily,

Please review the following.
https://github.com/BRAINSia/BRAINSTools/blob/master/BRAINSCommonLib/itkResampleInPlaceImageFilter.h

This can do the translation and versor rotation parts of what you want, but currently requires isotropic 1mm scaling.  Hopefully you could modify (and contribute back) an improvement that also incorporates the anisotropic scaleing component.

Let me know if you want to work more closely on this.

Hans

--


From: Insight-users <insight-users-bounces at itk.org<mailto:insight-users-bounces at itk.org>> on behalf of "Hammond, Emily M" <emily-hammond at uiowa.edu<mailto:emily-hammond at uiowa.edu>>
Date: Friday, February 19, 2016 at 3:43 PM
To: Insight Users <insight-users at itk.org<mailto:insight-users at itk.org>>
Subject: [ITK-users] Apply rigid transform by changing image information

Hello,

Context: I am applying a rigid registration process to align two images. The transform allows for anisotropic scaling, a translation, and a versor rotation. I have perform the registration and checked my results by loading the resulting transform into 3D Slicer and applying it to the moving image.

Problem: I am trying to apply the transform to the moving image without resampling, so just changing the image information. Essentially, I want to perform the equivalent of “Harden Transform” in Slicer. I have been following this example (http://www.itk.org/Doxygen/html/Examples_2RegistrationITKv3_2ChangeInformationImageFilter_8cxx-example.html#_a3) to change my image information.

To apply the scaling, I simply multiplied the spacing by the corresponding scale factor. For translation, I added the translation to the origin. For applying the rotation, the example shows to multiply the image direction matrix by the versor rotation matrix. The new spacing, origin, and direction matrix are then input into the new change information image filter.

I have done this, however, when using Slicer to load in the final image, the transform does not show to have been applied correctly. I have been saving my images as MetaImage files (.mhd) so the image information is saved in the header file. Can anyone please give me some advice on how to perform this task appropriately?

Here is my code:

// get image properties
            ImageType::PointType origin = image->GetOrigin();
            ImageType::SpacingType spacing = image->GetSpacing();
            ImageType::DirectionType direction = image->GetDirection();

            // get transform parameters
            TransformType::TranslationType translation = transform->GetTranslation();
            TransformType::ScaleVectorType scale = transform->GetScale();
            TransformType::VersorType versor = transform->GetVersor();

            // apply scaling and translation parameters to image
            for( int i = 0; i < 3; i++ )
            {
                  spacing[i] *= scale[i];
                  origin[i] += translation[i];
            }

            // apply rotation to image
            ImageType::DirectionType newDirection = direction*versor.GetMatrix();

            // allocate hardening filter
            typedef itk::ChangeInformationImageFilter< ImageType > HardenTransformFilter;
            HardenTransformFilter::Pointer harden = HardenTransformFilter::New();
            harden->SetInput( image );

            // set new parameters
            harden->SetOutputSpacing( spacing );
            harden->SetOutputOrigin( origin );
            harden->SetOutputDirection( newDirection );

            // turn change flags on
            harden->ChangeSpacingOn();
            harden->ChangeOriginOn();
            harden->ChangeDirectionOn();

            harden->Update();

Thanks in advance!
Emily Hammond
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20160219/522c7046/attachment.html>


More information about the Insight-users mailing list