Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <Registration/cmtkGroupwiseRegistrationFunctionalAffineInitializer.h>
00034
00035 #include <Base/cmtkMathUtil.h>
00036
00037 namespace
00038 cmtk
00039 {
00040
00043
00044 void
00045 GroupwiseRegistrationFunctionalAffineInitializer::InitializeXforms
00046 ( GroupwiseRegistrationFunctionalBase& functional, const bool alignCenters, const bool alignCenterOfMass, const bool initScales )
00047 {
00048 const size_t numberOfImages = functional.m_ImageVector.size();
00049
00050 const Vector3D centerTemplate = functional.m_TemplateGrid->GetCenterCropRegion();
00051
00052 std::vector<Vector3D> centers( numberOfImages );
00053 std::vector<Vector3D> firstOrderMoments;
00054 if ( initScales )
00055 firstOrderMoments.resize( numberOfImages );
00056 functional.m_XformVector.resize( numberOfImages );
00057
00058 Vector3D centerAverage;
00059 std::fill( centerAverage.begin(), centerAverage.end(), 0 );
00060
00061
00062 for ( size_t imageIdx = 0; imageIdx < numberOfImages; ++imageIdx )
00063 {
00064 if ( alignCenters )
00065 {
00066 if ( alignCenterOfMass )
00067 {
00068 if ( initScales )
00069 {
00070 centers[imageIdx] = functional.m_ImageVector[imageIdx]->GetCenterOfMass( firstOrderMoments[imageIdx] );
00071 }
00072 else
00073 {
00074 centers[imageIdx] = functional.m_ImageVector[imageIdx]->GetCenterOfMass();
00075 }
00076 }
00077 else
00078 {
00079 centers[imageIdx] = functional.m_ImageVector[imageIdx]->GetCenter();
00080 }
00081 }
00082 centerAverage += centers[imageIdx];
00083 }
00084
00085
00086 centerAverage *= (1.0 / numberOfImages);
00087
00088
00089 for ( size_t imageIdx = 0; imageIdx < numberOfImages; ++imageIdx )
00090 {
00091 AffineXform::SmartPtr xform( new AffineXform );
00092 xform->SetUseLogScaleFactors( true );
00093 xform->SetCenter( centerTemplate.begin() );
00094
00095 const Vector3D delta( centers[imageIdx] - centerAverage );
00096
00097 xform->SetXlate( delta.begin() );
00098 functional.m_XformVector[imageIdx] = xform;
00099 }
00100
00101
00102 if ( initScales )
00103 {
00104 UniformVolume::CoordinateVectorType avgScales( UniformVolume::CoordinateVectorType::Init( 0 ) );
00105 UniformVolume::CoordinateVectorType fom0( firstOrderMoments[0] );
00106 for ( size_t imageIdx = 0; imageIdx < numberOfImages; ++imageIdx )
00107 {
00108 for ( int dim = 0; dim < 3; ++dim )
00109 firstOrderMoments[imageIdx][dim] = log( firstOrderMoments[imageIdx][dim] / fom0[dim] );
00110 avgScales += firstOrderMoments[imageIdx];
00111 }
00112 avgScales *= ( 1.0 / numberOfImages );
00113 for ( size_t imageIdx = 0; imageIdx < numberOfImages; ++imageIdx )
00114 {
00115 firstOrderMoments[imageIdx] -= avgScales;
00116 AffineXform::SmartPtr::DynamicCastFrom( functional.m_XformVector[imageIdx] )->SetScales( firstOrderMoments[imageIdx].begin() );
00117 }
00118 }
00119 }
00120
00121 }