[ITK-users] 2D rigid transformation

Pietro Nardelli p.nardelli at umail.ucc.ie
Tue May 19 05:41:58 EDT 2015


Hi guys,

thank you very much for your help. I was trying to follow the examples you
sent me (converting it in native C++ ITK code), but it seems that the
optimizer does not work properly. In particular, no matter the number of
angles and the step length I choose, it always gives me the same result. It
seems to me that the optimizer is never updating the angles, therefore it
is not following the grid I create. Also the metric is always 0. There is
definitely something wrong! Here is part of the script I am using and the
result I always get. Am I overlooking anything?

  typedef itk::Euler2DTransform< double >
                              TransformType;
  typedef itk::ExhaustiveOptimizerv4< double >
                              OptimizerType;
  typedef itk::MeanSquaresImageToImageMetricv4< FixedInputImageType,
MovingInputImageType >               MetricType;
  typedef itk::CenteredTransformInitializer< TransformType,
FixedInputImageType,  MovingInputImageType > TransformInitializerType;
  typedef itk::ImageRegistrationMethodv4< FixedInputImageType,
MovingInputImageType, TransformType > RegistrationType;

  typename TransformType::Pointer               transform    =
TransformType::New();
  typename MetricType::Pointer                      metric       =
MetricType::New();
  typename OptimizerType::Pointer                optimizer    =
OptimizerType::New();
  typename RegistrationType::Pointer            registration =
RegistrationType::New();
  typename TransformInitializerType::Pointer initializer  =
TransformInitializerType::New();

  unsigned int angles = 12;
  OptimizerType::StepsType steps( transform->GetNumberOfParameters() );
  steps[0] = int(angles/2);
  steps[1] = 0;
  steps[2] = 0;
  optimizer->SetNumberOfSteps( steps );

  OptimizerType::ScalesType scales( transform->GetNumberOfParameters() );
  scales[0] = 2.0 * vnl_math::pi / angles;
  scales[1] = 1.0;
  scales[2] = 1.0;

  optimizer->SetScales( scales );

  initializer->SetTransform(   transform );
  initializer->SetFixedImage(  fixImage );
  initializer->SetMovingImage( movImage );
  //initializer->GeometryOn();
  initializer->InitializeTransform();

  // Initialize registration
  registration->SetMetric(                  metric    );
  registration->SetOptimizer(            optimizer );
  registration->SetFixedImage(         fixedImage  );
  registration->SetMovingImage(      movingImage  );
  registration->SetInitialTransform(   transform );

  try
  {
    registration->Update();
  }
  catch( itk::ExceptionObject & err )
  {
    std::cerr << "ExceptionObject caught !" << std::endl;
    std::cerr << err << std::endl;
    return EXIT_FAILURE;
  }

Result:

Final parameters: [-1.8849555921538759, -40, 40]
Result =
Metric value  = 0
Angle (rad) =  -1.88496
Angle (degrees) =  -108
Iterations    = 13
Rotation Center = [225.5, 185.5]
ExhaustiveOptimizerv4: Completed sampling of parametric space of size 3


Thank you very much,
Pietro

Pietro Nardelli*, MEngSc, BE*

Ph.D Candidate

School of Engineering

Electrical & Electronic Engineering

University College Cork

College Road

Cork, Ireland

On Fri, May 15, 2015 at 7:21 PM, Yaniv, Ziv Rafael (NIH/NLM/LHC) [C] <
zivrafael.yaniv at nih.gov> wrote:

> Hello Pietro,
>
> You should use the ExhaustiveOptimizerv4 (
> http://www.itk.org/Doxygen/html/classitk_1_1ExhaustiveOptimizerv4.html)
> which allows you to set a grid on which the similarity metric is evaluated.
>
> If you are familiar with python, then the following SimpleITK notebook may
> be of use to you (see last section):
> https://github.com/zivy/SimpleITK-Notebook-Staging/blob/master/registration3.ipynb
>
>      regards
>               Ziv
>
> From: Pietro Nardelli <p.nardelli at umail.ucc.ie<mailto:
> p.nardelli at umail.ucc.ie>>
> Date: Friday, May 15, 2015 at 2:13 PM
> To: "insight-users at itk.org<mailto:insight-users at itk.org>" <
> insight-users at itk.org<mailto:insight-users at itk.org>>
> Subject: [ITK-users] 2D rigid transformation
>
> Hello guys,
>
> is there a way to have a 2D rigid registration that uses a specific number
> of rotations and chooses the best one? I have two images that are simply
> rotated with respect to each other, and I would like to register them using
> for example 36 rotations (therefore computing the mean squared error every
> 10 degrees). At the moment I am using the 2DRigidTransform with a specified
> center, with a regular step descent optimizer and the
> ImageRegistrationMethodv4. I saw that the transform has the function
> SetFixedParameters() but I am not really sure whether I understand
> correctly that that would tell the optimizer the angles (and translations)
> to use at every iteration. Could anyone please clarify this?
>
> Thank you very much,
> Pietro
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20150519/0ad0c73a/attachment.html>


More information about the Insight-users mailing list