[Insight-users] Demons Registration- Warping Field Parameters

Rahul Chander rahulch at interchange.ubc.ca
Fri, 02 Apr 2004 21:06:47 -0800


Hi,
I was looking for a method in Demons Registration Filter that will 
allow me to export the final deformation field to an image file.  
This feature is implemented for FEM based deformable registration 
through member: WriteDisplacementField().  
Unable to find anything similar, I looked at the code for 
WriteDisplacementField() available in 
Code/Algorithms/itkFEMRegistrationFilter.txx  and wrote up something 
similar. 
I inserted the following for Demons Registration (2D) in 
Examples/Registration/DeformableRegistration2.cxx and got some 
results.  Can anyone confirm if this approach will give the correct 
results?  Is there a better way?

Thanks.
Rahul. 
...
#include <itkVectorIndexSelectionCastImageFilter.h>
....
...
  writer->SetFileName( argv[3] );
  caster->SetInput( warper->GetOutput() );
  writer->SetInput( caster->GetOutput()   );
  writer->Update();

//My code begins here. 
//Commented lines are for expanding to the 3D case.

	typedef itk::Image< float, Dimension > FloatImageType;
	typedef 
itk::VectorIndexSelectionCastImageFilter<DeformationFieldType,FloatImageType> 
IndexSelectCasterType;
	IndexSelectCasterType::Pointer fieldCaster1 = 
IndexSelectCasterType::New();
	IndexSelectCasterType::Pointer fieldCaster2 = 
IndexSelectCasterType::New();
//	IndexSelectCasterType::Pointer fieldCaster3 = 
IndexSelectCasterType::New();

	fieldCaster1->SetInput( warper->GetDeformationField() );
	fieldCaster1->SetIndex( 0 );
	fieldCaster2->SetInput(warper->GetDeformationField() );
	fieldCaster2->SetIndex( 1 );
//	fieldCaster3->SetInput(warper->GetDeformationField() );
//	fieldCaster3->SetIndex( 2 );

	// Define the output of the Moving
	fieldCaster1->Update();
	fieldCaster2->Update();
//	fieldCaster3->Update();

	typedef itk::ImageFileWriter<FloatImageType> WriterTypeFloat;
	WriterTypeFloat::Pointer writer1 = WriterTypeFloat::New();
	WriterTypeFloat::Pointer writer2 = WriterTypeFloat::New();
//	WriterTypeFloat::Pointer writer3 = WriterTypeFloat::New();

	// Set up the output filename
	std::string outfile1="X_disp_vec.hdr";
	std::string outfile2="Y_disp_vec.hdr";
//	std::string outfile3="Z_disp_vec.hdr";
	std::cout << "Writing displacements to " << outfile1;
	writer1->SetInput(fieldCaster1->GetOutput());
	writer1->SetFileName(outfile1.c_str());
	writer1->Write();
	std::cout << "...done" << std::endl;

	std::cout << "Writing displacements to " << outfile2;
	writer2->SetInput(fieldCaster2->GetOutput());
	writer2->SetFileName(outfile2.c_str());
	writer2->Write();
	std::cout << "...done" << std::endl;

// 	std::cout << "Writing displacements to " << outfile3;
// 	writer3->SetInput(fieldCaster3->GetOutput());
// 	writer3->SetFileName(outfile3.c_str());
// 	writer3->Write();
// 	std::cout << "...done" << std::endl;


The cout statements above do not function the way they are supposed 
to because of the threaded nature of the code, and therefore they 
are not very useful to have in main().  

-- 
===================================
Rahul Chander
IV Year Electrical Eng.
The University of British Columbia
Linux User:207994
===================================