[Insight-users] changing components in iteration of itkMultiResolutionImageRegistrationMethod

Patrik.Br. patrik.brynolfsson at gmail.com
Thu Jul 16 04:51:18 EDT 2009


Hello Luis,

I'm doing a similar thing to what Dan was attempting, i.e. change components
between levels in multi-resolution registration. My goal is to swap
transform from TranslationTransform to CenteredRigid2DTransform, but I get
the same error as Dan:

"Description: itk::ERROR: RegualStepGradientDecentOptimizer(014A1C60): The
size of Scales is 5, but the NumberOfParameters for the CostFunctions is 2"

Now when he posted his question you repiled:

Luis Ibanez wrote:
> 
> 
> Hi Dan,
> 
> 
> When you switch transform, you must also change the number
> of elements in the scaling-parameter array.
> 
> 
>      In your case, you have
> 
>         1) Translation2D -----> 2 parameters
>         2) Affine2D      -----> 6 parameters
> 
> 
> 
> and you pass to the optimizer the scaling array that permits to
> balance the irregularity in measurement unit between translations
> and rotations.
> 
> 
> 
> Please read the Image Registration chapter of the ITK Software Guide
> 
>       http://www.itk.org/ItkSoftwareGuide.pdf
> 
> in particular the section on Multi-Resolution registration.
> 
> 
> 
> You should also look at the code of the file
> 
>        Insight/Examples/Registration/
>             MultiResImageRegistration2.cxx
> 
> in particular to lines 325-333, and 379:
> 
> 
> // This is for the Affine transform
> 
>    OptimizerScalesType optimizerScales(
>       transform->GetNumberOfParameters() );
> 
>    optimizerScales[0] = 1.0; // scale for M11
>    optimizerScales[1] = 1.0; // scale for M12
>    optimizerScales[2] = 1.0; // scale for M21
>    optimizerScales[3] = 1.0; // scale for M22
> 
>    optimizerScales[4] = 1.0 / 1000000.0; // scale for translation on X
>    optimizerScales[5] = 1.0 / 1000000.0; // scale for translation on Y
> 
>    optimizer->SetScales( optimizerScales );
> 
> 
> 
> Note that the numbers for the translations X and Y depend on
> the spacing and number of pixels of your image.  The Image
> Registration chapter give you guidance on how to compute
> reasonable values for these scales.
> 
> 
> 
>    Regards,
> 
> 
>       Luis
> 
> ---------------
> 
I did not really understand your answer. My code in the command class for
the last resolution level is:

          typedef itk::Image<unsigned short,2> FixedImageType;
	  typedef itk::Image<unsigned short,2> MovingImageType;
	  typedef itk::CenteredRigid2DTransform<double> TransformType;

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

	  FixedImageType::Pointer  fixedImage   =
(FixedImageType*)(registration->GetFixedImage());
	  MovingImageType::Pointer movingImage  =
(MovingImageType*)(registration->GetMovingImage());

	  TransformType::InputPointType centerFixed;
	  TransformType::InputPointType centerMoving;
	  TransformType::TranslationType translation;

	  centerFixed[0] = fixedImage->GetOrigin()[0] +
(fixedImage->GetSpacing()[0])*(fixedImage->GetLargestPossibleRegion().GetSize()[0])/2.0;
	  centerFixed[1] = fixedImage->GetOrigin()[1] +
(fixedImage->GetSpacing()[1])*(fixedImage->GetLargestPossibleRegion().GetSize()[1])/2.0;
	  centerMoving[0] = movingImage->GetOrigin()[0] +
(movingImage->GetSpacing()[0])*(movingImage->GetLargestPossibleRegion().GetSize()[0])/2.0;
	  centerMoving[1] = movingImage->GetOrigin()[1] +
(movingImage->GetSpacing()[1])*(movingImage->GetLargestPossibleRegion().GetSize()[1])/2.0;
	  translation[0] =
registration->GetInitialTransformParametersOfNextLevel()[0];
	  translation[1] =
registration->GetInitialTransformParametersOfNextLevel()[1];

	  transform->SetCenter( centerFixed );
	  transform->SetTranslation( translation );
	  transform->SetAngle( 0.0 );
	  
	  registration->SetTransform( transform );
	  registration->SetInitialTransformParameters( transform->GetParameters()
);

	  OptimizerType::ScalesType optimizerScales(
transform->GetNumberOfParameters() );
	  const double translationScale = 1.0 / 1000.0;
	  
	  optimizerScales[0] = 1.0;
	  optimizerScales[1] = translationScale;
	  optimizerScales[2] = translationScale;
	  optimizerScales[3] = translationScale;
	  optimizerScales[4] = translationScale;

	  optimizer->SetScales( optimizerScales );

and I have explicitely defined the scales to be 5. How do I change the
CostFunction NumberOfParameters? I have read the ITK Software Guide and I'm
afraid I am no wiser. Any help appreciated!

Regards Patrik


Dan Rizzo wrote:
> Hello
> 
> I am trying to register two 2D images with some offset and rotation.
> 
> Section 8.7.1 of the Software Guide shows how to change parameters for 
> the Optimizer in between iterations of the multi resolution registration 
> framework.  It also mentions that you could even swap out components 
> between levels.  This is where I'm having trouble.
> 
> I'd like the first resolution registration to perform the Translation 
> transform, and the second to do an Affine transform.  The idea here is 
> to use a Gradient Descent optimizer for each, and the 
> MeanSquaresImageToImageMetric for both as well.   Later I should be able 
> to switch these components in between resolutions as well.  I was 
> planning on trying Mattes MI with a OnePlusOne for the first stage.
> 
> Is there some pattern I need to follow in my Command Observer class to 
> switch components?  I have gone ahead and set the registration's 
> transform to the new object using SetTransform().  I created a new 
> Optimizer and set the parameters accordingly.  I tried then calling 
> Update() on the registration.
> 
> When the program gets to the second resolution, I get the error message 
> "The size of Scales is 6, but the NumberOfParameters for the 
> CostFunction is 2." coming out of the 
> RegularStepGradientDescentOptimizer.  The first level had only 2 
> parameters as the transform was a translation, and the second had 6 for 
> affine.
> 
> Is there an example somewhere which actually does switch components in 
> between resolutions, or does anyone know what I'm doing / not doing?
> 
> Thanks in advance!
> 
> Dan
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users



-- 
View this message in context: http://www.nabble.com/changing-components-in-iteration-of-itkMultiResolutionImageRegistrationMethod-tp7019877p24512705.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list