00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freMattesMutualInformationMetricController_h
00023 #define __freMattesMutualInformationMetricController_h
00024
00025 #include "freImageToImageMetricControllerBase.h"
00026
00027 #include "freIntensityImageMediaController.h"
00028
00029 #include "itkMattesMutualInformationImageToImageMetric.h"
00030
00031 namespace FREE
00032 {
00033
00043 freControllerIDMacro(MattesMutualInformationMetricControllerBase, "MattesMutualInformationMetricBase");
00044 template <class TImageType>
00045 class MattesMutualInformationMetricControllerBase : public ImageToImageMetricControllerBase< itk::MattesMutualInformationImageToImageMetric<TImageType,TImageType> >
00046 {
00047 public:
00048 typedef itk::MattesMutualInformationImageToImageMetric<TImageType,TImageType> ComponentType;
00049 typedef ImageToImageMetricControllerBase<ComponentType> Superclass;
00050
00051 itkTypeMacro(MattesMutualInformationMetricControllerBase, ImageToImageMetricControllerBase);
00052
00053 DeclareParameterMacro(NrOfSmpl);
00054 DeclareParameterMacro(NrOfBins);
00055 DeclareParameterMacro(AbsoluteSamples);
00056 DeclareParameterMacro(UseAllSamples);
00057 DeclareParameterMacro(InitialSeed);
00058 DeclareParameterMacro(UseInitialSeed);
00059
00060 DeclareMediaIDMacro(sampleImage);
00061
00062 protected:
00065 MattesMutualInformationMetricControllerBase()
00066 {
00067
00068 this->UpdateControllerID(ControllerID::MattesMutualInformationMetricControllerBase);
00069 this->m_Description = "A mutual information metric. Based on the work of Mattes et. al..";
00070
00071 };
00072
00073 virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00074 const SessionComponentCache* pComponentCache,
00075 bool bRegardOldSetup) const
00076 {
00077 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00078
00079
00080 profile.Parameters().AddParameter(cParam_NrOfSmpl,Parameter::PVTDouble,cParamDsc_NrOfSmpl,1,"100",-1,true);
00081 profile.Parameters().AddParameter(cParam_NrOfBins,Parameter::PVTULong,cParamDsc_NrOfBins,1,"10",-1,true);
00082 profile.Parameters().AddParameter(cParam_AbsoluteSamples,Parameter::PVTBool,cParamDsc_AbsoluteSamples,1,"true",-1,true);
00083 profile.Parameters().AddParameter(cParam_UseAllSamples,Parameter::PVTBool,cParamDsc_UseAllSamples,1,"false");
00084 profile.Parameters().AddParameter(cParam_InitialSeed,CtrlProfile::Parameter::PVTInteger,cParamDsc_InitialSeed,1,"21021978");
00085 profile.Parameters().AddParameter(cParam_UseInitialSeed,CtrlProfile::Parameter::PVTBool,cParamDsc_UseInitialSeed,1,"false");
00086
00087 unsigned int iGroupID = 0;
00088
00089 if (bRegardOldSetup)
00090 {
00091 bool bAbsolute;
00092
00093 Parameter* pParamAbs = pComponentCache->Setup()->Parameters().GetParameter(cParam_AbsoluteSamples);
00094
00095 if (!pParamAbs) throwCtrlExceptionMacro("","Error. Parameter "<<cParam_AbsoluteSamples<<" could not be found in old setup. Please ensure the creation of valid setups.");
00096
00097 pParamAbs->GetParameterValue(bAbsolute);
00098
00099 if (!bAbsolute)
00100 {
00101
00102
00103 iGroupID = 1;
00104 }
00105 }
00106
00107 profile.MediaMap().AddMedia(MediaID_sampleImage,ControllerID::IntensityImageMediaControllerBase,DASet,TImageType::GetImageDimension(),iGroupID);
00108 };
00109
00114 virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00115 SessionComponentCache* pComponentCache,
00116 SessionInfo* pSessionInfo,
00117 const unsigned int& iActLevel) const
00118 {
00119 unsigned long lNrOfBins;
00120 bool bAbsolute;
00121 bool bAll;
00122 double dSmpl;
00123
00124 try
00125 {
00126 SessionAccessor::GetParameterValue(pComponentCache,cParam_NrOfSmpl,dSmpl,0,iActLevel,true);
00127 SessionAccessor::GetParameterValue(pComponentCache,cParam_NrOfBins,lNrOfBins,0,iActLevel,true);
00128 SessionAccessor::GetParameterValue(pComponentCache,cParam_AbsoluteSamples,bAbsolute,0,iActLevel,true);
00129 SessionAccessor::GetParameterValue(pComponentCache,cParam_UseAllSamples,bAll);
00130 }
00131 catchAllNPassMacro("Error while retrieving parameter values.");
00132
00133 unsigned long lNrOfSmpl = static_cast<unsigned long>(dSmpl);
00134
00135 if (!bAll && !bAbsolute)
00136 {
00137 if (dSmpl<0) throwCtrlExceptionMacro("","Relative number of samples must not be lesser then 0(0%). Pleas check setup. Current value: "<<dSmpl);
00138 if (dSmpl>1) throwCtrlExceptionMacro("","Relative number of samples must not be greater then 1 (100%). Pleas check setup. Current value: "<<dSmpl);
00139
00140 typedef TImageType InternalImageType;
00141
00142 SessionAccessor::GenericMediaPointer smpGenericSampleImage = SessionAccessor::GetLinkedMedia(MediaID_sampleImage,pComponentCache,pSessionInfo);
00143 if (smpGenericSampleImage.IsNull()) throwCtrlExceptionMacro("","Cannot compute number of samples. No sample image linked. Please check media linkage.");
00144
00145 InternalImageType* pSampleImage = 0;
00146
00147 try
00148 {
00149 pSampleImage = dynamic_cast<InternalImageType*>(smpGenericSampleImage.GetPointer());
00150 }
00151 catchAllNPassMacro("Error while casting sample image");
00152 if (!pSampleImage) throwCtrlExceptionMacro("","Error while casting sample image.");
00153
00154 lNrOfSmpl = static_cast<unsigned long>(pSampleImage->GetLargestPossibleRegion().GetNumberOfPixels()*(dSmpl));
00155 }
00156 else if (!bAbsolute)
00157 {
00158 if (dSmpl<0) throwCtrlExceptionMacro("","Absolute number of samples must not be lesser then 0. Pleas check setup. Current value: "<<dSmpl);
00159 };
00160
00161 pMainComponent->SetNumberOfSpatialSamples(lNrOfSmpl);
00162 pMainComponent->SetNumberOfHistogramBins(lNrOfBins);
00163 pMainComponent->SetUseAllPixels(bAll);
00164
00165 if (iActLevel == 0)
00166 {
00167 try
00168 {
00169 Parameter::Pointer smpParamUseSeed = SessionAccessor::GetParameter(pComponentCache,cParam_UseInitialSeed);
00170 if (smpParamUseSeed.IsNotNull())
00171 {
00172 bool bUseSeed;
00173 smpParamUseSeed->GetParameterValue(bUseSeed);
00174
00175 int iSeed;
00176
00177 if (bUseSeed)
00178 {
00179 SessionAccessor::GetParameterValue(pComponentCache,cParam_InitialSeed,iSeed,0,iActLevel,true);
00180 pMainComponent->ReinitializeSeed(iSeed);
00181 }
00182 }
00183 }
00184 catchAllNPassMacro("Error while initializing random generator with seed.");
00185 }
00186 }
00187
00188 void
00189 SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia, ComponentType* pComponent, SessionComponentCache* pComponentCache,
00190 SessionInfo* pSessionInfo) const
00191 {
00192 if (mediaID == MediaID_sampleImage)
00193 {
00194
00195 }
00196 else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00197 };
00198
00199 };
00200
00201 template <class TImageType>
00202 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00203 ::cParam_NrOfSmpl = "NrOfSmpl";
00204 template <class TImageType>
00205 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00206 ::cParamDsc_NrOfSmpl = "Number of samples used by the metric. If SampleAbsolute is false, this value indicates the percentage of the pixel count of sampleImage that will be used.";
00207
00208 template <class TImageType>
00209 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00210 ::cParam_NrOfBins = "NrOfBins";
00211 template <class TImageType>
00212 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00213 ::cParamDsc_NrOfBins = "Number of histogram bins used for calculating the mi.";
00214
00215 template <class TImageType>
00216 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00217 ::cParam_AbsoluteSamples = "AbsoluteSamples";
00218 template <class TImageType>
00219 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00220 ::cParamDsc_AbsoluteSamples = "Indicates if NrOfSmpl is the absolut number of samples (true) or the percentage (0...1 : 0%...100%) of the pixels of sampleImage (false) that should be used.";
00221
00222 template <class TImageType>
00223 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00224 ::cParam_UseAllSamples = "UseAllSamples";
00225 template <class TImageType>
00226 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00227 ::cParamDsc_UseAllSamples = "If true all pixels of the image will be used as samples. Does not require sampleImage.";
00228
00229 template <class TImageType>
00230 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00231 ::MediaID_sampleImage = "sampleImage";
00232 template <class TImageType>
00233 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00234 ::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.";
00235
00236 template <class TImageType>
00237 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00238 ::cParam_UseInitialSeed = "UseInitialSeed";
00239 template <class TImageType>
00240 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00241 ::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.";
00242
00243 template <class TImageType>
00244 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00245 ::cParam_InitialSeed = "InitialSeed";
00246 template <class TImageType>
00247 const char* const MattesMutualInformationMetricControllerBase<TImageType>
00248 ::cParamDsc_InitialSeed = "The seed for the random generator used to draw the samples.";
00249
00259 freControllerIDMacro(MattesMutualInformation2DMetricController, "Mattes Mutual Information 2D Metric");
00260 class MattesMutualInformation2DMetricController : public MattesMutualInformationMetricControllerBase<InternalImage2DType>
00261 {
00262 public:
00263 itkTypeMacro(MattesMutualInformation2DMetricController, MattesMutualInformationMetricControllerBase);
00264
00265 MattesMutualInformation2DMetricController();
00266 };
00267
00277 freControllerIDMacro(MattesMutualInformation3DMetricController, "Mattes Mutual Information 3D Metric");
00278 class MattesMutualInformation3DMetricController : public MattesMutualInformationMetricControllerBase<InternalImage3DType>
00279 {
00280 public:
00281 itkTypeMacro(MattesMutualInformation3DMetricController, MattesMutualInformationMetricControllerBase);
00282
00283 MattesMutualInformation3DMetricController();
00284 };
00285
00286 }
00287
00288 #endif