Thanks Brian,<div><br></div><div>I think I did not do enough research into the stipulations on using each type of deformable registration method. I&#39;ll be looking into the diffeomorphic demons method</div><div> To see if I can obtain more useable results.</div>
<div><br></div><div>Thanks again,</div><div><br></div><div>Tim<br><br>On Friday, January 3, 2014, brian avants  wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">hi tim <div><br></div><div>there are 2 significant issues with this question, neither of which have to do with code</div><div><br></div><div>1) demons deformation fields may not be invertible - this is why diffeomorphic demons was developed</div>


<div><br></div><div>2) your approach to estimating an inverse is only accurate if deformations are sub-pixel i.e. motion is less than 1 voxel</div><div><br></div><div>one method for estimating an inverse is illustrated here:</div>


<div>







<p>./ITKv4/Modules/Filtering/DisplacementField/test/itkInvertDisplacementFieldImageFilterTest.cxx</p></div></div><div class="gmail_extra"><br clear="all"><div><div><br></div>brian<br><div><br></div><div><br></div>

</div>
<br><br><div class="gmail_quote">On Thu, Jan 2, 2014 at 4:32 PM, Tim Bhatnagar <span dir="ltr">&lt;<a href="javascript:_e({}, &#39;cvml&#39;, &#39;tim.bhatnagar@gmail.com&#39;);" target="_blank">tim.bhatnagar@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><div><div>Hello all,<br><br></div>Would anyone have a WORKING c++/source file that successfully generates/acquires the inverse displacement field from a Demon&#39;s non-rigid registration field?<br><br></div>



Many users have been helping me in achieving this, though I&#39;m worried that I&#39;m losing some of the finer points in my code implementation.. this is what I have so far, and it compiles, but the program always crashes at the same point, after a negative index is created for my new field...<br>



<br>any help is much appreciated.. my c++ code is below:<br><br>#include &quot;itkInverseDisplacementFieldImageFilter.h&quot;<br>#include &quot;itkImageFileWriter.h&quot;<br>#include &quot;itkImageFileReader.h&quot;<br>#include &quot;itkFilterWatcher.h&quot;<br>



#include &quot;itkVectorScaleImageFilter.h&quot;<br>#include &quot;itkImage.h&quot;<br>#include &quot;itkArray.h&quot;<br><br>int main( int argc, char * argv[] )<br>{<br><br>  if( argc &lt; 4 )<br>    {<br>    std::cerr &lt;&lt; &quot;Missing Parameters &quot; &lt;&lt; std::endl;<br>



    std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0];<br>    std::cerr &lt;&lt; &quot;inputDemonsField subSampFactor outputInvertedField&quot; &lt;&lt; std::endl;<br>    return EXIT_FAILURE;<br>    }<br><br>  const     unsigned int Dimension = 3;<br>



  typedef   float VectorComponentType;<br><br>  typedef   itk::Vector&lt; VectorComponentType, Dimension &gt; VectorType;<br><br>  typedef itk::Image&lt; VectorType,  Dimension &gt; DisplacementFieldType;<br><br>  typedef itk::Array&lt; VectorType &gt; ArrayType;<br>



<br>  typedef itk::InverseDisplacementFieldImageFilter&lt;<br>    DisplacementFieldType,<br>    DisplacementFieldType<br>    &gt;  FilterType;<br><br>  FilterType::Pointer filter = FilterType::New();<br><br>  FilterWatcher watcher(filter);<br>



