Hi All ;)<div><br></div><div>I  have a question.</div><div>I am trying to extract position of landmarks after TPS transformation.</div><div>I can&#39;t receive position of points after transformation.</div><div>I don&#39;t know what&#39;s wrong with this code ?</div>
<div>Could anyone look at this code ?</div><div>I would appreciate for any help please.</div><div>I need to receive points after TPS registration.</div><div><br></div><div>Here is my code :</div><div><br></div><div><br></div>
<div><br></div><div><div>#include &quot;itkImageRegistrationMethod.h&quot;</div><div>#include &quot;itkMattesMutualInformationImageToImageMetric.h&quot;</div><div>#include &quot;itkLinearInterpolateImageFunction.h&quot;</div>
<div>#include &quot;itkOrientedImage.h&quot;</div><div>#include &quot;itkTimeProbesCollectorBase.h&quot;</div><div>#include &quot;itkImage.h&quot;</div><div>#include &quot;itkVector.h&quot;</div><div>#include &quot;itkResampleImageFilter.h&quot;</div>
<div>#include &quot;itkLandmarkBasedTransformInitializer.h&quot;</div><div>#include &quot;itkRigid2DTransform.h&quot;</div><div>#include &quot;itkBSplineDeformableTransform.h&quot;</div><div>#include &quot;itkCenteredTransformInitializer.h&quot;</div>
<div>#include &quot;itkVersorRigid3DTransform.h&quot;</div><div>#include &quot;itkAffineTransform.h&quot;</div><div>#include &quot;itkBSplineDeformableTransform.h&quot;</div><div>#include &quot;itkRegularStepGradientDescentOptimizer.h&quot;</div>
<div>#include &quot;itkBSplineResampleImageFunction.h&quot;</div><div>#include &quot;itkBSplineDecompositionImageFilter.h&quot;</div><div>#include &quot;itkResampleImageFilter.h&quot;</div><div>#include &quot;itkCastImageFilter.h&quot;</div>
<div>#include &quot;itkSquaredDifferenceImageFilter.h&quot;</div><div>#include &quot;itkTransformFileReader.h&quot;</div><div>#include &quot;itkCommand.h&quot;</div><div>#include &quot;itkLinearInterpolateImageFunction.h&quot;</div>
<div>#include &quot;itkThinPlateSplineKernelTransform.h&quot;</div><div>#include &quot;itkVolumeSplineKernelTransform.h&quot;</div><div>#include &quot;itkElasticBodySplineKernelTransform.h&quot;</div><div>#include &quot;itkPoint.h&quot;</div>
<div>#include &quot;itkPointSet.h&quot;</div><div>#include &quot;itkTransformFileWriter.h&quot;</div><div><br></div><div><br></div><div><br></div><div>class CommandIterationUpdate : public itk::Command </div><div>{</div><div>
public:</div><div>  typedef  CommandIterationUpdate   Self;</div><div>  typedef  itk::Command             Superclass;</div><div>  typedef itk::SmartPointer&lt;Self&gt;   Pointer;</div><div>  itkNewMacro( Self );</div><div>
protected:</div><div>  CommandIterationUpdate() {};</div><div>public:</div><div>  typedef itk::RegularStepGradientDescentOptimizer  OptimizerType;</div><div>  typedef   const OptimizerType *                   OptimizerPointer;</div>
<div><br></div><div>  void Execute(itk::Object *caller, const itk::EventObject &amp; event)</div><div>    {</div><div>    Execute( (const itk::Object *)caller, event);</div><div>    }</div><div><br></div><div>  void Execute(const itk::Object * object, const itk::EventObject &amp; event)</div>
<div>    {</div><div>    OptimizerPointer optimizer = </div><div>      dynamic_cast&lt; OptimizerPointer &gt;( object );</div><div>    if( !(itk::IterationEvent().CheckEvent( &amp;event )) )</div><div>      {</div><div>      return;</div>
<div>      }</div><div>    std::cout &lt;&lt; optimizer-&gt;GetCurrentIteration() &lt;&lt; &quot;   &quot;;</div><div>    std::cout &lt;&lt; optimizer-&gt;GetValue() &lt;&lt; &quot;   &quot;;</div><div>    std::cout &lt;&lt; std::endl;</div>
<div>    }</div><div>};</div><div><br></div><div><br></div><div>using namespace std;</div><div><br></div><div><br></div><div>int main(int argc, char* argv[])</div><div>{</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double tab[30] = </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> // Tracker</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>-81.29,-31.07,<span class="Apple-tab-span" style="white-space:pre">        </span>-770.58, </div>
<div>    -83.11,<span class="Apple-tab-span" style="white-space:pre">        </span>-21.26,<span class="Apple-tab-span" style="white-space:pre">        </span>-822.64,</div><div>    -93.45,<span class="Apple-tab-span" style="white-space:pre">        </span>-32.44,<span class="Apple-tab-span" style="white-space:pre">        </span>-858.72,</div>
<div>    -68.08,<span class="Apple-tab-span" style="white-space:pre">        </span>-126.89,-813.07,</div><div>    -61.04,<span class="Apple-tab-span" style="white-space:pre">        </span>75.74,<span class="Apple-tab-span" style="white-space:pre">        </span>-808.36,</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span> // Image</div><div>    140.6,<span class="Apple-tab-span" style="white-space:pre">        </span>230.7,<span class="Apple-tab-span" style="white-space:pre">        </span>-30.5,</div>
<div>    140.2,<span class="Apple-tab-span" style="white-space:pre">        </span>231.7,<span class="Apple-tab-span" style="white-space:pre">        </span>-71.1,</div><div>    144.8,<span class="Apple-tab-span" style="white-space:pre">        </span>235.9,<span class="Apple-tab-span" style="white-space:pre">        </span>-116.1,</div>
<div>    45.8,<span class="Apple-tab-span" style="white-space:pre">        </span>220.2,<span class="Apple-tab-span" style="white-space:pre">        </span>-66.7,</div><div>    231.6,<span class="Apple-tab-span" style="white-space:pre">        </span>211.3,<span class="Apple-tab-span" style="white-space:pre">        </span>-66.1</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>};</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>
<br></div><div>  const     unsigned int   Dimension = 3;</div><div>  typedef   unsigned char  PixelType;</div><div>  typedef   double CoordinateRepType;</div><div>  typedef   itk::ThinPlateSplineKernelTransform&lt; CoordinateRepType,Dimension&gt;     TPSTransformType;</div>
<div>  typedef   itk::Point&lt; CoordinateRepType,Dimension &gt;  PointType;</div><div>  typedef   std::vector&lt; PointType &gt;                   PointArrayType;</div><div>  typedef   TPSTransformType::PointSetType      PointSetType;</div>
<div>  typedef   PointSetType::Pointer            PointSetPointer;</div><div>  typedef   PointSetType::PointIdentifier  PointIdType;</div><div><br></div><div><br></div><div>  // Landmarks correspondances may be associated with the SplineKernelTransforms</div>
<div>  // via Point Set containers. Let us define containers for the landmarks.</div><div>  PointSetType::Pointer sourceLandMarks = PointSetType::New();</div><div>  PointSetType::Pointer targetLandMarks = PointSetType::New();</div>
<div>  PointType trackerPoint;     PointType imagePoint;</div><div>  PointSetType::PointsContainer::Pointer sourceLandMarkContainer = </div><div>                                   sourceLandMarks-&gt;GetPoints();</div><div>
  PointSetType::PointsContainer::Pointer targetLandMarkContainer = </div><div>                                   targetLandMarks-&gt;GetPoints();</div><div> </div><div><br></div><div><br></div><div><br></div><div>  // 1 Landmark</div>
