00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freMutualInformationMetricController_h
00023 #define __freMutualInformationMetricController_h
00024
00025 #include "freImageToImageMetricControllerBase.h"
00026
00027 #include "freIntensityImageMediaController.h"
00028
00029 #include "itkMutualInformationImageToImageMetric.h"
00030
00031 namespace FREE
00032 {
00033
00043 freControllerIDMacro(MutualInformationMetricControllerBase, "MutualInformationMetricBase");
00044 template <class TImageType>
00045 class MutualInformationMetricControllerBase : public ImageToImageMetricControllerBase< itk::MutualInformationImageToImageMetric<TImageType,TImageType> >
00046 {
00047 public:
00048 typedef itk::MutualInformationImageToImageMetric<TImageType,TImageType> ComponentType;
00049 typedef ImageToImageMetricControllerBase<ComponentType> Superclass;
00050
00051 itkTypeMacro(MutualInformationMetricControllerBase, ImageToImageMetricControllerBase);
00052
00053 DeclareParameterMacro(NrOfSmpl);
00054 DeclareParameterMacro(MovingStdDev);
00055 DeclareParameterMacro(FixedStdDev);
00056 DeclareParameterMacro(AbsoluteSamples);
00057 DeclareParameterMacro(InitialSeed);
00058 DeclareParameterMacro(UseInitialSeed);
00059
00060 DeclareMediaIDMacro(sampleImage);
00061
00062 protected:
00065 MutualInformationMetricControllerBase()
00066 {
00067
00068 this->UpdateControllerID(ControllerID::MutualInformationMetricControllerBase);
00069 this->m_Description = "A mutual information metric based on the concept of Viola and Wells.";
00070 };
00071
00072 virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00073 const SessionComponentCache* pComponentCache,
00074 bool bRegardOldSetup) const
00075 {
00076 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00077
00078
00079 profile.Parameters().AddParameter(cParam_NrOfSmpl,Parameter::PVTDouble,cParamDsc_NrOfSmpl,1,"100",-1,true);
00080 profile.Parameters().AddParameter(cParam_MovingStdDev,Parameter::PVTDouble,cParamDsc_MovingStdDev,1,"1.0",-1,true);
00081 profile.Parameters().AddParameter(cParam_FixedStdDev,Parameter::PVTDouble,cParamDsc_FixedStdDev,1,"1.0",-1,true);
00082 profile.Parameters().AddParameter(cParam_AbsoluteSamples,Parameter::PVTBool,cParamDsc_AbsoluteSamples,1,"true");
00083 profile.Parameters().AddParameter(cParam_InitialSeed,CtrlProfile::Parameter::PVTInteger,cParamDsc_InitialSeed,1,"21021978",-1,true);
00084 profile.Parameters().AddParameter(cParam_UseInitialSeed,CtrlProfile::Parameter::PVTBool,cParamDsc_UseInitialSeed,1,"false");
00085
00086 profile.Parameters().AddParameter(cParam_MetricMinimize,Parameter::PVTBool,cParamDsc_MetricMinimize,1,"false",1,false,0,DAGet);
00087
00088 unsigned int iGroupID = 0;
00089
00090 if (bRegardOldSetup)
00091 {
00092 bool bAbsolute;
00093
00094 Parameter* pParamAbs = pComponentCache->Setup()->Parameters().GetParameter(cParam_AbsoluteSamples);
00095
00096 if (!pParamAbs) throwCtrlExceptionMacro("","Error. Parameter "<<cParam_AbsoluteSamples<<" could not be found in old setup. Please ensure the creation of valid setups.");
00097
00098 pParamAbs->GetParameterValue(bAbsolute);
00099
00100 if (!bAbsolute)
00101 {
00102
00103
00104 iGroupID = 1;
00105 }
00106 }
00107
00108 profile.MediaMap().AddMedia(MediaID_sampleImage,ControllerID::IntensityImageMediaControllerBase,DASet,TImageType::GetImageDimension(),iGroupID);
00109 };
00110
00115 virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00116 SessionComponentCache* pComponentCache,
00117 SessionInfo* pSessionInfo,
00118 const unsigned int& iActLevel) const
00119 {
00120 double dSmpl;
00121 double dMovingStdDev;
00122 double dFixedStdDev;
00123 int iSeed;
00124 bool bAbsolute;
00125 bool bUseSeed;
00126
00127 try
00128 {
00129 SessionAccessor::GetParameterValue(pComponentCache,cParam_NrOfSmpl,dSmpl,0,iActLevel,true);
00130 SessionAccessor::GetParameterValue(pComponentCache,cParam_MovingStdDev,dMovingStdDev,0,iActLevel,true);
00131 SessionAccessor::GetParameterValue(pComponentCache,cParam_FixedStdDev,dFixedStdDev,0,iActLevel,true);
00132 SessionAccessor::GetParameterValue(pComponentCache,cParam_AbsoluteSamples,bAbsolute);
00133 SessionAccessor::GetParameterValue(pComponentCache,cParam_UseInitialSeed,bUseSeed);
00134 SessionAccessor::GetParameterValue(pComponentCache,cParam_InitialSeed,iSeed);
00135 }
00136 catchAllNPassMacro("Error while retrieving parameter values.");
00137
00138 unsigned int iNrOfSmpl = static_cast<unsigned int>(dSmpl);
00139
00140 if (!bAbsolute)
00141 {
00142 if (dSmpl<0) throwCtrlExceptionMacro("","Relative number of samples must not be lesser then 0 (0%). Pleas check setup. Current value: "<<dSmpl);
00143 if (dSmpl>1) throwCtrlExceptionMacro("","Relative number of samples must not be greater then 1 (100%). Pleas check setup. Current value: "<<dSmpl);
00144
00145 typedef TImageType InternalImageType;
00146
00147 SessionAccessor::GenericMediaPointer smpGenericSampleImage = SessionAccessor::GetLinkedMedia(MediaID_sampleImage,pComponentCache,pSessionInfo);
00148 if (smpGenericSampleImage.IsNull()) throwCtrlExceptionMacro("","Cannot compute number of samples. No sample image linked. Please check media linkage.");
00149
00150 InternalImageType* pSampleImage = 0;
00151
00152 try
00153 {
00154 pSampleImage = dynamic_cast<InternalImageType*>(smpGenericSampleImage.GetPointer());
00155 }
00156 catchAllNPassMacro("Error while casting sample image");
00157 if (!pSampleImage) throwCtrlExceptionMacro("","Error while casting sample image.");
00158
00159 iNrOfSmpl = static_cast<unsigned int>(pSampleImage->GetLargestPossibleRegion().GetNumberOfPixels()*dSmpl);
00160 }
00161 else if (!bAbsolute)
00162 {
00163 if (dSmpl<0) throwCtrlExceptionMacro("","Absolute number of samples must not be lesser then 0. Pleas check setup. Current value: "<<dSmpl);
00164 };
00165
00166 pMainComponent->SetNumberOfSpatialSamples(iNrOfSmpl);
00167 pMainComponent->SetMovingImageStandardDeviation(dMovingStdDev);
00168 pMainComponent->SetFixedImageStandardDeviation(dFixedStdDev);
00169 if (bUseSeed && (iActLevel==0)) pMainComponent->ReinitializeSeed(iSeed);
00170 };
00171
00172 void
00173 SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia, ComponentType* pComponent, SessionComponentCache* pComponentCache,
00174 SessionInfo* pSessionInfo) const
00175 {
00176 if (mediaID == MediaID_sampleImage)
00177 {
00178
00179 }
00180 else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00181 };
00182
00183 };
00184
00185 template <class TImageType>
00186 const char* const MutualInformationMetricControllerBase<TImageType>
00187 ::cParam_NrOfSmpl = "NrOfSmpl";
00188 template <class TImageType>
00189 const char* const MutualInformationMetricControllerBase<TImageType>
00190 ::cParamDsc_NrOfSmpl = "Number of samples used by the metric. If SampleAbsolute is false, this value indicates the fraction of the pixel count of sampleImage that will be used (0: 0%; 1: 100%).";
00191
00192 template <class TImageType>
00193 const char* const MutualInformationMetricControllerBase<TImageType>
00194 ::cParam_MovingStdDev = "MovingStdDev";
00195 template <class TImageType>
00196 const char* const MutualInformationMetricControllerBase<TImageType>
00197 ::cParamDsc_MovingStdDev = "Standard deviation for moving image.";
00198
00199 template <class TImageType>
00200 const char* const MutualInformationMetricControllerBase<TImageType>
00201 ::cParam_FixedStdDev = "FixedStdDev";
00202 template <class TImageType>
00203 const char* const MutualInformationMetricControllerBase<TImageType>
00204 ::cParamDsc_FixedStdDev = "Standard deviation for the fixed image.";
00205
00206 template <class TImageType>
00207 const char* const MutualInformationMetricControllerBase<TImageType>
00208 ::cParam_AbsoluteSamples = "AbsoluteSamples";
00209 template <class TImageType>
00210 const char* const MutualInformationMetricControllerBase<TImageType>
00211 ::cParamDsc_AbsoluteSamples = "Indicates if NrOfSmpl is the absolut number of samples (true) or the percentage (0: 0% ... 1: 100%) of the pixels of sampleImage (false) that should be used.";
00212
00213 template <class TImageType>
00214 const char* const MutualInformationMetricControllerBase<TImageType>
00215 ::cParam_UseInitialSeed = "UseInitialSeed";
00216 template <class TImageType>
00217 const char* const MutualInformationMetricControllerBase<TImageType>
00218 ::cParamDsc_UseInitialSeed = "If true the seed specified by \"InitialSeed\" will be used to draw the samples. If false, the internal clock will be used as seed.";
00219
00220 template <class TImageType>
00221 const char* const MutualInformationMetricControllerBase<TImageType>
00222 ::cParam_InitialSeed = "InitialSeed";
00223 template <class TImageType>
00224 const char* const MutualInformationMetricControllerBase<TImageType>
00225 ::cParamDsc_InitialSeed = "The seed for the random generator used to draw the samples.";
00226
00227 template <class TImageType>
00228 const char* const MutualInformationMetricControllerBase<TImageType>
00229 ::MediaID_sampleImage = "sampleImage";
00230 template <class TImageType>
00231 const char* const MutualInformationMetricControllerBase<TImageType>
00232 ::MediaIDDsc_sampleImage = "Reference image that can be used to determine the number of samples that should be used. It is only needed if AbsoluteSample is false.";
00233
00234
00244 freControllerIDMacro(MutualInformation2DMetricController, "Mutual Information 2D Metric");
00245 class MutualInformation2DMetricController : public MutualInformationMetricControllerBase<InternalImage2DType>
00246 {
00247 public:
00248 itkTypeMacro(MutualInformation2DMetricController, MutualInformationMetricControllerBase);
00249
00250 MutualInformation2DMetricController();
00251 };
00252
00262 freControllerIDMacro(MutualInformation3DMetricController, "Mutual Information 3D Metric");
00263 class MutualInformation3DMetricController : public MutualInformationMetricControllerBase<InternalImage3DType>
00264 {
00265 public:
00266 itkTypeMacro(MutualInformation3DMetricController, MutualInformationMetricControllerBase);
00267
00268 MutualInformation3DMetricController();
00269 };
00270
00271 }
00272
00273 #endif