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
00036
00037
00038
00039
00040 #ifndef _itkFEMImageMetricLoad_h_
00041 #define _itkFEMImageMetricLoad_h_
00042
00043 #include "itkFEMLoadElementBase.h"
00044
00045 #include "itkImage.h"
00046 #include "itkTranslationTransform.h"
00047
00048 #include "itkImageRegionIteratorWithIndex.h"
00049 #include "itkNeighborhoodIterator.h"
00050 #include "itkNeighborhoodIterator.h"
00051 #include "itkNeighborhoodInnerProduct.h"
00052 #include "itkDerivativeOperator.h"
00053 #include "itkForwardDifferenceOperator.h"
00054 #include "itkLinearInterpolateImageFunction.h"
00055 #include "vnl/vnl_math.h"
00056
00057 #include <itkMutualInformationImageToImageMetric.h>
00058 #include <itkMattesMutualInformationImageToImageMetric.h>
00059 #include <itkMeanSquaresImageToImageMetric.h>
00060 #include <itkNormalizedCorrelationImageToImageMetric.h>
00061
00062
00063
00064 namespace itk
00065 {
00066 namespace fem
00067 {
00068
00092 template<class TMoving,class TFixed>
00093 class ImageMetricLoad : public LoadElement
00094 {
00095 FEM_CLASS(ImageMetricLoad,LoadElement)
00096 public:
00097
00098
00099 typedef typename LoadElement::Float Float;
00100
00101 typedef TMoving MovingType;
00102 typedef typename MovingType::ConstPointer MovingConstPointer;
00103 typedef MovingType* MovingPointer;
00104 typedef TFixed FixedType;
00105 typedef FixedType* FixedPointer;
00106 typedef typename FixedType::ConstPointer FixedConstPointer;
00107
00109 itkStaticConstMacro(ImageDimension, unsigned int,
00110 MovingType::ImageDimension);
00111
00112 typedef ImageRegionIteratorWithIndex<MovingType> RefRegionIteratorType;
00113 typedef ImageRegionIteratorWithIndex<FixedType> TarRegionIteratorType;
00114
00115
00116 typedef NeighborhoodIterator<MovingType>
00117 MovingNeighborhoodIteratorType;
00118 typedef typename MovingNeighborhoodIteratorType::IndexType
00119 MovingNeighborhoodIndexType;
00120 typedef typename MovingNeighborhoodIteratorType::RadiusType
00121 MovingRadiusType;
00122 typedef NeighborhoodIterator<FixedType>
00123 FixedNeighborhoodIteratorType;
00124 typedef typename FixedNeighborhoodIteratorType::IndexType
00125 FixedNeighborhoodIndexType;
00126 typedef typename FixedNeighborhoodIteratorType::RadiusType
00127 FixedRadiusType;
00128
00129
00130
00131 typedef typename MovingType::PixelType RefPixelType;
00132 typedef typename FixedType::PixelType TarPixelType;
00133 typedef Float PixelType;
00134 typedef Float ComputationType;
00135 typedef Image< RefPixelType, itkGetStaticConstMacro(ImageDimension) > RefImageType;
00136 typedef Image< TarPixelType, itkGetStaticConstMacro(ImageDimension) > TarImageType;
00137 typedef Image< PixelType, itkGetStaticConstMacro(ImageDimension) > ImageType;
00138 typedef vnl_vector<Float> VectorType;
00139
00140
00141
00142
00143
00144
00145 typedef double CoordinateRepresentationType;
00146 typedef Transform< CoordinateRepresentationType,itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > TransformBaseType;
00147 typedef TranslationTransform<CoordinateRepresentationType, itkGetStaticConstMacro(ImageDimension) > DefaultTransformType;
00148
00150 typedef ImageToImageMetric<FixedType,MovingType > MetricBaseType;
00151 typedef typename MetricBaseType::Pointer MetricBaseTypePointer;
00152
00153 typedef MutualInformationImageToImageMetric< MovingType, FixedType > MutualInformationMetricType;
00154
00155 typedef MeanSquaresImageToImageMetric< MovingType, FixedType > MeanSquaresMetricType;
00156
00157 typedef NormalizedCorrelationImageToImageMetric< MovingType, FixedType > NormalizedCorrelationMetricType;
00158
00159
00160
00161
00162
00163
00164 typedef MeanSquaresMetricType DefaultMetricType;
00165 typedef typename DefaultTransformType::ParametersType ParametersType;
00166 typedef typename DefaultTransformType::JacobianType JacobianType;
00167
00168
00169
00170
00171
00172 typedef LinearInterpolateImageFunction< MovingType, double > InterpolatorType;
00173
00175 typedef float RealType;
00176 typedef CovariantVector<RealType,
00177 itkGetStaticConstMacro(ImageDimension)> GradientPixelType;
00178 typedef Image<GradientPixelType,
00179 itkGetStaticConstMacro(ImageDimension)> GradientImageType;
00180 typedef SmartPointer<GradientImageType> GradientImagePointer;
00181 typedef GradientRecursiveGaussianImageFilter< ImageType,
00182 GradientImageType >
00183 GradientImageFilterType;
00184
00186
00187
00188
00189
00191 void SetMetric(MetricBaseTypePointer MP) { m_Metric=MP; };
00192
00194 void SetMovingImage(MovingType* R)
00195 {
00196 m_RefImage = R;
00197 m_RefSize=m_RefImage->GetLargestPossibleRegion().GetSize();
00198 };
00200
00201 void SetMetricMovingImage(MovingType* R)
00202 {
00203 m_Metric->SetMovingImage( R );
00204 m_RefSize=R->GetLargestPossibleRegion().GetSize();
00205 };
00206
00208 void SetFixedImage(FixedType* T)
00209 {
00210 m_TarImage=T;
00211 m_TarSize=T->GetLargestPossibleRegion().GetSize();
00212 };
00213 void SetMetricFixedImage(FixedType* T)
00214 {
00215 m_Metric->SetFixedImage( T ) ;
00216 m_TarSize=T->GetLargestPossibleRegion().GetSize();
00217 };
00219
00220
00221 MovingPointer GetMovingImage() { return m_RefImage; };
00222 FixedPointer GetFixedImage() { return m_TarImage; };
00223
00225 void SetMetricRadius(MovingRadiusType T) {m_MetricRadius = T; };
00226
00228 MovingRadiusType GetMetricRadius() { return m_MetricRadius; };
00229
00234 void SetNumberOfIntegrationPoints(unsigned int i){ m_NumberOfIntegrationPoints=i;}
00235 unsigned int GetNumberOfIntegrationPoints(){ return m_NumberOfIntegrationPoints;}
00237
00241 void SetSign(Float s) {m_Sign=s;}
00242
00244 void SetTemp(Float s) {m_Temp=s;}
00245
00246
00248 void SetGamma(Float s) {m_Gamma=s;}
00249
00250 void SetSolution(Solution::ConstPointer ptr) { m_Solution=ptr; }
00251 Solution::ConstPointer GetSolution() { return m_Solution; }
00252
00256 Float GetMetric (VectorType InVec);
00257 VectorType GetPolynomialFitToMetric(VectorType PositionInElement, VectorType SolutionAtPosition);
00259
00260 VectorType MetricFiniteDiff(VectorType PositionInElement, VectorType SolutionAtPosition);
00261
00262
00263 Float GetSolution(unsigned int i,unsigned int which=0)
00264 {
00265 return m_Solution->GetSolutionValue(i,which);
00266 }
00267
00268
00269
00270
00271 void InitializeMetric(void);
00272 ImageMetricLoad();
00273 Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0);
00274
00278 VectorType Fe1(VectorType);
00279 VectorType Fe(VectorType,VectorType);
00281
00282 static Baseclass* NewImageMetricLoad(void)
00283 { return new ImageMetricLoad; }
00284
00285
00287
00288 void SetMetricGradientImage(GradientImageType* g) { m_MetricGradientImage=g;}
00289 GradientImageType* GetMetricGradientImage() { return m_MetricGradientImage;}
00291
00292
00293 void PrintCurrentEnergy(){ std:: cout << " energy " << m_Energy << std::endl;}
00294 double GetCurrentEnergy() { return m_Energy; }
00295 void SetCurrentEnergy( double e ) { m_Energy=e; }
00296
00297 protected:
00298
00299
00300 private:
00301 GradientImageType* m_MetricGradientImage;
00302 MovingPointer m_RefImage;
00303 FixedPointer m_TarImage;
00305 typename MovingType::SizeType m_RefSize;
00306 typename FixedType::SizeType m_TarSize;
00307 unsigned int m_NumberOfIntegrationPoints;
00308 unsigned int m_SolutionIndex;
00309 unsigned int m_SolutionIndex2;
00310 Float m_Sign;
00311 Float m_Temp;
00312 Float m_Gamma;
00313
00314 typename Solution::ConstPointer m_Solution;
00315 MetricBaseTypePointer m_Metric;
00316 typename TransformBaseType::Pointer m_Transform;
00317 typename InterpolatorType::Pointer m_Interpolator;
00318
00319 mutable double m_Energy;
00320 private:
00323 static const int DummyCLID;
00324
00325 };
00326
00327
00328
00329
00330 }}
00331
00332 #ifndef ITK_MANUAL_INSTANTIATION
00333 #include "itkFEMImageMetricLoad.txx"
00334 #endif
00335
00336 #endif
00337