<div>  trackerPoint[0] = tab[0];</div><div>  trackerPoint[1] = tab[1];</div><div>  trackerPoint[2] = tab[2];</div><div>  imagePoint[0] = tab[15];</div><div>  imagePoint[1] = tab[16];</div><div>  imagePoint[2] = tab[17];</div>
<div>  sourceLandMarkContainer-&gt;InsertElement( 0,trackerPoint);</div><div>  targetLandMarkContainer-&gt;InsertElement(0,imagePoint);</div><div><br></div><div><br></div><div> </div><div>  // 2 Landmark</div><div>  trackerPoint[0] = tab[3];</div>
<div>  trackerPoint[1] = tab[4];</div><div>  trackerPoint[2] = tab[5];</div><div>  imagePoint[0] = tab[18];</div><div>  imagePoint[1] = tab[19];</div><div>  imagePoint[2] = tab[20];</div><div>  sourceLandMarkContainer-&gt;InsertElement(1,trackerPoint);</div>
<div>  targetLandMarkContainer-&gt;InsertElement(1,imagePoint);</div><div> </div><div>  // 3 Landmark</div><div>  trackerPoint[0] = tab[6];</div><div>  trackerPoint[1] = tab[7];</div><div>  trackerPoint[2] = tab[8];</div>
<div>  imagePoint[0] = tab[21];</div><div>  imagePoint[1] = tab[22];</div><div>  imagePoint[2] = tab[23];</div><div>  sourceLandMarkContainer-&gt;InsertElement( 2,trackerPoint);</div><div>  targetLandMarkContainer-&gt;InsertElement(2,imagePoint);</div>
<div> </div><div>  // 4 Landmark</div><div>  trackerPoint[0] = tab[9];</div><div>  trackerPoint[1] = tab[10];</div><div>  trackerPoint[2] = tab[11];</div><div>  imagePoint[0] = tab[24];</div><div>  imagePoint[1] = tab[25];</div>
<div>  imagePoint[2] = tab[26];</div><div>  sourceLandMarkContainer-&gt;InsertElement( 3,trackerPoint);</div><div>  targetLandMarkContainer-&gt;InsertElement(3,imagePoint);</div><div><br></div><div>  // 5 Landmark</div><div>
  trackerPoint[0] = tab[12];</div><div>  trackerPoint[1] = tab[13];</div><div>  trackerPoint[2] = tab[14];</div><div>  imagePoint[0] = tab[27];</div><div>  imagePoint[1] = tab[28];</div><div>  imagePoint[2] = tab[29];</div>
