<div class="gmail_quote"><div class="gmail_quote">Hi,all,<br>
     I need to register a CAD model to CT image of a patient with this model. First of all, I<br>
got an initial transform matrix with fiducial registration method, which<br>
already puts the CAD model in approximately the right place, and then I<br>
obtained the gradient magnitude image of the 
CT data, and tried using PointSetToImageRegistrationMethod to register the<br>
point set to it.<br>
     But when registration is performed, only rotation parameters are<br>
changed during registration, and the fractional translation around zero is<br>
observed. I tried changing translation scale maximum and minimum step<br>
length but it is not translating at all and only rotation is effected by<br>
change of these parameters, and the registration result is totally wrong.<br>
     Could anyone please help me take a look at the source codes and give me<br>
some suggestions?Thanks!<br>
<br>
P.S. the source codes are as follows:<br>
<br>
void registerCADmodelToImage()<br>
{<br>
        typedef itk::Image&lt;double, 3&gt; ITKImageType;<br>
        typedef itk::PointSetToImageRegistrationMethod&lt;PointSetType,ITKImageType&gt;<br>
RegistrationType;<br>
        typedef itk::PointSet&lt; double, 3 &gt; PointSetType;<br>
        typedef itk::VersorRigid3DTransform&lt; double &gt; TransformType;<br>
        typedef itk::VersorRigid3DTransformOptimizer OptimizerType;<br>
        typedef<br>
itk::NormalizedCorrelationPointSetToImageMetric&lt;PointSetType,ITKImageType&gt;<br>
MetricType;<br>
        typedef itk:: LinearInterpolateImageFunction&lt;ITKImageType,double &gt;<br>
InterpolatorType;<br>
        typedef MetricType::TransformType TransformBaseType;<br>
        typedef TransformBaseType::ParametersType ParametersType;<br>
<br>
        RegistrationType::Pointer RegistrationMethod= RegistrationType::New();<br>
        PointSetType::Pointer pointSet= PointSetType::New();<br>
        MetricType::Pointer metric = MetricType::New();<br>
        OptimizerType::Pointer optimizer = OptimizerType::New();<br>
        InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>
        TransformType::Pointer transform = TransformType::New();<br>
        transform-&gt;SetIdentity();<br>
<br>
//--------------------------------------------------------------------------------------------------<br>
// Set the initial registration matrix for the CAD model<br>
//--------------------------------------------------------------------------------------------------<br>
        itk::Matrix&lt;double, 3, 3&gt; transformMatrix,transformMatrixIni;<br>
        itk::Vector&lt;double, 3&gt;    vec,vecIni;<br>
        static const int D = 3;<br>
        int i, j;<br>
<br>
        transformMatrix[0][0]=0.1675;<br>
transformMatrix[0][1]=-0.985872;transformMatrix[0][2]=0;<br>
        transformMatrix[1][0]=-0.985872;<br>
transformMatrix[1][1]=-0.1675;transformMatrix[1][2]=0;<br>
        transformMatrix[2][0]=0; transformMatrix[2][1]=0;transformMatrix[2][2]=-1;<br>
        vec[0]=8.9;vec[1]=41.47;vec[2]=-103.88;<br>
<br>
        vtkSmartPointer&lt;vtkMatrix4x4&gt; vtkmatInitial =<br>
vtkSmartPointer&lt;vtkMatrix4x4&gt;::New();<br>
        vtkmatInitial-&gt;Identity();<br>
<br>
        for (i=0; i &lt; D; i++)<br>
                {<br>
                for (j=0; j &lt; D; j++)<br>
                        {<br>
                        (*vtkmatInitial)[i][j] = transformMatrix[i][j];<br>
                        }<br>
                (*vtkmatInitial)[i][D] = vec[i];<br>
                }<br>
<br>
//--------------------------------------------------------------------------------------------------<br>
// Set the point data set for the CAD model<br>
//--------------------------------------------------------------------------------------------------<br>
        unsigned int pointId=0;<br>
        setPointData(35,34,vtkmatInitial,&amp;pointId,pointSet);<br>
        setPointData(25,36.679,vtkmatInitial,&amp;pointId,pointSet);<br>
       <br><div><div class="h5">
//----------------------------------------------------------------------------<br>
// Load the moving image<br>
//----------------------------------------------------------------------------<br>
  typedef itk::ImageFileReader&lt;ITKImageType&gt; MovingImageReaderType;<br>
<br>
  MovingImageReaderType::Pointer movingReader =<br>
MovingImageReaderType::New();<br>
  movingReader-&gt;SetFileName( &quot;1.mhd&quot; );<br>
<br>
  try<br>
    {<br>
    movingReader-&gt;Update();<br>
    }<br>
  catch( itk::ExceptionObject &amp; e )<br>
    {<br>
    std::cout &lt;&lt; e.GetDescription() &lt;&lt; std::endl;<br>
    return ;<br>
    }<br>
<br>
  typedef itk::GradientMagnitudeImageFilter&lt;<br>
                  ITKImageType, ITKImageType &gt;  filterType;<br>
<br>
   // Create and setup a gradient filter<br>
  filterType::Pointer gradientFilter = filterType::New();<br>
  gradientFilter-&gt;SetInput( movingReader-&gt;GetOutput() );<br>
  gradientFilter-&gt;Update();<br>
<br>
        RegistrationMethod-&gt;SetInitialTransformParameters(transform-&gt;GetParameters()<br>
);<br>
        RegistrationMethod-&gt;SetTransform( transform );<br>
<br>
        // Scale the translation components of the Transform in the Optimizer<br>
        typedef OptimizerType::ScalesType OptimizerScalesType;<br>
        OptimizerScalesType optimizerScales( transform-&gt;GetNumberOfParameters());<br>
<br>
        const double translationScale = 1.0 ;<br>
        optimizerScales[0] = 0.1;<br>
        optimizerScales[1] = 0.1;<br>
        optimizerScales[2] = 0.1;<br>
        optimizerScales[3] = translationScale;<br>
        optimizerScales[4] = translationScale;<br>
        optimizerScales[5] = translationScale;<br>
        optimizer-&gt;SetMaximumStepLength( 0.1 );<br>
        optimizer-&gt;SetMinimumStepLength( 0.01 );<br>
        optimizer-&gt;SetNumberOfIterations( 500 );<br>
        optimizer-&gt;SetRelaxationFactor( 0.90 );<br>
        optimizer-&gt;SetGradientMagnitudeTolerance( 0.005 );<br>
        optimizer-&gt;MinimizeOn();<br>
        RegistrationMethod-&gt;SetFixedPointSet( pointSet );<br>
        RegistrationMethod-&gt;SetMetric( metric );<br>
        RegistrationMethod-&gt;SetOptimizer( optimizer );<br>
        RegistrationMethod-&gt;SetInterpolator( interpolator );<br>
        RegistrationMethod-&gt;SetMovingImage( gradientFilter-&gt;GetOutput() );<br>
<br>
        try<br>
                {<br>
                RegistrationMethod-&gt;Update();<br>
                }<br>
<br>
        catch( itk::ExceptionObject &amp; e )<br>
                {<br>
                std::cout &lt;&lt; &quot;testing!!!&quot; &lt;&lt; std::endl;<br>
                std::cerr &lt;&lt; e &lt;&lt; std::endl;<br>
                ostrstream ostr;<br>
                cout.rdbuf(ostr.rdbuf());<br>
                std::cout &lt;&lt; e &lt;&lt; std::endl;<br>
                }<br>
<br>
        OptimizerType::ParametersType<br>
finalParameters=RegistrationMethod-&gt;GetLastTransformParameters();<br>
<br>
        double versorX              = finalParameters[0];<br>
        double versorY              = finalParameters[1];<br>
        double versorZ              = finalParameters[2];<br>
        double finalTranslationX    = finalParameters[3];<br>
        double finalTranslationY    = finalParameters[4];<br>
        double finalTranslationZ    = finalParameters[5];<br>
<br>
        const unsigned int numberOfIterations = optimizer-&gt;GetCurrentIteration();<br>
        const double bestValue = optimizer-&gt;GetValue();<br>
<br>
  // Print out results<br>
  //<br>
  std::cout &lt;&lt; std::endl &lt;&lt; std::endl;<br>
  std::cout &lt;&lt; &quot;Result = &quot; &lt;&lt; std::endl;<br>
  std::cout &lt;&lt; &quot; versor X      = &quot; &lt;&lt; versorX  &lt;&lt; std::endl;<br>
  std::cout &lt;&lt; &quot; versor Y      = &quot; &lt;&lt; versorY  &lt;&lt; std::endl;<br>
  std::cout &lt;&lt; &quot; versor Z      = &quot; &lt;&lt; versorZ  &lt;&lt; std::endl;<br>
  std::cout &lt;&lt; &quot; Translation X = &quot; &lt;&lt; finalTranslationX  &lt;&lt; std::endl;<br>
  std::cout &lt;&lt; &quot; Translation Y = &quot; &lt;&lt; finalTranslationY  &lt;&lt; std::endl;<br>
  std::cout &lt;&lt; &quot; Translation Z = &quot; &lt;&lt; finalTranslationZ  &lt;&lt; std::endl;<br>
  std::cout &lt;&lt; &quot; Iterations    = &quot; &lt;&lt; numberOfIterations &lt;&lt; std::endl;<br>
  std::cout &lt;&lt; &quot; Metric value  = &quot; &lt;&lt; bestValue          &lt;&lt; std::endl;<br>
}<br>
<br>
<br>
<br>
</div></div></div><br>
</div><br>