<br>  // Read a DisplacementField<br>  typedef itk::ImageFileReader&lt;  DisplacementFieldType  &gt; ReaderType;<br><br>  ReaderType::Pointer reader = ReaderType::New();<br><br>  reader-&gt;SetFileName( argv[1] );<br><br>



  reader-&gt;Update();<br><br><br>  // Obtaining an input displacement field<br>  DisplacementFieldType::Pointer field = reader-&gt;GetOutput();<br><br>  DisplacementFieldType::RegionType inputRegion;<br>  DisplacementFieldType::SizeType inputSize;<br>



  DisplacementFieldType::DirectionType inputDirection;<br>  DisplacementFieldType::PointType inputOrigin;<br>  DisplacementFieldType::SpacingType inputSpacing;<br><br>  inputRegion = field-&gt;GetLargestPossibleRegion();<br>



  inputSize = field-&gt;GetLargestPossibleRegion().GetSize();<br>  inputDirection =  field-&gt;GetDirection();<br>  inputOrigin =  field-&gt;GetOrigin();<br>  inputSpacing =  field-&gt;GetSpacing();<br>  inputRegion.SetIndex(field-&gt;GetLargestPossibleRegion().GetIndex());<br>



<br>  DisplacementFieldType::Pointer outField = DisplacementFieldType::New();<br><br> <br><br><br>   itk::ImageRegionIteratorWithIndex&lt; DisplacementFieldType &gt; it( field, inputRegion );<br><br>   filter-&gt;SetOutputSpacing( field-&gt;GetSpacing() );<br>



   filter-&gt;SetOutputOrigin( field-&gt;GetOrigin() );<br>   filter-&gt;SetSize( inputSize );<br><br>  filter-&gt;SetInput( field );<br>  filter-&gt;SetSubsamplingFactor( atof(argv[2]) );<br><br>  try<br>    {<br>    filter-&gt;UpdateLargestPossibleRegion();<br>



    }<br>  catch( itk::ExceptionObject &amp; excp )<br>    {<br>    std::cerr &lt;&lt; &quot;Exception thrown &quot; &lt;&lt; std::endl;<br>    std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>    }<br><br>  // Make template to ensure proper indexing of new def field<br>



<br>  DisplacementFieldType::Pointer outField = filter-&gt;GetOutput();<br>  DisplacementFieldType::RegionType outputRegion;<br><br>   outputRegion.SetIndex( inputRegion.GetIndex() );<br><br>  // Write an image for regression testing<br>



  typedef itk::ImageFileWriter&lt;  DisplacementFieldType  &gt; WriterType;<br><br>  WriterType::Pointer writer = WriterType::New();<br><br>  outField-&gt;Update();<br>  writer-&gt;SetInput (outField );<br>  writer-&gt;SetFileName( argv[3] );<br>



<br>  try<br>    {<br>    writer-&gt;Update();<br>    }<br>  catch( itk::ExceptionObject &amp; excp )<br>    {<br>    std::cerr &lt;&lt; &quot;Exception thrown by writer&quot; &lt;&lt; std::endl;<br>    std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>



    return EXIT_FAILURE;<br>    }<br><br><br><br><br>  // Now, test for loop invariant (acts as filter validation)<br>  // f^-1(f(p1) + p1 ) - f(p1)  = 0<br>  it.GoToBegin();<br>  while( !it.IsAtEnd() )<br>    {<br><br>    DisplacementFieldType::PointType p1;<br>



    field-&gt;TransformIndexToPhysicalPoint(it.GetIndex(), p1);<br><br>    DisplacementFieldType::PixelType fp1 = it.Get();<br><br>    DisplacementFieldType::PointType p2;<br>    p2[0] = p1[0] + fp1[0];<br>    p2[1] = p1[1] + fp1[1];<br>



    p2[2] = p1[2] + fp1[2];<br><br>    DisplacementFieldType::IndexType id2;<br>    outField-&gt;Transform</div>_____________________________________<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.php" target="_blank">http://www.kitware.com/products/protraining.php</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>
<br></blockquote></div><br></div>
</blockquote></div><br><br>-- <br>Tim Bhatnagar<br>PhD Candidate<br>Orthopaedic Injury Biomechanics Group<br>Department of Mechanical Engineering<br>University of British Columbia<br><br>Rm 5000 - 818 West 10th Ave.<br>Vancouver, BC<br>
Canada<br>V5Z 1M9<br><br>Ph: (604) 675-8845<br>Fax: (604) 675-8820<br>Web: <a href="http://oibg.mech.ubc.ca" target="_blank">oibg.mech.ubc.ca</a><br><br>