Hi all,<div><br></div><div>I have been using itk for quite some time, mainly the FEM package. I run FEM registration on 3D Volumes with around 100 iteration. As a result of the registration procedure, the warped image file and the multi component deformation field are stored.</div>
<div>When visualizing the warped image + deformation field in Paraview it appears to be correct.</div><div><br></div><div>The problem I am facing is the following:</div><div><br></div><div>I want to manually warp the moving image to obtain the registered image (moving + deformation field = registered image)</div>
<div>I am using the WarpImageFilter, more or less the same code that is used in the FEMRegistrationFilter. I am unable to reproduce the same result, it seems the image has been barely &#39;warped&#39; when visualizing the result. There is a big difference between the warped image obtained through the FEMRegistrationFilter and by manually warping it.</div>
<div><br></div><div>Is my assumption correct that the Deformation field returned from the FEMRegistrationFilter holds the total deformation and not only the deformation of the last iteration.</div><div><br></div><div>This is the code I am working with (it is not optimized)</div>
<div><br></div><div><br></div><div><div>#if defined(_MSC_VER)</div><div>#pragma warning ( disable : 4786 )</div><div>#endif</div><div><br></div><div>#include &quot;itkImageFileReader.h&quot; </div><div>#include &quot;itkImageFileWriter.h&quot; </div>
<div>#include &quot;itkMinimumMaximumImageFilter.h&quot;</div><div>#include &quot;itkShiftScaleImageFilter.h&quot;</div><div>#include &quot;itkImageRegionIterator.h&quot;</div><div><br></div><div><br></div><div>#include &quot;itkCastImageFilter.h&quot;</div>
<div>#include &quot;itkWarpImageFilter.h&quot;</div><div>#include &quot;itkLinearInterpolateImageFunction.h&quot;</div><div><br></div><div>#include &quot;itkSquaredDifferenceImageFilter.h&quot;</div><div>#include &quot;itkCheckerBoardImageFilter.h&quot;</div>
<div>#include &quot;itkTimeProbe.h&quot;       </div><div><br></div><div>#include &quot;itkImageRegionIteratorWithIndex.h&quot;</div><div>#include &quot;itkPointSet.h&quot;</div><div>#include &lt;fstream&gt;</div><div><br>
</div><div>#include &quot;itkCastImageFilter.h&quot;</div><div><br></div><div>int main( int argc, char *argv[] )</div><div>{</div><div>    if( argc &lt; 4 )</div><div>    {</div><div>        std::cerr &lt;&lt; &quot;Missing Parameters &quot; &lt;&lt; std::endl;</div>
<div>        std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0];</div><div>        std::cerr &lt;&lt; &quot; fixedImagefile movingImageFile deformField.vtk &quot;;</div><div>        std::cerr &lt;&lt; &quot; outputImageFile &quot; &lt;&lt; std::endl;</div>
<div>        return 1;</div><div>    }</div><div><br></div><div>    </div><div>    const unsigned int Dimension = 3;</div><div>    typedef float PixelType;</div><div><br></div><div><br></div><div>    typedef itk::Image&lt; PixelType, Dimension &gt;  FixedImageType;</div>
<div>    typedef itk::ImageFileReader&lt; FixedImageType &gt; FixedImageReaderType;</div><div>    FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New();</div><div>    fixedImageReader-&gt;SetFileName( argv[1] );</div>
<div><br></div><div>    </div><div>    typedef itk::Image&lt; PixelType, Dimension &gt;  MovingImageType;</div><div>    typedef itk::ImageFileReader&lt; MovingImageType &gt; MovingImageReaderType;</div><div>    MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();</div>
<div>    movingImageReader-&gt;SetFileName( argv[2] );</div><div><br></div><div>    typedef itk::Vector&lt; float, Dimension &gt;    VectorPixelType;</div><div>    typedef itk::Image&lt;  VectorPixelType, Dimension &gt; DeformationFieldType;</div>
<div><br></div><div>    typedef itk::ImageFileReader&lt; DeformationFieldType &gt;  FieldReaderType;</div><div>    FieldReaderType::Pointer fieldReader = FieldReaderType::New();</div><div><br></div><div>    fieldReader-&gt;SetFileName( argv[3] );</div>
<div><br></div><div>   </div><div>   try {</div><div><br></div><div>    fieldReader-&gt;Update();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>movingImageReader-&gt;Update();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>fixedImageReader-&gt;Update();</div>
<div>   }</div><div><br></div><div>   catch ( itk::ExceptionObject &amp; err ) </div><div>   {</div><div>    std::cerr &lt;&lt; &quot;ExceptionObject caught !&quot; &lt;&lt; std::endl; </div><div>    std::cerr &lt;&lt; err &lt;&lt; std::endl; </div>
<div>    return -1;</div><div>    } </div><div><br></div><div><br></div><div>    </div><div>    typedef itk::WarpImageFilter&lt;FixedImageType, MovingImageType,DeformationFieldType  &gt;     WarperType;</div><div>    WarperType::Pointer warper = WarperType::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef WarperType::CoordRepType WarperCoordRepType;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef itk::LinearInterpolateImageFunction&lt;MovingImageType, WarperCoordRepType  &gt;  InterpolatorType;</div>
<div><br></div><div>    InterpolatorType::Pointer interpolator = InterpolatorType::New();</div><div>    FixedImageType::Pointer fixedImage = fixedImageReader-&gt;GetOutput();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>FixedImageType::Pointer warpedImage;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>  warper-&gt;SetInput( movingImageReader-&gt;GetOutput() );</div><div>      warper-&gt;SetDeformationField( fieldReader-&gt;GetOutput() );</div>
<div>      warper-&gt;SetInterpolator( interpolator );</div><div>      warper-&gt;SetOutputOrigin( fixedImage-&gt;GetOrigin() );</div><div>      warper-&gt;SetOutputSpacing( fixedImage-&gt;GetSpacing() );</div><div>      warper-&gt;SetOutputDirection( fixedImage-&gt;GetDirection() );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>  MovingImageType::PixelType padValue = 0;</div><div>      warper-&gt;SetEdgePaddingValue( padValue );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div>     warper-&gt;Update();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> warpedImage = warper-&gt;GetOutput();</div><div><br></div><div>    /*typedef itk::ImageFileWriter&lt; MovingImageType &gt;  WriterType;</div>
<div>  </div><div>    WriterType::Pointer writer =  WriterType::New();</div><div>    writer-&gt;SetFileName( argv[4] );</div><div>    writer-&gt;SetInput( warper-&gt;GetOutput()   );</div><div>    writer-&gt;Update();*/</div>
<div><br></div><div><br></div><div><br></div><div>  typedef itk::MinimumMaximumImageFilter&lt;MovingImageType&gt; MinMaxFilterType;</div><div>  MinMaxFilterType::Pointer minMaxFilter = MinMaxFilterType::New();</div><div>  minMaxFilter-&gt;SetInput( warpedImage );</div>
<div>  minMaxFilter-&gt;Update();</div><div>  float min = minMaxFilter-&gt;GetMinimum();</div><div>  double shift = -1.0 * static_cast&lt;double&gt;( min );</div><div>  double scale = static_cast&lt;double&gt;( minMaxFilter-&gt;GetMaximum() );</div>
<div>  scale += shift;</div><div>  scale = 255.0 / scale;</div><div>  typedef itk::ShiftScaleImageFilter&lt;MovingImageType, MovingImageType&gt; FilterType;</div><div>  FilterType::Pointer filter = FilterType::New();</div>
<div>  filter-&gt;SetInput( warpedImage );</div><div>  filter-&gt;SetShift( shift );</div><div>  filter-&gt;SetScale( scale );</div><div>  filter-&gt;Update();</div><div><br></div><div><br></div><div>  typedef itk::Image&lt;PixelType,Dimension&gt;                    WriteImageType;</div>
<div>  typedef itk::CastImageFilter&lt;MovingImageType,WriteImageType&gt; CasterType1;</div><div>  CasterType1::Pointer caster1 = CasterType1::New();</div><div>  caster1-&gt;SetInput(filter-&gt;GetOutput());</div><div>  caster1-&gt;Update();</div>
<div>  typedef itk::ImageFileWriter&lt;WriteImageType&gt; WriterType;</div><div>  WriterType::Pointer writer = WriterType::New();</div><div>  writer-&gt;SetFileName(argv[4]);</div><div>  writer-&gt;SetInput(caster1-&gt;GetOutput() );</div>
<div>  writer-&gt;Write();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>    return 0;</div><div>}</div></div><div><br></div><div><br></div><div><br></div>