[Insight-users] question ? [ThinPlateSplineKernelTransform]

agatte wiatrak11 at poczta.onet.pl
Wed May 30 05:15:59 EDT 2012


Hi all ;)

I am dealing with landmark deformable registration.
After TPS transformation in 2D.
I received 12 parameters.  I have a question.
Could I put  parameters of TPS  in matrix? 
What I could put  parameters to matrix (for example matrix 4x4) ?

I would appreciate for any help/advice.

Here my code :


int main()
{

	double tab[20] = 
	{
		// image
    140.6,	230.7,	
    140.2,	231.7,	
    144.8,	235.9,	
    45.8,	220.2,	
    231.6,	211.3,	

	 //tracker
	-81.29,-31.07,	
    -83.11,	-21.26,	
    -93.45,	-32.44,
    -68.08,	-126.89,
    -61.04,	75.74,	
	};
	
	
	

  const     unsigned int   Dimension = 2;
  typedef   unsigned char  PixelType;
  typedef   itk::Image< PixelType, Dimension >  InputImageType;
  typedef   itk::ImageFileReader< InputImageType  >  ReaderType;
  typedef   itk::ImageFileWriter< InputImageType >  DeformedImageWriterType;
  typedef   itk::Point<  float, Dimension >  FieldPointType;
  typedef   itk::Vector< float, Dimension >  FieldVectorType;
  typedef   itk::Image< FieldVectorType,  Dimension >  
DeformationFieldType;
  typedef   itk::ImageFileWriter< DeformationFieldType >  FieldWriterType;
  typedef   double CoordinateRepType;
  typedef   itk::ThinPlateSplineKernelTransform<
CoordinateRepType,Dimension>     TPSTransformType;
  typedef   itk::Point< CoordinateRepType,Dimension >  PointType;
  typedef   std::vector< PointType >                   PointArrayType;
  typedef   TPSTransformType::PointSetType      PointSetType;
  typedef   PointSetType::Pointer            PointSetPointer;
  typedef   PointSetType::PointIdentifier  PointIdType;
  typedef   itk::ResampleImageFilter< InputImageType, 
                                      InputImageType  >  ResamplerType;
  typedef   itk::LinearInterpolateImageFunction< 
                       InputImageType, double >  InterpolatorType;


  // Landmarks correspondances may be associated with the
SplineKernelTransforms
  // via Point Set containers. Let us define containers for the landmarks.
  PointSetType::Pointer sourceLandMarks = PointSetType::New();
  PointSetType::Pointer targetLandMarks = PointSetType::New();
  PointType trackerPoint;     PointType imagePoint;
  PointSetType::PointsContainer::Pointer sourceLandMarkContainer = 
                                   sourceLandMarks->GetPoints();
  PointSetType::PointsContainer::Pointer targetLandMarkContainer = 
                                   targetLandMarks->GetPoints();
 

  // 1 Landmark
  trackerPoint[0] = tab[0];
  trackerPoint[1] = tab[1];
  imagePoint[0] = tab[10];
  imagePoint[1] = tab[11];
  sourceLandMarkContainer->InsertElement( 0,trackerPoint);
  targetLandMarkContainer->InsertElement(0,imagePoint);
 
  // 2 Landmark
  trackerPoint[0] = tab[2];
  trackerPoint[1] = tab[3];
  imagePoint[0] = tab[12];
  imagePoint[1] = tab[13];
  sourceLandMarkContainer->InsertElement(1,trackerPoint);
  targetLandMarkContainer->InsertElement(1,imagePoint);
 
  // 3 Landmark
  trackerPoint[0] = tab[4];
  trackerPoint[1] = tab[5];
  imagePoint[0] = tab[14];
  imagePoint[1] = tab[15];
  sourceLandMarkContainer->InsertElement( 2,trackerPoint);
  targetLandMarkContainer->InsertElement(2,imagePoint);
 
  // 4 Landmark
  trackerPoint[0] = tab[6];
  trackerPoint[1] = tab[7];
  imagePoint[0] = tab[16];
  imagePoint[1] = tab[17];
  sourceLandMarkContainer->InsertElement( 3,trackerPoint);
  targetLandMarkContainer->InsertElement(3,imagePoint);

  // 5 Landmark
  trackerPoint[0] = tab[8];
  trackerPoint[1] = tab[9];
  imagePoint[0] = tab[18];
  imagePoint[1] = tab[19];
  sourceLandMarkContainer->InsertElement( 5,trackerPoint);
  targetLandMarkContainer->InsertElement(5,imagePoint);

  TPSTransformType::Pointer tps = TPSTransformType::New();
  tps->SetSourceLandmarks(sourceLandMarks);
  tps->SetTargetLandmarks(targetLandMarks);
  tps->ComputeWMatrix();
  tps->Register();
  std::cout<<tps<<std::endl;
  std::cout<<tps->GetParameters()<<std::endl;

  
  system("Pause");

  TPSTransformType::ParametersType parameters = tps->GetParameters();



 double pReturn[12];

  for(int i=0; i<12; i++)
  {
	  pReturn[i]=parameters(i);
	  std::cout<<pReturn[i]<<std::endl;
  }

  // Save transform to *.txt file
  typedef itk::TransformFileWriter    TransformWriterType;
  TransformWriterType::Pointer transformWriter = TransformWriterType::New();
  transformWriter->AddTransform( tps);
  transformWriter->SetFileName("tpsTransformFile2D.txt");
  transformWriter->Update();

  return EXIT_SUCCESS;
}
-- 
View this message in context: http://old.nabble.com/question----ThinPlateSplineKernelTransform--tp33930438p33930438.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list