<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta content="text/html; charset=utf-8">
</head>
<body style="word-wrap:break-word; color:rgb(0,0,0); font-size:14px; font-family:Calibri,sans-serif">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline}
a:visited, span.MsoHyperlinkFollowed
        {color:#954F72;
        text-decoration:underline}
.MsoChpDefault
        {}
@page WordSection1
        {margin:72.0pt 72.0pt 72.0pt 72.0pt}
div.WordSection1
        {}
-->
</style>
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Probably the</span><span lang="HU"> si</span><span lang="EN-US">mplest method is the following:</span></p>
<p class="MsoNormal"><span lang="EN-US">* create a homogeneous transformation matrix that transforms between image coordinate indices and physical coordinates (computed from origin, spacing, and axis directions)</span></p>
<p class="MsoNormal"><span lang="EN-US">* multiply it with the matrix of the transformation applied to the image</span></p>
<p class="MsoNormal"><span lang="EN-US">* compute spacing, origin, and directions from the resulting matrix and set it in the image</span><span lang="EN-US"></span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span lang="EN-US">Example of computing origin, scaling, directions from transformation matrix:</span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLVolumeNode.cxx#L420">https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLVolumeNode.cxx#L420</a></span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal">How <span lang="EN-US">to create homogeneous transformation matrix from various ITK transforms:</span></p>
<p class="MsoNormal"><a href="https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkITKTransformConverter.h#L135">https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkITKTransformConverter.h#L135</a></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Andras</p>
<p class="MsoNormal"><span style="font-size:12.0pt; font-family:"Times New Roman",serif"> </span></p>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="border:none; padding:0cm"><b>From: </b><a href="mailto:hans-johnson@uiowa.edu">Johnson, Hans J</a><br>
<b>Sent: </b>February 19, 2016 17:59<br>
<b>To: </b><a href="mailto:emily-hammond@uiowa.edu">Hammond, Emily M</a>; <a href="mailto:insight-users@itk.org">
Insight Users</a><br>
<b>Subject: </b>Re: [ITK] [ITK-users] Apply rigid transform by changing image information</p>
</div>
<p class="MsoNormal"><span style="font-size:12.0pt; font-family:"Times New Roman",serif"> </span></p>
</div>
<div>
<div>
<div>
<div>Emily,</div>
<div><br>
</div>
<div>Please review the following.</div>
<div><a href="https://github.com/BRAINSia/BRAINSTools/blob/master/BRAINSCommonLib/itkResampleInPlaceImageFilter.h">https://github.com/BRAINSia/BRAINSTools/blob/master/BRAINSCommonLib/itkResampleInPlaceImageFilter.h</a></div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>Let me know if you want to work more closely on this.</div>
<div><br>
</div>
<div>Hans</div>
<div><br>
</div>
<div>
<div id="MAC_OUTLOOK_SIGNATURE">
<div>
<div>-- </div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</div>
<div><br>
</div>
<span id="OLK_SRC_BODY_SECTION">
<div style="font-family:Calibri; font-size:12pt; text-align:left; color:black; border-bottom:medium none; border-left:medium none; padding-bottom:0in; padding-left:0in; padding-right:0in; border-top:#b5c4df 1pt solid; border-right:medium none; padding-top:3pt">
<span style="font-weight:bold">From: </span>Insight-users <<a href="mailto:insight-users-bounces@itk.org">insight-users-bounces@itk.org</a>> on behalf of "Hammond, Emily M" <<a href="mailto:emily-hammond@uiowa.edu">emily-hammond@uiowa.edu</a>><br>
<span style="font-weight:bold">Date: </span>Friday, February 19, 2016 at 3:43 PM<br>
<span style="font-weight:bold">To: </span>Insight Users <<a href="mailto:insight-users@itk.org">insight-users@itk.org</a>><br>
<span style="font-weight:bold">Subject: </span>[ITK-users] Apply rigid transform by changing image information<br>
</div>
<div><br>
</div>
<div>
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif"}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline}
span.EmailStyle17
        {font-family:"Calibri","sans-serif";
        color:windowtext}
.MsoChpDefault
        {font-family:"Calibri","sans-serif"}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.WordSection1
        {}
-->
</style>
<div lang="EN-US">
<div class="WordSection1">
<p class="MsoNormal">Hello,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">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.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">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
 (<a href="http://www.itk.org/Doxygen/html/Examples_2RegistrationITKv3_2ChangeInformationImageFilter_8cxx-example.html#_a3">http://www.itk.org/Doxygen/html/Examples_2RegistrationITKv3_2ChangeInformationImageFilter_8cxx-example.html#_a3</a>) to change my image
 information.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">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.
</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">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?</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Here is my code:</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="margin-left:.5in; text-indent:.5in; text-autospace:none">
<span style="font-size:10pt; font-family:'Courier New'; color:green">// get image properties</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            ImageType::PointType origin = image->GetOrigin();</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            ImageType::SpacingType spacing = image->GetSpacing();</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            ImageType::DirectionType direction = image->GetDirection();</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'"> </span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">           
<span style="color:green">// get transform parameters</span></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            TransformType::TranslationType translation = transform->GetTranslation();</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            TransformType::ScaleVectorType scale = transform->GetScale();</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            TransformType::VersorType versor = transform->GetVersor();</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'"> </span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">           
<span style="color:green">// apply scaling and translation parameters to image</span></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">           
<span style="color:blue">for</span>( <span style="color:blue">int</span> i = 0; i < 3; i++ )</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            {</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">                  spacing[i] *= scale[i];</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">                  origin[i] += translation[i];</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            }</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'"> </span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">           
<span style="color:green">// apply rotation to image</span></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            ImageType::DirectionType newDirection = direction*versor.GetMatrix();</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'"> </span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">           
<span style="color:green">// allocate hardening filter</span></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">           
<span style="color:blue">typedef</span> itk::ChangeInformationImageFilter< ImageType > HardenTransformFilter;</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            HardenTransformFilter::Pointer harden = HardenTransformFilter::New();</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            harden->SetInput( image );</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'"> </span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">           
<span style="color:green">// set new parameters</span></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            harden->SetOutputSpacing( spacing );</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            harden->SetOutputOrigin( origin );</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            harden->SetOutputDirection( newDirection );</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'"> </span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">           
<span style="color:green">// turn change flags on</span></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            harden->ChangeSpacingOn();</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            harden->ChangeOriginOn();</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'">            harden->ChangeDirectionOn();</span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10pt; font-family:'Courier New'"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt; font-family:'Courier New'">            harden->Update();</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Thanks in advance!<br>
Emily Hammond</p>
</div>
</div>
</div>
</span></div>
</body>
</html>