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"><<a href="mailto:freiman@cs.huji.ac.il">freiman@cs.huji.ac.il</a>></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->SetOutputSpacing( fixedImage->GetSpacing() );<br>
<div class="im">resampler->SetSize( fixedImage->GetLargestPossibleRegion().GetSize() );<br>
resampler->SetOutputOrigin( fixedImage->GetOrigin());<br>
</div>resampler->SetOutputDirection(movingImage->GetDirection());<br>
<div><div></div><div class="h5"><br>
On Tue, Sep 28, 2010 at 9:27 AM, Vincent Magnotta<br>
<<a href="mailto:vincent-magnotta@uiowa.edu">vincent-magnotta@uiowa.edu</a>> wrote:<br>
> Moti,<br>
><br>
> The number one reason for this type of error is not correctly handling the<br>
> origin and orientation in the images. Just quickly looking at the code, you<br>
> should also set the direction of the output image.<br>
><br>
> Vince<br>
><br>
><br>
><br>
> On 9/28/10 8:22 AM, "Moti Freiman" <<a href="mailto:freiman@cs.huji.ac.il">freiman@cs.huji.ac.il</a>> wrote:<br>
><br>
>> Hi All,<br>
>> I have an affine transformation that I produced using the ICP<br>
>> algorithm as implemented in VTK.<br>
>> Now I want to transfer the original moving image to the coordinates of<br>
>> the fixed one.<br>
>><br>
>> I wrote a simple ITK based application, that read the images and the<br>
>> transform, and apply the trasnform to the moving image.<br>
>> However, It seems that I got an empty image (with default value),<br>
>> although the transformation of the surfaces using VTK works well.<br>
>> I tested the transformation by transforming several points using both<br>
>> ITK transform and the VTK transform, and the points transffered<br>
>> indentically.<br>
>> Does any one has an idea, some expirience with that problem.<br>
>><br>
>> The code is attached bellow<br>
>> Best,<br>
>> Moti<br>
>><br>
>><br>
>><br>
>><br>
>> --------------------------------- ITK based affine image<br>
>> transformation -------------------------------------------<br>
>><br>
>> // declare the affine transfrom<br>
>> typedef itk::AffineTransform <double,Dimension> itkAffineTransformType;<br>
>> itkAffineTransformType::Pointer trans = itkAffineTransformType::New();<br>
>> trans->SetIdentity();<br>
>><br>
>> // read transform params from file<br>
>> std::fstream transFile;<br>
>> transFile.open (inputReferenceToPatientTransformFileName.c_str(),<br>
>> std::ios::in);<br>
>> int numOfElements = Dimension*Dimension;<br>
>><br>
>> itkAffineTransformType::MatrixType matrix;<br>
>> itkTranslationTransformType::OutputVectorType translation;<br>
>><br>
>> for (int i=0;i<Dimension;++i)<br>
>> {<br>
>> for (int j=0;j<Dimension;++j)<br>
>> {<br>
>> transFile >> matrix(i,j);<br>
>> }<br>
>> }<br>
>> dout << "end to read matrix" << std::endl;<br>
>> for (int i=0;i<Dimension;++i)<br>
>> {<br>
>> transFile >> translation[i];<br>
>> translation[i] = -translation[i];<br>
>><br>
>> }<br>
>><br>
>> transFile.close();<br>
>><br>
>><br>
>><br>
>> trans->SetMatrix( matrix );<br>
>> trans->SetOffset(translation);<br>
>><br>
>> // transform some point for testing purpose<br>
>> dout << trans << std::endl;<br>
>> itkAffineTransformType::InputPointType inPoint;<br>
>> inPoint[0] = 1; inPoint[1] = 1; inPoint[2] = 1;<br>
>> itkAffineTransformType::OutputPointType outPoint =<br>
>> trans->TransformPoint(inPoint);<br>
>> dout << outPoint[0] << ", " << outPoint[1] << ", " << outPoint[2] <<<br>
>> std::endl;<br>
>><br>
>><br>
>> // resample the moving image<br>
>> typedef itk::ResampleImageFilter< LabelsImageType,<br>
>> LabelsImageType > ResampleFilterType;<br>
>> ResampleFilterType::Pointer resampler = ResampleFilterType::New();<br>
>><br>
>><br>
>><br>
>> typedef itk::NearestNeighborInterpolateImageFunction<LabelsImageType,<br>
>> double> InterpolatorType;<br>
>> InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>
>> resampler->SetInterpolator( interpolator );<br>
>> resampler->SetTransform( trans );<br>
>> resampler->SetDefaultPixelValue(100);<br>
>> resampler->SetOutputSpacing( fixedImage );<br>
>> resampler->SetSize( fixedImage->GetLargestPossibleRegion().GetSize() );<br>
>> resampler->SetOutputOrigin( fixedImage->GetOrigin());<br>
>> resampler->SetInput (movingImage);<br>
>><br>
>><br>
>> resampler->Update();<br>
>><br>
>><br>
>> ------------------------------------------ end of code<br>
>> --------------------------------------------------------------<br>
><br>
> ----------------------<br>
> Associate Professor<br>
> Department of Radiology<br>
> 0453-D JCP<br>
> 200 Hawkins Drive<br>
> Iowa City, IA 52242<br>
> E-mail: <a href="mailto:vincent-magnotta@uiowa.edu">vincent-magnotta@uiowa.edu</a><br>
> Phone: 319-356-8255 Fax: 319-353-6275<br>
> Website: <a href="http://www.radiology.uiowa.edu" target="_blank">http://www.radiology.uiowa.edu</a><br>
><br>
><br>
><br>
><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'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>