<div><br></div><div>  sourceLandMarkContainer-&gt;InsertElement(4,trackerPoint);</div><div>  targetLandMarkContainer-&gt;InsertElement(4,imagePoint);</div><div><br></div><div>  TPSTransformType::Pointer tps = TPSTransformType::New();</div>
<div>  tps-&gt;SetSourceLandmarks(sourceLandMarks);</div><div>  tps-&gt;SetTargetLandmarks(targetLandMarks);</div><div>  tps-&gt;ComputeWMatrix();</div><div>  tps-&gt;UpdateParameters();</div><div><br></div><div><br></div>
<div><br></div><div><br></div><div>    PointSetType::Pointer transformed_points = PointSetType::New();</div><div>  PointSetType::PointsContainer::Pointer transformed_points_container = transformed_points-&gt;GetPoints();    </div>
<div>  TPSTransformType::OutputPointType trackerPointNewPosition;</div><div><br></div><div>  for(unsigned int i = 0; i &lt; sourceLandMarks-&gt;GetNumberOfPoints(); i++){</div><div><font color="#ff0000"><b>    PointType src_pnt = sourceLandMarks-&gt;GetPoint(i);  // Here It doesn&#39;t compile  ?</b></font></div>
<div>    trackerPointNewPosition = tps-&gt;TransformPoint(trackerPoint);</div><div>    transformed_points_container-&gt;InsertElement(i,trackerPointNewPosition); </div><div>  }</div><div><br></div><div>    </div><div><br>
</div><div>  return EXIT_SUCCESS;</div><div><br></div><div><br></div><div>}</div><div><br></div></div><div>agatte</div>