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't receive position of points after transformation.</div><div>I don't know what'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 "itkImageRegistrationMethod.h"</div><div>#include "itkMattesMutualInformationImageToImageMetric.h"</div><div>#include "itkLinearInterpolateImageFunction.h"</div>
<div>#include "itkOrientedImage.h"</div><div>#include "itkTimeProbesCollectorBase.h"</div><div>#include "itkImage.h"</div><div>#include "itkVector.h"</div><div>#include "itkResampleImageFilter.h"</div>
<div>#include "itkLandmarkBasedTransformInitializer.h"</div><div>#include "itkRigid2DTransform.h"</div><div>#include "itkBSplineDeformableTransform.h"</div><div>#include "itkCenteredTransformInitializer.h"</div>
<div>#include "itkVersorRigid3DTransform.h"</div><div>#include "itkAffineTransform.h"</div><div>#include "itkBSplineDeformableTransform.h"</div><div>#include "itkRegularStepGradientDescentOptimizer.h"</div>
<div>#include "itkBSplineResampleImageFunction.h"</div><div>#include "itkBSplineDecompositionImageFilter.h"</div><div>#include "itkResampleImageFilter.h"</div><div>#include "itkCastImageFilter.h"</div>
<div>#include "itkSquaredDifferenceImageFilter.h"</div><div>#include "itkTransformFileReader.h"</div><div>#include "itkCommand.h"</div><div>#include "itkLinearInterpolateImageFunction.h"</div>
<div>#include "itkThinPlateSplineKernelTransform.h"</div><div>#include "itkVolumeSplineKernelTransform.h"</div><div>#include "itkElasticBodySplineKernelTransform.h"</div><div>#include "itkPoint.h"</div>
<div>#include "itkPointSet.h"</div><div>#include "itkTransformFileWriter.h"</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<Self> 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 & 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 & event)</div>
<div> {</div><div> OptimizerPointer optimizer = </div><div> dynamic_cast< OptimizerPointer >( object );</div><div> if( !(itk::IterationEvent().CheckEvent( &event )) )</div><div> {</div><div> return;</div>
<div> }</div><div> std::cout << optimizer->GetCurrentIteration() << " ";</div><div> std::cout << optimizer->GetValue() << " ";</div><div> std::cout << 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< CoordinateRepType,Dimension> TPSTransformType;</div>
<div> typedef itk::Point< CoordinateRepType,Dimension > PointType;</div><div> typedef std::vector< PointType > 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->GetPoints();</div><div>
PointSetType::PointsContainer::Pointer targetLandMarkContainer = </div><div> targetLandMarks->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->InsertElement( 0,trackerPoint);</div><div> targetLandMarkContainer->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->InsertElement(1,trackerPoint);</div>
<div> targetLandMarkContainer->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->InsertElement( 2,trackerPoint);</div><div> targetLandMarkContainer->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->InsertElement( 3,trackerPoint);</div><div> targetLandMarkContainer->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->InsertElement(4,trackerPoint);</div><div> targetLandMarkContainer->InsertElement(4,imagePoint);</div><div><br></div><div> TPSTransformType::Pointer tps = TPSTransformType::New();</div>
<div> tps->SetSourceLandmarks(sourceLandMarks);</div><div> tps->SetTargetLandmarks(targetLandMarks);</div><div> tps->ComputeWMatrix();</div><div> tps->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->GetPoints(); </div>
<div> TPSTransformType::OutputPointType trackerPointNewPosition;</div><div><br></div><div> for(unsigned int i = 0; i < sourceLandMarks->GetNumberOfPoints(); i++){</div><div><font color="#ff0000"><b> PointType src_pnt = sourceLandMarks->GetPoint(i); // Here It doesn't compile ?</b></font></div>
<div> trackerPointNewPosition = tps->TransformPoint(trackerPoint);</div><div> transformed_points_container->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>