[Insight-users] On Metrics of registration

cspl affable at hd2 . dot . net . in
Mon, 26 Aug 2002 14:27:30 +0530


This is a multi-part message in MIME format.

------=_NextPart_000_000C_01C24D0C.B60125B0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Dear Mr.Luis,
 I am working on itkImageRegistration with different metric classes as =
metrics for registration.I could get the output with =
itkMutualInformationImageToImageMetric class.But,I am getting error when =
i used itkNormalizedCorrelationImageToImageMetric and =
itkMeanSquaresImageToImageMetric.I found that some classes like =
setFixedImagestandarddeviation,setNumberOfSamples etc are not available =
in Normal and meansquares.I am getting problem at startregistration().I =
am unable to catch the exception using try and catch.I am getting some =
memory exception.I am enclosing  code.



--------code---------
 //Check for registration type
 if(RegType=3D=3D0)
 {
 Flag=3Dfalse;
typedef itk::MeanSquaresImageToImageMetric<ImageType,ImageType> =
MetricType;      MetricType::Pointer         metric   =3D =
MetricType::New();
  AfxMessageBox("mean squares");
  registration->SetMetric(metric);
 }
 else if (RegType=3D=3D1)
 {
typedef itk::NormalizedCorrelationImageToImageMetric<ImageType, =
ImageType> MetricType;    =20
    MetricType::Pointer         metric =3D MetricType::New();
/*metric->SetFixedImageRegion(FixedImage->GetBufferedRegion());
    metric->SetScaleGradient( 1.0 );*/
    registration->SetMetric(metric);
    Flag=3Dfalse;
 }
 else if (RegType=3D=3D2)
 {
typedef itk::MutualInformationImageToImageMetric<ImageType,  ImageType> =
MetricType;    =20
    MetricType::Pointer         metric =3D MetricType::New();

    metric->SetMovingImageStandardDeviation( 2 );
    metric->SetFixedImageStandardDeviation( 2 );
    metric->SetNumberOfSpatialSamples( 50 );=20
    registration->SetMetric(metric);
    Flag=3Dfalse;
 }=20
 else
 {    =20
    Flag=3Dtrue;
 }

=20
=20
typedef itk::QuaternionRigidTransform<double> TransformType;

typedef itk::QuaternionRigidTransformGradientDescentOptimizer =
OptimizerType;     =20

typedef itk::LinearInterpolateImageFunction<ImageType, double>  =
InterpolatorType;
    =20
 TransformType::Pointer      transform     =3D TransformType::New();  =
OptimizerType::Pointer      optimizer     =3D  OptimizerType::New();
 InterpolatorType::Pointer   interpolator  =3D InterpolatorType::New();
    =20
       =20
     RegistrationType1::ParametersType =
guess(transform->GetNumberOfParameters() );
     =20
     guess[0] =3D 0.0;
     guess[1] =3D 0.0;
     guess[2] =3D 0.0;
     guess[3] =3D 1.0;
     guess[4] =3D 1.0;
     guess[5] =3D 1.0;
     guess[6] =3D 0.0;
     =20
     registration->SetInitialTransformParameters (guess);          =20
      =20
    // Set translation scale
    typedef OptimizerType::ScalesType ScaleType;
    ScaleType scales(transform->GetNumberOfParameters());
    scales.Fill( 1.0 );
    for( unsigned j =3D 4; j < 7; j++ )
    {
     scales[j] =3D 1.0 / vnl_math_sqr(1000.0);
    }
         =20
   =20
    //Scale parameters=20
    optimizer->SetNumberOfIterations(1000);
    optimizer->SetLearningRate( 0.0000001 );         =20
   =20
    // Setup the optimizer
    optimizer->SetScales(scales);
    // optimizer->MaximizeOn();
           =20
    //set registration parameters
   =20
    registration->SetOptimizer(optimizer);
    registration->SetTransform(transform);
    registration->SetInterpolator(interpolator);
    registration->SetFixedImage(FixedImage);
    registration->SetMovingImage(MovingImage);
   registration->DebugOn();
             =20
    try
    {
     registration->StartRegistration();
    }
    catch(itk::ExceptionObject &except)
    {  =20
            std::cerr<<"Exception"<<except.GetDescription();
    =20
     =20
    }
  =20
