[Insight-users] rotating with itkVersorTransform

J. Pura puraj at mail.nih.gov
Fri Feb 26 10:29:43 EST 2010


Here is my code. Thanks. Blob1 is ITKimg3Datlas, Blob2 is ITKimg3Dconv.

	// Setup rotation

	  ImageType3D::Pointer ITKimg3Dconv		= ImageType3D::New();
	  ImageType3D::Pointer ITKimg3Datlas	= ImageType3D::New();	
	  TransformType::Pointer      transform     = TransformType::New();
	  InterpolatorType::Pointer   interpolator  = InterpolatorType::New();


	  CenterType center;
	  center[0] = fixedCOM_x;
	  center[1] = fixedCOM_y;
	  center[2] = fixedCOM_z;

 
	Copy_CISImage_to_ITKImage(img3Dconv, ITKimg3Dconv);
	Copy_CISImage_to_ITKImage(img3Datlas, ITKimg3Datlas);


   ParametersType initialParameters( transform->GetNumberOfParameters() );

   // Set Versors
   // Define axis of rotation = vector normal to both primary axes
	double rotax1 = primaryAxis_conv.y * primaryAxis_atlas.z -
primaryAxis_conv.z * primaryAxis_atlas.y;
	double rotax2 = primaryAxis_conv.z * primaryAxis_atlas.x -
primaryAxis_conv.x * primaryAxis_atlas.z;
	double rotax3 = primaryAxis_conv.x * primaryAxis_atlas.y -
primaryAxis_conv.y * primaryAxis_atlas.x;
	
	// factor to create unit vector
	double sqrtsumsq = sqrt(pow(rotax1,2.0) + pow(rotax2,2.0) +
pow(rotax3,2.0));

	initialParameters[0] = (-rotax1/sqrtsumsq) * sin (angleoffset / 2.0 );
	initialParameters[1] = (-rotax2/sqrtsumsq) * sin (angleoffset / 2.0 );
	initialParameters[2] = (-rotax3/sqrtsumsq) * sin (angleoffset / 2.0 );

	//initialParameters[0] = rotax1 * sin (angleoffsetx / 2.0 );
	//initialParameters[1] = rotax2 * sin (angleoffsety / 2.0 );
	//initialParameters[2] = rotax3 * sin (angleoffsetz / 2.0 ); 

  // TransformType::OutputVectorType axis;
   //axis[0] = 1;
   //axis[1] = 0;
   //axis[2] = 0;

   transform->SetParameters (initialParameters);
   transform->SetCenter(center);
   //transform->Rotate3D(axis,angleoffsetx,false);

   TransformType::Pointer finalTransform = TransformType::New();

   finalTransform->SetParameters( transform->GetParameters() );

  ResampleFilterType::Pointer resampler = ResampleFilterType::New();
  resampler->SetInput( ITKimg3Datlas );

  resampler->SetTransform( finalTransform );
  resampler->SetInterpolator(interpolator);
  resampler->SetSize( ITKimg3Dconv->GetLargestPossibleRegion().GetSize() );

  resampler->SetOutputOrigin(  ITKimg3Dconv->GetOrigin() );
  resampler->SetOutputSpacing( ITKimg3Dconv->GetSpacing() );
  resampler->SetDefaultPixelValue( 0 );
  resampler->Update();
-- 
View this message in context: http://n2.nabble.com/rotating-with-itkVersorTransform-tp4638986p4639781.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list