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
00034
00035 #include <Registration/cmtkGroupwiseRegistrationFunctionalXformTemplateBase.h>
00036
00037 #include <Base/cmtkMathUtil.h>
00038 #include <IO/cmtkVolumeIO.h>
00039
00040 #ifdef CMTK_BUILD_MPI
00041 # include <mpi.h>
00042 # include <IO/cmtkMPI.h>
00043 #endif
00044
00045 namespace
00046 cmtk
00047 {
00048
00051
00052 template<class TXform>
00053 GroupwiseRegistrationFunctionalXformTemplateBase<TXform>::GroupwiseRegistrationFunctionalXformTemplateBase() :
00054 m_HistogramBins( 64 ),
00055 m_HistogramKernelRadiusMax( 0 ),
00056 m_MaxRelativeNumberOutsidePixels( 0.99 ),
00057 m_CropImageHistograms( false )
00058 {}
00059
00060 template<class TXform>
00061 GroupwiseRegistrationFunctionalXformTemplateBase<TXform>::~GroupwiseRegistrationFunctionalXformTemplateBase()
00062 {
00063 }
00064
00065 template<class TXform>
00066 void
00067 GroupwiseRegistrationFunctionalXformTemplateBase<TXform>
00068 ::SetNumberOfHistogramBins( const size_t numberOfHistogramBins )
00069 {
00070 this->m_HistogramBins = numberOfHistogramBins;
00071 if ( this->m_OriginalImageVector.size() )
00072 {
00073 std::cerr << "WARNING: you called GroupwiseRegistrationFunctionalBase::SetNumberOfHistogramBins(),\n"
00074 << " but target images were already set. To be safe, I am re-generating\n"
00075 << " pre-scaled images.\n\n";
00076 this->SetTargetImages( this->m_OriginalImageVector );
00077 }
00078 }
00079
00080 template<class TXform>
00081 UniformVolume::SmartPtr
00082 GroupwiseRegistrationFunctionalXformTemplateBase<TXform>
00083 ::PrepareSingleImage( UniformVolume::SmartPtr& image )
00084 {
00085 UniformVolume::SmartPtr newTargetImage = this->Superclass::PrepareSingleImage( image );
00086
00087 TypedArray::SmartPtr data = newTargetImage->GetData();
00088 if ( this->m_CropImageHistograms )
00089 {
00090 data->PruneHistogram( true, false, this->m_HistogramBins );
00091 }
00092
00093 data->Rescale( 1.0 * (this->m_HistogramBins-1) / data->GetRange().Width(), this->m_HistogramKernelRadiusMax );
00094
00095 newTargetImage->SetData( TypedArray::SmartPtr( data->Convert( TYPE_BYTE ) ) );
00096 return newTargetImage;
00097 }
00098
00099 template<class TXform>
00100 void
00101 GroupwiseRegistrationFunctionalXformTemplateBase<TXform>
00102 ::PrepareTargetImages()
00103 {
00104 this->m_ImageVector.resize( this->m_OriginalImageVector.size() );
00105
00106 #ifdef CMTK_BUILD_MPI
00107
00108 const size_t imageFrom = this->m_RankMPI;
00109 const size_t imageSkip = this->m_SizeMPI;
00110 #else
00111 const size_t imageFrom = 0;
00112 const size_t imageSkip = 1;
00113 #endif
00114 for ( size_t i = imageFrom; i < this->m_ImageVector.size(); i += imageSkip )
00115 {
00116 this->m_ImageVector[i] = UniformVolume::SmartPtr( this->PrepareSingleImage( this->m_OriginalImageVector[i] ) );
00117 }
00118
00119 #ifdef CMTK_BUILD_MPI
00120
00121 for ( size_t i = 0; i < this->m_ImageVector.size(); ++i )
00122 {
00123 cmtk::mpi::Broadcast( MPI::COMM_WORLD, this->m_ImageVector[i], i % this->m_SizeMPI );
00124 }
00125 #endif
00126
00127 this->m_PrivateUserBackgroundValue = this->m_UserBackgroundValue + this->m_HistogramKernelRadiusMax;
00128 }
00129
00131
00132 }
00133
00134 #include <Base/cmtkAffineXform.h>
00135 #include <Base/cmtkSplineWarpXform.h>
00136
00137 template class cmtk::GroupwiseRegistrationFunctionalXformTemplateBase<cmtk::AffineXform>;
00138 template class cmtk::GroupwiseRegistrationFunctionalXformTemplateBase<cmtk::SplineWarpXform>;