Regards,
CSPL

------=_NextPart_000_000C_01C24D0C.B60125B0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Dear Mr.Luis,<BR>&nbsp;I am working on=20
itkImageRegistration with different metric classes as metrics for =
registration.I=20
could get the output with itkMutualInformationImageToImageMetric =
class.But,I am=20
getting error when i used itkNormalizedCorrelationImageToImageMetric and =

itkMeanSquaresImageToImageMetric.I found that some classes like=20
setFixedImagestandarddeviation,setNumberOfSamples etc are not available =
in=20
Normal and meansquares.I am getting problem at startregistration().I am =
unable=20
to catch the exception using try and catch.I am getting some memory =
exception.I=20
am enclosing&nbsp; code.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV><FONT face=3DArial =
size=3D2>
<DIV><BR>--------code---------<BR>&nbsp;//Check for registration=20
type<BR>&nbsp;if(RegType=3D=3D0)<BR>&nbsp;{<BR>&nbsp;Flag=3Dfalse;<BR>typ=
edef=20
itk::MeanSquaresImageToImageMetric&lt;ImageType,ImageType&gt;=20
MetricType;&nbsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;MetricType::Pointer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
=20
metric&nbsp;&nbsp; =3D =
MetricType::New();<BR>&nbsp;&nbsp;AfxMessageBox("mean=20
squares");<BR>&nbsp;&nbsp;registration-&gt;SetMetric(metric);<BR>&nbsp;}<=
BR>&nbsp;else=20
if (RegType=3D=3D1)<BR>&nbsp;{<BR>typedef=20
itk::NormalizedCorrelationImageToImageMetric&lt;ImageType,&nbsp;ImageType=
&gt;=20
MetricType;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
MetricType::Pointer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
metric =3D=20
MetricType::New();<BR>/*metric-&gt;SetFixedImageRegion(FixedImage-&gt;Get=
BufferedRegion());<BR>&nbsp;&nbsp;&nbsp;=20
metric-&gt;SetScaleGradient( 1.0 );*/<BR>&nbsp;&nbsp;&nbsp;=20
registration-&gt;SetMetric(metric);<BR>&nbsp;&nbsp;&nbsp;=20
Flag=3Dfalse;<BR>&nbsp;}<BR>&nbsp;else if =
(RegType=3D=3D2)<BR>&nbsp;{<BR>typedef=20
itk::MutualInformationImageToImageMetric&lt;ImageType, =
&nbsp;ImageType&gt;=20
MetricType;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
MetricType::Pointer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
metric =3D=20
MetricType::New();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; metric-&gt;SetMovingImageStandardDeviation( 2=20
);<BR>&nbsp;&nbsp;&nbsp; metric-&gt;SetFixedImageStandardDeviation( 2=20
);<BR>&nbsp;&nbsp;&nbsp; metric-&gt;SetNumberOfSpatialSamples( 50=20
);&nbsp;<BR>&nbsp;&nbsp;&nbsp;=20
registration-&gt;SetMetric(metric);<BR>&nbsp;&nbsp;&nbsp; =
Flag=3Dfalse;<BR>&nbsp;}=20
<BR>&nbsp;else<BR>&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; =

Flag=3Dtrue;<BR>&nbsp;}</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;<BR>&nbsp;<BR>typedef =
itk::QuaternionRigidTransform&lt;double&gt;=20
TransformType;</DIV>
<DIV>&nbsp;</DIV>
<DIV>typedef itk::QuaternionRigidTransformGradientDescentOptimizer=20
OptimizerType;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </DIV>
<DIV>&nbsp;</DIV>
<DIV>typedef itk::LinearInterpolateImageFunction&lt;ImageType, =
double&gt;=20
&nbsp;InterpolatorType;<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;TransformType::Pointer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
transform&nbsp;&nbsp;&nbsp;&nbsp; =3D TransformType::New();&nbsp;=20
OptimizerType::Pointer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
optimizer&nbsp;&nbsp;&nbsp;&nbsp; =3D=20
&nbsp;OptimizerType::New();<BR>&nbsp;InterpolatorType::Pointer&nbsp;&nbsp=
;=20
interpolator&nbsp; =3D =
InterpolatorType::New();<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
RegistrationType1::ParametersType =
guess(transform-&gt;GetNumberOfParameters()=20
);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp; =
guess[0] =3D=20
0.0;<BR>&nbsp;&nbsp;&nbsp;&nbsp; guess[1] =3D =
0.0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
guess[2] =3D 0.0;<BR>&nbsp;&nbsp;&nbsp;&nbsp; guess[3] =3D=20
1.0;<BR>&nbsp;&nbsp;&nbsp;&nbsp; guess[4] =3D =
1.0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
guess[5] =3D 1.0;<BR>&nbsp;&nbsp;&nbsp;&nbsp; guess[6] =3D=20
0.0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
registration-&gt;SetInitialTransformParameters=20
(guess);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; // Set translation scale<BR>&nbsp;&nbsp;&nbsp; =
typedef=20
OptimizerType::ScalesType ScaleType;<BR>&nbsp;&nbsp;&nbsp; ScaleType=20
scales(transform-&gt;GetNumberOfParameters());<BR>&nbsp;&nbsp;&nbsp;=20
scales.Fill( 1.0 );<BR>&nbsp;&nbsp;&nbsp; for( unsigned j =3D 4; j &lt; =
7; j++=20
)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; scales[j] =3D 1.0 =
/=20
vnl_math_sqr(1000.0);<BR>&nbsp;&nbsp;&nbsp;=20
}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; //Scale=20
parameters&nbsp;<BR>&nbsp;&nbsp;&nbsp;=20
optimizer-&gt;SetNumberOfIterations(1000);<BR>&nbsp;&nbsp;&nbsp;=20
optimizer-&gt;SetLearningRate( 0.0000001=20
);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; // Setup the optimizer<BR>&nbsp;&nbsp;&nbsp;=20
optimizer-&gt;SetScales(scales);<BR>&nbsp;&nbsp;&nbsp;=20
//&nbsp;optimizer-&gt;MaximizeOn();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; //set registration =
parameters<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;=20
registration-&gt;SetOptimizer(optimizer);<BR>&nbsp;&nbsp;&nbsp;=20
registration-&gt;SetTransform(transform);<BR>&nbsp;&nbsp;&nbsp;=20
registration-&gt;SetInterpolator(interpolator);<BR>&nbsp;&nbsp;&nbsp;=20
registration-&gt;SetFixedImage(FixedImage);<BR>&nbsp;&nbsp;&nbsp;=20
registration-&gt;SetMovingImage(MovingImage);<BR>&nbsp;&nbsp;&nbsp;regist=
ration-&gt;DebugOn();</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;=20
try<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
registration-&gt;StartRegistration();<BR>&nbsp;&nbsp;&nbsp;=20
}<BR>&nbsp;&nbsp;&nbsp; catch(itk::ExceptionObject=20
&amp;except)<BR>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cerr&lt;&lt;"Excepti=
on"&lt;&lt;except.GetDescription();<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; =
}<BR>&nbsp;&nbsp;=20
<DIV><FONT face=3DArial size=3D2>Regards,</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>CSPL</FONT></DIV></FONT></DIV></BODY></HTML>

------=_NextPart_000_000C_01C24D0C.B60125B0--