[Insight-users] Apply Transform

Luis Ibanez luis.ibanez at kitware.com
Tue Jun 30 11:17:25 EDT 2009


Hi Steban,

You code seem to be ok.

However we are missing some important information from
your image.

In particular:


     A) What are the coordinates of the Origin  ?
          you can get this with   image->GetOrigin()

     B) What is the orientation of the image ?
          you can get this with    image->GetDirection()


Your manual computation seems to assume that
the origin coordinates are (0,0,0) and that the
direction cosines are given  by an Identity matrix.


If you want to understand the rotation of the image
you should first experiment with Translations set
to Zero.  Otherwise, as you probably know, a
Rotation followed by a Translation will generate
a different apparent center of rotation.


You are also missing to include in your email the
values that you are passing as angles for the
Euler transform.

Also, a screenshot of the output image that lead
you to suspect that something is wrong, will be
useful for this discussion. Could you please post
this screenshot in a public web site ?



     Thanks


          Luis


-------------------------------------------------------------------
On Mon, Jun 29, 2009 at 1:24 PM, Oscar Esteban Sanz-Dranguet <
oesteban at die.upm.es> wrote:

> 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;
>  }
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090630/7d1f7833/attachment.htm>


More information about the Insight-users mailing list