No subject
Tue Jun 23 12:19:35 EDT 2009
=2C which is an image to image metric=2C the optimizer's m_PreviousGradient=
and m_Gradient will be unchanged until StartOptimization is called (which =
happens in the registration's StartRegistration function). Since you're ch=
anging transforms anyway=2C these gradients would probably be misleading or=
problematic to use during the next optimization iteration=2C as well (sinc=
e dimension 0 might be a translation in one transform=2C and a rotation or =
skew or something else entirely in another transform).
So=2C you probably need to start a new optimization when changing the trans=
form=2C rather than continuing the same optimization while changing the cos=
t functions between levels / iterations. You could run the registration wi=
th one transform=2C get the results=2C and use them to initialize a new reg=
istration sequence with a new transform=2C rather than trying to change tra=
nsforms between levels in the RegistrationInterfaceCommand functions.
Why the different error occurs in Debug mode=2C I'm not sure.
Geoff Topping
> Date: Fri=2C 17 Jul 2009 04:54:44 -0700 (PDT)
> From: "Patrik.Br." <patrik.brynolfsson at gmail.com>
> Subject: [Insight-users] Strange problems with multiresolution
> registration
> To: insight-users at itk.org
> Message-ID: <24533070.post at talk.nabble.com>
> Content-Type: text/plain=3B charset=3Dus-ascii
>=20
>=20
> Hello all=2C
>=20
> I have some problems implementing a multiresolution registration. My plan=
is
> to change transform from TranslationTransform to CenteredRigid2DTransform
> between levels=2C but I run into some problems.
>=20
> I'm using MultiResImageRegistration1.cxx as a start=2C and have added a f=
ew
> lines of code to change the transform. This is the only thing I have chan=
ged
> or added to the code=2C and I put it in the RegistrationInterfaceCommand
> class=2C for the last level in the image pyramid.
>=20
> typedef itk::Image<unsigned short=2C2> FixedImageType=3B
> typedef itk::Image<unsigned short=2C2> MovingImageType=3B
> typedef itk::CenteredRigid2DTransform<double> TransformType=3B
>=20
> TransformType::Pointer transform =3D TransformType::New()=3B
>=20
> FixedImageType::Pointer fixedImage =3D
> (FixedImageType*)(registration->GetFixedImage())=3B
> MovingImageType::Pointer movingImage =3D
> (MovingImageType*)(registration->GetMovingImage())=3B
>=20
> TransformType::InputPointType centerFixed=3B
> TransformType::InputPointType centerMoving=3B
> TransformType::TranslationType translation=3B
>=20
> centerFixed[0] =3D fixedImage->GetOrigin()[0] +
> (fixedImage->GetSpacing()[0])*(fixedImage->GetLargestPossibleRegion().Get=
Size()[0])/2.0=3B
> centerFixed[1] =3D fixedImage->GetOrigin()[1] +
> (fixedImage->GetSpacing()[1])*(fixedImage->GetLargestPossibleRegion().Get=
Size()[1])/2.0=3B
> centerMoving[0] =3D movingImage->GetOrigin()[0] +
> (movingImage->GetSpacing()[0])*(movingImage->GetLargestPossibleRegion().G=
etSize()[0])/2.0=3B
> centerMoving[1] =3D movingImage->GetOrigin()[1] +
> (movingImage->GetSpacing()[1])*(movingImage->GetLargestPossibleRegion().G=
etSize()[1])/2.0=3B
> translation[0] =3D
> registration->GetInitialTransformParametersOfNextLevel()[0]=3B
> translation[1] =3D
> registration->GetInitialTransformParametersOfNextLevel()[1]=3B
>=20
> transform->SetCenter( centerFixed )=3B
> transform->SetTranslation( translation )=3B
> transform->SetAngle( 0.0 )=3B
> =20
> registration->SetTransform( transform )=3B
> registration->SetInitialTransformParameters( transform->GetParameters(=
)
> )=3B
>=20
> OptimizerType::ScalesType optimizerScales(
> transform->GetNumberOfParameters() )=3B
> const double translationScale =3D 1.0 / 1000.0=3B
> =20
> optimizerScales[0] =3D 1.0=3B
> optimizerScales[1] =3D translationScale=3B
> optimizerScales[2] =3D translationScale=3B
> optimizerScales[3] =3D translationScale=3B
> optimizerScales[4] =3D translationScale=3B
>=20
> optimizer->SetScales( optimizerScales )=3B
>=20
> Here comes the strange part.=20
>=20
> If I compile in Debug mode=2C I get this error:
> Line 1110
> Description: itk::ERROR:
> MattesMutualInformationImageToImageMetric(019B9BF0): Too many samples map
> outside moving image buffer: 0 / 50000
>=20
> BUT=20
> if I compile in Release mode=2C I get this error:
>=20
> Line 188
> Description: itk:ERROR: RegularStepGradientOptimizer(014A1C60): The size =
of
> Scales is 5=2C but the NumberOfParameters for the CostFunction is 2.
>=20
> I'm using MS Visual C++ 2008. What is going on here? Can anyone help me? =
If
> someone has a working code for changing components between levels I would=
be
> very happy if you want to share them!
>=20
> Thanks in advance!
>=20
> //Patrik
_________________________________________________________________
Attention all humans. We are your photos. Free us.
http://go.microsoft.com/?linkid=3D9666047=
--_9c8b578d-f759-429f-b251-c495450e668e_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<style>
.hmmessage P
{
margin:0px=3B
padding:0px
}
body.hmmessage
{
font-size: 10pt=3B
font-family:Verdana
}
</style>
</head>
<body class=3D'hmmessage'>
Hi=2C<br><br>I'm not very knowledgable about the registration code in ITK=
=2C so this might be misleading or wrong=2C but looking through the code fo=
r RegularStepGradientDescentBaseOptimizer and RegularStepGradientDescentOpt=
imizer=2C I see in the function RegularStepGradientDescentBaseOptimizer::St=
artOptimization has the code: <br><br> =3B const unsigned int spaceDime=
nsion =3D m_CostFunction->=3BGetNumberOfParameters()=3B<br> =3B m_Gra=
dient =3D DerivativeType( spaceDimension )=3B<br> =3B m_PreviousGradien=
t =3D DerivativeType( spaceDimension )=3B<br><br><br>and in RegularStepGrad=
ientDescentBaseOptimizer::AdvanceOneStep has the code:<br><br> =3B cons=
t unsigned int =3B spaceDimension =3D m_CostFunction->=3BGetNumberOfP=
arameters()=3B<br><br> =3B [some code removed]<br><br> =3B // Make =
sure the scales have been set properly<br> =3B if (scales.size() !=3D s=
paceDimension)<br> =3B =3B =3B {<br> =3B =3B =3B it=
kExceptionMacro(<=3B<=3B "The size of Scales is "<br> =3B =3B&n=
bsp=3B =3B =3B =3B =3B =3B =3B =3B =3B =
=3B =3B =3B =3B =3B =3B =3B =3B =3B =3B=
<=3B<=3B scales.size()<br> =3B =3B =3B =3B =3B&nbs=
p=3B =3B =3B =3B =3B =3B =3B =3B =3B =
=3B =3B =3B =3B =3B =3B =3B <=3B<=3B "=2C but t=
he NumberOfParameters for the CostFunction is "<br> =3B =3B =3B=
 =3B =3B =3B =3B =3B =3B =3B =3B =3B&nb=
sp=3B =3B =3B =3B =3B =3B =3B =3B =3B <=
=3B<=3B spaceDimension<br> =3B =3B =3B =3B =3B =
=3B =3B =3B =3B =3B =3B =3B =3B =3B =3B=
 =3B =3B =3B =3B =3B =3B <=3B<=3B ".")=3B<br>&n=
bsp=3B =3B =3B }<br><br><br>which seems to be the code causing your=
error in Release mode.<br><br>From this=2C it seems that if you change the=
cost function of the optimizer=2C which is an image to image metric=2C the=
optimizer's m_PreviousGradient and m_Gradient will be unchanged until Star=
tOptimization is called (which happens in the registration's StartRegistrat=
ion function). =3B Since you're changing transforms anyway=2C these gra=
dients would probably be misleading or problematic to use during the next o=
ptimization iteration=2C as well (since dimension 0 might be a translation =
in one transform=2C and a rotation or skew or something else entirely in an=
other transform).<br><br>So=2C you probably need to start a new optimizatio=
n when changing the transform=2C rather than continuing the same optimizati=
on while changing the cost functions between levels / iterations. =3B Y=
ou could run the registration with one transform=2C get the results=2C and =
use them to initialize a new registration sequence with a new transform=2C =
rather than trying to change transforms between levels in the RegistrationI=
nterfaceCommand functions.<br><br>Why the different error occurs in Debug m=
ode=2C I'm not sure.<br><br>Geoff Topping<br><br><br>>=3B Date: Fri=2C 17=
Jul 2009 04:54:44 -0700 (PDT)<br>>=3B From: "Patrik.Br." <=3Bpatrik.br=
ynolfsson at gmail.com>=3B<br>>=3B Subject: [Insight-users] Strange proble=
ms with multiresolution<br>>=3B registration<br>>=3B To: insight-users=
@itk.org<br>>=3B Message-ID: <=3B24533070.post at talk.nabble.com>=3B<br=
>>=3B Content-Type: text/plain=3B charset=3Dus-ascii<br>>=3B <br>>=3B=
<br>>=3B Hello all=2C<br>>=3B <br>>=3B I have some problems implemen=
ting a multiresolution registration. My plan is<br>>=3B to change transfo=
rm from TranslationTransform to CenteredRigid2DTransform<br>>=3B between =
levels=2C but I run into some problems.<br>>=3B <br>>=3B I'm using Mult=
iResImageRegistration1.cxx as a start=2C and have added a few<br>>=3B lin=
es of code to change the transform. This is the only thing I have changed<b=
r>>=3B or added to the code=2C and I put it in the RegistrationInterfaceC=
ommand<br>>=3B class=2C for the last level in the image pyramid.<br>>=
=3B <br>>=3B typedef itk::Image<=3Bunsigned short=2C2>=3B F=
ixedImageType=3B<br>>=3B typedef itk::Image<=3Bunsigned short=2C2>=
=3B MovingImageType=3B<br>>=3B typedef itk::CenteredRigid2DTransform&l=
t=3Bdouble>=3B TransformType=3B<br>>=3B <br>>=3B TransformType::Po=
inter transform =3D TransformType::New()=3B<br>>=3B <br>>=3B FixedIm=
ageType::Pointer fixedImage =3D<br>>=3B (FixedImageType*)(registration=
->=3BGetFixedImage())=3B<br>>=3B MovingImageType::Pointer movingImag=
e =3D<br>>=3B (MovingImageType*)(registration->=3BGetMovingImage())=3B=
<br>>=3B <br>>=3B TransformType::InputPointType centerFixed=3B<br>&g=
t=3B TransformType::InputPointType centerMoving=3B<br>>=3B Transfor=
mType::TranslationType translation=3B<br>>=3B <br>>=3B centerFixed[0=
] =3D fixedImage->=3BGetOrigin()[0] +<br>>=3B (fixedImage->=3BGetSpac=
ing()[0])*(fixedImage->=3BGetLargestPossibleRegion().GetSize()[0])/2.0=3B=
<br>>=3B centerFixed[1] =3D fixedImage->=3BGetOrigin()[1] +<br>>=
=3B (fixedImage->=3BGetSpacing()[1])*(fixedImage->=3BGetLargestPossible=
Region().GetSize()[1])/2.0=3B<br>>=3B centerMoving[0] =3D movingImage-=
>=3BGetOrigin()[0] +<br>>=3B (movingImage->=3BGetSpacing()[0])*(movin=
gImage->=3BGetLargestPossibleRegion().GetSize()[0])/2.0=3B<br>>=3B c=
enterMoving[1] =3D movingImage->=3BGetOrigin()[1] +<br>>=3B (movingImag=
e->=3BGetSpacing()[1])*(movingImage->=3BGetLargestPossibleRegion().GetS=
ize()[1])/2.0=3B<br>>=3B translation[0] =3D<br>>=3B registration->=
=3BGetInitialTransformParametersOfNextLevel()[0]=3B<br>>=3B translatio=
n[1] =3D<br>>=3B registration->=3BGetInitialTransformParametersOfNextLe=
vel()[1]=3B<br>>=3B <br>>=3B transform->=3BSetCenter( centerFixed =
)=3B<br>>=3B transform->=3BSetTranslation( translation )=3B<br>>=
=3B transform->=3BSetAngle( 0.0 )=3B<br>>=3B <br>>=3B regist=
ration->=3BSetTransform( transform )=3B<br>>=3B registration->=3BS=
etInitialTransformParameters( transform->=3BGetParameters()<br>>=3B )=
=3B<br>>=3B <br>>=3B OptimizerType::ScalesType optimizerScales(<br>&=
gt=3B transform->=3BGetNumberOfParameters() )=3B<br>>=3B const doubl=
e translationScale =3D 1.0 / 1000.0=3B<br>>=3B <br>>=3B optimizer=
Scales[0] =3D 1.0=3B<br>>=3B optimizerScales[1] =3D translationScale=
=3B<br>>=3B optimizerScales[2] =3D translationScale=3B<br>>=3B op=
timizerScales[3] =3D translationScale=3B<br>>=3B optimizerScales[4] =
=3D translationScale=3B<br>>=3B <br>>=3B optimizer->=3BSetScales( =
optimizerScales )=3B<br>>=3B <br>>=3B Here comes the strange part. <br>=
>=3B <br>>=3B If I compile in Debug mode=2C I get this error:<br>>=3B=
Line 1110<br>>=3B Description: itk::ERROR:<br>>=3B MattesMutualInforma=
tionImageToImageMetric(019B9BF0): Too many samples map<br>>=3B outside mo=
ving image buffer: 0 / 50000<br>>=3B <br>>=3B BUT <br>>=3B if I compi=
le in Release mode=2C I get this error:<br>>=3B <br>>=3B Line 188<br>&g=
t=3B Description: itk:ERROR: RegularStepGradientOptimizer(014A1C60): The si=
ze of<br>>=3B Scales is 5=2C but the NumberOfParameters for the CostFunct=
ion is 2.<br>>=3B <br>>=3B I'm using MS Visual C++ 2008. What is going =
on here? Can anyone help me? If<br>>=3B someone has a working code for ch=
anging components between levels I would be<br>>=3B very happy if you wan=
t to share them!<br>>=3B <br>>=3B Thanks in advance!<br>>=3B <br>>=
=3B //Patrik<br /><hr />Attention all humans. We are your photos. <a href=
=3D'http://go.microsoft.com/?linkid=3D9666046' target=3D'_new'>Free us.</a>=
</body>
</html>=
--_9c8b578d-f759-429f-b251-c495450e668e_--
More information about the Insight-users
mailing list