[Insight-users] [Insight-users]itkMutualInformationImageToImageMetric.txx

Lydia Ng lng at insightful . com
Thu, 22 May 2003 15:21:34 -0700


Hi Aloys,

Thank you for your contribution - it has been added to cvs repository.

FYI: I did a test on my machine (XP,VC7,Release mode) with 100 calls to
GetValueAndDerivatives()

Before: 4.25 seconds
After : 3.031 seconds
=20
Cheers,
Lydia

> -----Original Message-----
> From: duboisda at tele . ucl . ac . be [mailto:duboisda at tele . ucl . ac . be]
> Sent: Wednesday, May 21, 2003 11:27 AM
> To: insight-users at public . kitware . com
> Subject: [Insight-users] [Insight-
> users]itkMutualInformationImageToImageMetric.txx
>=20
>=20
> Some optimisation methods using the MutualInformationMetric need the
> derivative of the MI. The slow part of the derivative is the line
>    derivative +=3D ( derivB - (*aditer) ) * weight;
>=20
> You can accelerate it by 3 if you replace
>=20
>     for( aiter =3D m_SampleA.begin(), aditer =3D
sampleADerivatives.begin();
>       aiter !=3D aend; ++aiter, ++aditer )
>         {
>=20
> 	valueFixed =3D ( (*biter).FixedImageValue -
(*aiter).FixedImageValue )
> /
> 	  m_FixedImageStandardDeviation;
> 	valueFixed =3D m_KernelFunction->Evaluate( valueFixed );
>=20
> 	valueMoving =3D ( (*biter).MovingImageValue -
> (*aiter).MovingImageValue ) /
> 	  m_MovingImageStandardDeviation;
> 	valueMoving =3D m_KernelFunction->Evaluate( valueMoving );
>=20
> 	weightMoving =3D valueMoving / dDenominatorMoving;
>   	weightJoint =3D valueMoving * valueFixed / dDenominatorJoint;
>=20
> 	weight =3D ( weightMoving - weightJoint );
> 	weight *=3D (*biter).MovingImageValue - (*aiter).MovingImageValue;
>=20
>   	derivative +=3D ( derivB - (*aditer) ) * weight;
>=20
>       } // end of sample A loop
>     } // end of sample B loop
>=20
> by
>=20
>     totalweight =3D 0;
>=20
>     for( aiter =3D m_SampleA.begin(), aditer =3D
sampleADerivatives.begin();
>       aiter !=3D aend; ++aiter, ++aditer )
>         {
>=20
> 	valueFixed =3D ( (*biter).FixedImageValue -
(*aiter).FixedImageValue )
> /
> 	  m_FixedImageStandardDeviation;
> 	valueFixed =3D m_KernelFunction->Evaluate( valueFixed );
>=20
> 	valueMoving =3D ( (*biter).MovingImageValue -
> (*aiter).MovingImageValue ) /
> 	  m_MovingImageStandardDeviation;
> 	valueMoving =3D m_KernelFunction->Evaluate( valueMoving );
>=20
> 	weightMoving =3D valueMoving / dDenominatorMoving;
>   	weightJoint =3D valueMoving * valueFixed / dDenominatorJoint;
>=20
> 	weight =3D ( weightMoving - weightJoint );
> 	weight *=3D (*biter).MovingImageValue - (*aiter).MovingImageValue;
>=20
> 	totalweight +=3D weight;
> 	derivative -=3D (*aditer) * weight;
>=20
>       } // end of sample A loop
>=20
>     derivative +=3D derivB * totalweight;
>=20
>     } // end of sample B loop
>=20
> And you have to initialize totalweight at the beginning of the
function as
> double.
> derivB is a constant array in the loop. Add it takes a long time. Just
add
> the weight during the A loop and multiply derivB at the end is
faster....
>=20
>    aloys
>=20
>=20
> _______________________________________________
> Insight-users mailing list
> Insight-users at public . kitware . com
> http://public . kitware . com/mailman/listinfo/insight-users