[Insight-users] Apply Transform
Oscar Esteban Sanz-Dranguet
oesteban at die.upm.es
Mon Jun 29 13:24:02 EDT 2009
Hi,
I try to apply a rigid transform to some mri images. After SetCenter,
only rotation about Y axis seems to use this center. Why I don't get the
correct center of rotation about X and Z axis? (code at the end)
Best Regards,
Oscar Esteban
<<<<<<<<<<<<<<<<< CODE >>>>>>>>>>>>>>>>>>>>>>
int main( int argc, char *argv[] )
{
if ( argc < 8 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImageFile outputImageFile";
std::cerr << " traslationX traslationY traslationZ";
std::cerr << " rotationX rotationY rotationZ";
std::cerr << std::endl;
return 1;
}
typedef itk::ImageFileReader< ImageType > ImageReaderType;
typedef itk::Euler3DTransform< double > TransformType;
// Read images
ImageReaderType::Pointer imageReader = ImageReaderType::New();
imageReader->SetFileName( argv[1] );
imageReader->Update();
ImageType::Pointer image = imageReader->GetOutput();
ImageType::SpacingType spacing = image->GetSpacing();
ImageType::IndexType pixelCenter = { 128, 128, 58 };
image->SetPixel( pixelCenter, 255);
TransformType::Pointer transform = TransformType::New();
TransformType::InputPointType center;
center[0] = 128.5 * spacing[0];
center[1] = 128.5 * spacing[1];
center[2] = 58.5 * spacing[2];
transform->SetCenter( center );
TransformType::OutputVectorType translation;
translation[0] = atof( argv[3] ) * spacing[0];
translation[1] = atof( argv[4] ) * spacing[1];
translation[2] = atof( argv[5] ) * spacing[2];
transform->SetRotation( deg2rad( atof( argv[6] ) ), deg2rad( atof(
argv[7] ) ), deg2rad( atof( argv[8] ) ) );
transform->SetTranslation( translation );
transform->Print(std::cout, 3);
typedef itk::ResampleImageFilter< ImageType, ImageType >
ResampleFilterType;
ResampleFilterType::Pointer resampler = ResampleFilterType::New();
resampler->SetTransform( transform );
resampler->SetInput( image );
resampler->SetReferenceImage( image );
resampler->UseReferenceImageOn( );
resampler->Update();
typedef itk::ImageFileWriter< ImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[2] );
writer->SetInput( resampler->GetOutput() );
writer->Update();
return EXIT_SUCCESS;
}
More information about the Insight-users
mailing list