[ITK-users] [ITK] Apply rigid transform by changing image information
Andras Lasso
lasso at queensu.ca
Sat Feb 20 10:52:38 EST 2016
Probably the simplest method is the following:
* create a homogeneous transformation matrix that transforms between image coordinate indices and physical coordinates (computed from origin, spacing, and axis directions)
* multiply it with the matrix of the transformation applied to the image
* compute spacing, origin, and directions from the resulting matrix and set it in the image
Example of computing origin, scaling, directions from transformation matrix:
https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLVolumeNode.cxx#L420
How to create homogeneous transformation matrix from various ITK transforms:
https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkITKTransformConverter.h#L135
Andras
From: Johnson, Hans J<mailto:hans-johnson at uiowa.edu>
Sent: February 19, 2016 17:59
To: Hammond, Emily M<mailto:emily-hammond at uiowa.edu>; Insight Users<mailto:insight-users at itk.org>
Subject: Re: [ITK] [ITK-users] Apply rigid transform by changing image information
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/20160220/05f26a75/attachment.html>
More information about the Insight-users
mailing list