[Insight-users] Problem with MeanSquaresImageToImageMetric.
suresh
suresh " <suresh_kb at rediffmail . com
24 Aug 2002 13:13:38 -0000
This is a multipart mime message
--Next_1030194818---0-202.54.124.153-18770
Content-type: text/html;
charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
--Next_1030194818---0-202.54.124.153-18770
Content-type: text/plain;
charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Hi Luis,=0D=0A=0D=0AThanks for the help.=0D=0A=0D=0AIndeed, all that code i=
submitted was in a try-catch.=0D=0AIt is not throwing any itk::Exception.=
=0D=0AIts throwing a windows runtime error.=0D=0A=0D=0ATHIS PROGRAM HAS PER=
FORMED AN ILLEGALOPERATION AND WILL BE SHUTDOWN.=0D=0A=0D=0A********Code s=
nippet..1***=0D=0A typedef itk::QuaternionRigidTransform<double> Transfo=
rmType;=0D=0A typedef itk::QuaternionRigidTransformGradientDescentOptimi=
zer OptimizerType; =0D=0A typedef itk::LinearInterpolateImageFunction<Im=
ageType, double> InterpolatorType;=0D=0A typedef itk::ImageRegistrationM=
ethod<ImageType,ImageType> RegistrationType1;=0D=0A=0D=0A typedef itk::M=
eanSquaresImageToImageMetric<ImageType, ImageType> MetricType; =0D=0A M=
etricType::Pointer metric =3D MetricType::New();=0D=0A Tr=
ansformType::Pointer transform =3D TransformType::New();=0D=0A =
OptimizerType::Pointer optimizer =3D OptimizerType::New();=0D=0A =
InterpolatorType::Pointer interpolator =3D InterpolatorType::New();=0D=
=0A RegistrationType1::Pointer registration =3D RegistrationType1::New=
(); =0D=0A RegistrationType1::ParametersType guess(transform->GetNumb=
erOfParameters() ); =0D=0A =0D=0A guess[0] =3D 0.0; guess[1] =3D 0.0; g=
uess[2] =3D 0.0; guess[3] =3D 1.0;=0D=0A guess[4] =3D 20.0; guess[5] =3D=
40.0; guess[6] =3D 0.0;=0D=0A=0D=0A ImagePointer fixedImage =3D BufferT=
oImage(MRI);// built from an pixel buffer=0D=0A ImagePointer movingImage=
=3D BufferToImage(SPECT);=0D=0A=0D=0A registration->SetInitialTransformPar=
ameters (guess); =0D=0A //Set translation scale=0D=0A typedef Optimizer=
Type::ScalesType ScaleType;=0D=0A ScaleType scales(transform->GetNumberOfPa=
rameters());=0D=0A scales.Fill( 1.0 );=0D=0A for( unsigned j =3D 4; j < 7; =
j++ )=0D=0A {=0D=0A scales[j] =3D 1.0 / vnl_math_sqr(300.0);=0D=0A } =
=0D=0A //Scale parameters =0D=0A optimizer->SetNumberOfIterations( 1 );=
=0D=0A optimizer->SetLearningRate( 0.0000001 );=0D=0A //set registration =
parameters=0D=0A registration->SetMetric(metric);=0D=0A registration->SetOp=
timizer(optimizer);=0D=0A registration->SetTransform(transform);=0D=0A regi=
stration->SetInterpolator(interpolator); =0D=0A registration->SetFixedI=
mage(fixedImage);=0D=0A registration->SetMovingImage(movingImage); =0D=0A =
// Setup the optimizer=0D=0A optimizer->SetScales(scales); =0D=0A try{=
=0D=0A registration->StartRegistration(); =0D=0A }catch(itk::Exception=
% Eo){=0D=0A AfxMessageBox(Eo.GetDescription()); =0D=0A }=0D=0A--------=
---------------------------------------------------------------=0D=0AI even=
tried to use the example code =0D=0A=0D=0A****Code Snippet ...2*****=0D=0A=
=0D=0A typedef itk::AffineTransform< double, 3> TransformType;=0D=0A type=
def TransformType::ParametersType ParametersType;=0D=0A typedef itk::Gr=
adientDescentOptimizer OptimizerType;=0D=0A typedef itk::MeanSquaresIma=
geToImageMetric< ImageType, ImageType > MetricType;=0D=0A typedef =
itk:: LinearInterpolateImageFunction< ImageType, double >=0D=0A Interpo=
latorType;=0D=0A typedef itk::ImageRegistrationMethod< =0D=0A =
ImageType, =0D=0A =
ImageType > RegistrationType;=0D=0Atypedef itk::CommandIterationUpdate =
< =0D=0A OptimizerType > CommandIteratio=
nType;=0D=0A=0D=0A MetricType::Pointer metric =3D MetricTyp=
e::New();=0D=0A TransformType::Pointer transform =3D TransformTyp=
e::New();=0D=0A OptimizerType::Pointer optimizer =3D OptimizerTyp=
e::New();=0D=0A TransformType::Pointer trasform =3D TransformTyp=
e::New();=0D=0A InterpolatorType::Pointer interpolator =3D Interpolator=
Type::New();=0D=0A RegistrationType::Pointer registration =3D Registrat=
ionType::New(); =0D=0A ImagePointer fixedImage =3D BufferToImage(MRI=
);=0D=0A ImagePointer movingImage =3D BufferToImage(SPECT);=0D=0A Im=
ageType::RegionType region;=0D=0A ImageType::SizeType size;=0D=0A ImageTy=
pe::IndexType index =3D ImageType::IndexType::ZeroIndex;=0D=0A size[0] =3D=
MRI->width;=0D=0A size[1] =3D MRI->height;=0D=0A size[2] =3D MRI->depth;=
=0D=0A region.SetSize( size );=0D=0A region.SetIndex( index );=0D=0A mov=
ingImage->SetLargestPossibleRegion( region );=0D=0A movingImage->SetBuffer=
edRegion( region );=0D=0A movingImage->SetRequestedRegion( region );=0D=0A=
movingImage->Allocate();=0D=0A fixedImage->SetLargestPossibleRegion( reg=
ion );=0D=0A fixedImage->SetBufferedRegion( region );=0D=0A fixedImage->S=
etRequestedRegion( region );=0D=0A fixedImage->Allocate();=0D=0A registra=
tion->SetMetric( metric );=0D=0A registration->SetOptimizer(=
optimizer );=0D=0A registration->SetTransform( transform =
);=0D=0A registration->SetFixedImage( fixedImage );=0D=0A registrat=
ion->SetMovingImage( movingImage );=0D=0A registration->SetInterpolato=
r( interpolator );=0D=0A metric->SetFixedImageRegion( fixedImage->GetBuf=
feredRegion() );=0D=0A CommandIterationType::Pointer iterationCommand =3D =
CommandIterationType::New();=0D=0A iterationCommand->SetOptimizer( optimi=
zer.GetPointer() );=0D=0A OptimizerType::ScalesType scales( transform->Get=
NumberOfParameters() );=0D=0A scales.Fill( 1.0 ); =0D=0A unsigned long =
numberOfIterations =3D 10;=0D=0A double translationScale =3D 1=
e-4;=0D=0A double learningRate =3D 1e-6;=0D=0A for( unsign=
ed int i=3D0; i<Dimension; i++)=0D=0A {=0D=0A scales[ i + Dimension *=
Dimension] =3D translationScale;=0D=0A }=0D=0A=0D=0A optimizer->SetSca=
les( scales );=0D=0A optimizer->SetLearningRate( learningRate );=0D=0A op=
timizer->SetNumberOfIterations( numberOfIterations );=0D=0A optimizer->Min=
imizeOn();=0D=0A transform->SetIdentity();=0D=0A registration->SetInitial=
TransformParameters( transform->GetParameters() );=0D=0A try=0D=0A {=0D=
=0A registration->StartRegistration();=0D=0A }=0D=0A catch( itk::Exc=
eptionObject & e )=0D=0A {=0D=0A AfxMessageBox(e.GetDescription());=0D=
=0A }=0D=0A-------------------------------------------------------------=
--------------=0D=0A=0D=0AAs I wrote earlier The BufferToImage Function bui=
lds an Image from a Buffer. =0D=0AThe code sniuppet .. 1 works perfectly wi=
th itk::MutualInformationImageToImageMetric.=0D=0A=0D=0AI could not identif=
y whats wrong with MeanSquaresImageToImageMetric.=0D=0AIs there any thing t=
hat i need to initialize with, fixedImage and movingImages?? =0D=0A=0D=0Ap=
lease help me with this.=0D=0A=0D=0AThanks,=0D=0A=0D=0Asuresh=0D=0A=0D=0A=
=0D=0A=0D=0A=0D=0A=0D=0A=0D=0A
--Next_1030194818---0-202.54.124.153-18770--