Hi Moti,<br><br>Did you set the Center of rotation<br> in the Affine Transform ?<br><br>---<br><br>and yet, a better solution,<br><br>you could use directly ICP implementation in ITK,<br>and fee it with points that have been harvested<br>
using the:<br><br>                   IndexToPhysicalPoint() <br><br>method of the itkImages.<br><br>In that way you will be sure of using points<br>that are really in the same coordinate system<br>as the images.<br><br>It is quite likely that the point coordinates <br>
that you used as input for the VTK ICP <br>algorithm, do not map to the locations<br>that you are expecting in the ITK images.<br><br><br>Also, keep in mind that VTK and ITK <br>have a reflection in the coordinates of<br>
the Y axis... this may also be playing<br>here...<br><br><br><br>    Regards,<br><br><br>         Luis<br><br><br>------------------------------------------------------<br><div class="gmail_quote">On Tue, Sep 28, 2010 at 10:09 AM, Moti Freiman <span dir="ltr">&lt;<a href="mailto:freiman@cs.huji.ac.il">freiman@cs.huji.ac.il</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi,<br>
Thanks for the fast answer.<br>
I added the direction code as you can see below. Problem still not solved yet.<br>
I think that I handle the origin, and orientation well now.<br>
Any other suggestion?<br>
Thanks,<br>
Moti<br>
<br>
<br>
<br>
resampler-&gt;SetOutputSpacing( fixedImage-&gt;GetSpacing() );<br>
<div class="im">resampler-&gt;SetSize(  fixedImage-&gt;GetLargestPossibleRegion().GetSize() );<br>
resampler-&gt;SetOutputOrigin( fixedImage-&gt;GetOrigin());<br>
</div>resampler-&gt;SetOutputDirection(movingImage-&gt;GetDirection());<br>
<div><div></div><div class="h5"><br>
On Tue, Sep 28, 2010 at 9:27 AM, Vincent Magnotta<br>
&lt;<a href="mailto:vincent-magnotta@uiowa.edu">vincent-magnotta@uiowa.edu</a>&gt; wrote:<br>
&gt; Moti,<br>
&gt;<br>
&gt; The number one reason for this type of error is not correctly handling the<br>
&gt; origin and orientation in the images. Just quickly looking at the code, you<br>
&gt; should also set the direction of the output image.<br>
&gt;<br>
&gt; Vince<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On 9/28/10 8:22 AM, &quot;Moti Freiman&quot; &lt;<a href="mailto:freiman@cs.huji.ac.il">freiman@cs.huji.ac.il</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; Hi All,<br>
&gt;&gt; I have an affine transformation that I produced using the ICP<br>
&gt;&gt; algorithm as implemented in VTK.<br>
&gt;&gt; Now I want to transfer the original moving image to the coordinates of<br>
&gt;&gt; the fixed one.<br>
&gt;&gt;<br>
&gt;&gt; I wrote a simple ITK based application, that read the images and the<br>
&gt;&gt; transform, and apply the trasnform to the moving image.<br>
&gt;&gt; However, It seems that I got an empty image (with default value),<br>
&gt;&gt; although the transformation of the surfaces using VTK works well.<br>
&gt;&gt; I tested the transformation by transforming several points using both<br>
&gt;&gt; ITK transform and the VTK transform, and the points transffered<br>
&gt;&gt; indentically.<br>
&gt;&gt; Does any one has an idea, some expirience with that problem.<br>
&gt;&gt;<br>
&gt;&gt; The code is attached bellow<br>
&gt;&gt; Best,<br>
&gt;&gt; Moti<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --------------------------------- ITK based affine image<br>
&gt;&gt; transformation -------------------------------------------<br>
&gt;&gt;<br>
&gt;&gt;         // declare the affine transfrom<br>
&gt;&gt; typedef itk::AffineTransform &lt;double,Dimension&gt; itkAffineTransformType;<br>
&gt;&gt; itkAffineTransformType::Pointer trans = itkAffineTransformType::New();<br>
&gt;&gt; trans-&gt;SetIdentity();<br>
&gt;&gt;<br>
&gt;&gt; // read transform params from file<br>
&gt;&gt; std::fstream transFile;<br>
&gt;&gt; transFile.open (inputReferenceToPatientTransformFileName.c_str(),<br>
&gt;&gt; std::ios::in);<br>
&gt;&gt; int numOfElements = Dimension*Dimension;<br>
&gt;&gt;<br>
&gt;&gt; itkAffineTransformType::MatrixType matrix;<br>
&gt;&gt; itkTranslationTransformType::OutputVectorType translation;<br>
&gt;&gt;<br>
&gt;&gt; for (int i=0;i&lt;Dimension;++i)<br>
&gt;&gt; {<br>
&gt;&gt; for (int j=0;j&lt;Dimension;++j)<br>
&gt;&gt; {<br>
&gt;&gt; transFile &gt;&gt; matrix(i,j);<br>
&gt;&gt; }<br>
&gt;&gt; }<br>
&gt;&gt; dout &lt;&lt; &quot;end to read matrix&quot; &lt;&lt; std::endl;<br>
&gt;&gt; for (int i=0;i&lt;Dimension;++i)<br>
&gt;&gt; {<br>
&gt;&gt; transFile &gt;&gt; translation[i];<br>
&gt;&gt; translation[i]  = -translation[i];<br>
&gt;&gt;<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; transFile.close();<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; trans-&gt;SetMatrix( matrix );<br>
&gt;&gt; trans-&gt;SetOffset(translation);<br>
&gt;&gt;<br>
&gt;&gt;         // transform some point for testing purpose<br>
&gt;&gt; dout &lt;&lt; trans &lt;&lt; std::endl;<br>
&gt;&gt; itkAffineTransformType::InputPointType inPoint;<br>
&gt;&gt; inPoint[0] = 1;  inPoint[1] = 1; inPoint[2] = 1;<br>
&gt;&gt; itkAffineTransformType::OutputPointType outPoint =<br>
&gt;&gt; trans-&gt;TransformPoint(inPoint);<br>
&gt;&gt; dout &lt;&lt; outPoint[0] &lt;&lt; &quot;, &quot; &lt;&lt; outPoint[1] &lt;&lt; &quot;, &quot; &lt;&lt; outPoint[2] &lt;&lt;<br>
&gt;&gt; std::endl;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;         // resample the moving image<br>
&gt;&gt;         typedef itk::ResampleImageFilter&lt; LabelsImageType,<br>
&gt;&gt; LabelsImageType &gt; ResampleFilterType;<br>
&gt;&gt; ResampleFilterType::Pointer resampler = ResampleFilterType::New();<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; typedef itk::NearestNeighborInterpolateImageFunction&lt;LabelsImageType,<br>
&gt;&gt; double&gt; InterpolatorType;<br>
&gt;&gt; InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>
&gt;&gt; resampler-&gt;SetInterpolator( interpolator );<br>
&gt;&gt; resampler-&gt;SetTransform( trans );<br>
&gt;&gt; resampler-&gt;SetDefaultPixelValue(100);<br>
&gt;&gt; resampler-&gt;SetOutputSpacing( fixedImage );<br>
&gt;&gt; resampler-&gt;SetSize( fixedImage-&gt;GetLargestPossibleRegion().GetSize() );<br>
&gt;&gt; resampler-&gt;SetOutputOrigin( fixedImage-&gt;GetOrigin());<br>
&gt;&gt; resampler-&gt;SetInput (movingImage);<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; resampler-&gt;Update();<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; ------------------------------------------ end of code<br>
&gt;&gt; --------------------------------------------------------------<br>
&gt;<br>
&gt; ----------------------<br>
&gt; Associate Professor<br>
&gt; Department of Radiology<br>
&gt; 0453-D JCP<br>
&gt; 200 Hawkins Drive<br>
&gt; Iowa City, IA 52242<br>
&gt; E-mail: <a href="mailto:vincent-magnotta@uiowa.edu">vincent-magnotta@uiowa.edu</a><br>
&gt; Phone: 319-356-8255 Fax: 319-353-6275<br>
&gt; Website: <a href="http://www.radiology.uiowa.edu" target="_blank">http://www.radiology.uiowa.edu</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
</div></div><div class="im">--<br>
__<br>
Moti Freiman, Postdoctoral Associate,<br>
Harvard Medical School.<br>
Research Fellow,<br>
Computational Radiology Laboratory.<br>
Dept. of Radiology, Children&#39;s hospital,<br>
300 Longwood Ave. Boston, MA 02115.<br>
<br>
</div>Lab website: <a href="http://crl.med.harvard.edu" target="_blank">http://crl.med.harvard.edu</a><br>
<div><div></div><div class="h5">_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</div></div></blockquote></div><br>