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
00185
00186
00187
00188
00190 void SetMetric(MetricBaseTypePointer MP) { m_Metric=MP; };
00191
00193 void SetMovingImage(MovingType* R)
00194 {
00195 m_RefImage = R;
00196 m_RefSize=m_RefImage->GetLargestPossibleRegion().GetSize();
00197 };
00198
00199 void SetMetricMovingImage(MovingType* R)
00200 {
00201 m_Metric->SetMovingImage( R );
00202 m_RefSize=R->GetLargestPossibleRegion().GetSize();
00203 };
00204
00206 void SetFixedImage(FixedType* T)
00207 {
00208 m_TarImage=T;
00209 m_TarSize=T->GetLargestPossibleRegion().GetSize();
00210 };
00211 void SetMetricFixedImage(FixedType* T)
00212 {
00213 m_Metric->SetFixedImage( T ) ;
00214 m_TarSize=T->GetLargestPossibleRegion().GetSize();
00215 };
00216
00217
00218 MovingPointer GetMovingImage() { return m_RefImage; };
00219 FixedPointer GetFixedImage() { return m_TarImage; };
00220
00222 void SetMetricRadius(MovingRadiusType T) {m_MetricRadius = T; };
00224 MovingRadiusType GetMetricRadius() { return m_MetricRadius; };
00225
00230 void SetNumberOfIntegrationPoints(unsigned int i){ m_NumberOfIntegrationPoints=i;}
00231 unsigned int GetNumberOfIntegrationPoints(){ return m_NumberOfIntegrationPoints;}
00232
00236 void SetSign(Float s) {m_Sign=s;}
00237
00239 void SetTemp(Float s) {m_Temp=s;}
00240
00241
00243 void SetGamma(Float s) {m_Gamma=s;}
00244
00245 void SetSolution(Solution::ConstPointer ptr) { m_Solution=ptr; }
00246 Solution::ConstPointer GetSolution() { return m_Solution; }
00247
00251 Float GetMetric (VectorType InVec);
00252 VectorType GetPolynomialFitToMetric(VectorType PositionInElement, VectorType SolutionAtPosition);
00253
00254 VectorType MetricFiniteDiff(VectorType PositionInElement, VectorType SolutionAtPosition);
00255
00256
00257 Float GetSolution(unsigned int i,unsigned int which=0)
00258 {
00259 return m_Solution->GetSolutionValue(i,which);
00260 }
00261
00262
00263
00264
00265 void InitializeMetric(void);
00266 ImageMetricLoad();
00267 Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0);
00268
00272 VectorType Fe1(VectorType);
00273 VectorType Fe(VectorType,VectorType);
00274
00275 static Baseclass* NewImageMetricLoad(void)
00276 { return new ImageMetricLoad; }
00277
00278
00280
00281 void SetMetricGradientImage(GradientImageType* g) { m_MetricGradientImage=g;}
00282 GradientImageType* GetMetricGradientImage() { return m_MetricGradientImage;}
00283
00284
00285 void PrintCurrentEnergy(){ std:: cout << " energy " << m_Energy << std::endl;}
00286 double GetCurrentEnergy() { return m_Energy; }
00287 void SetCurrentEnergy( double e ) { m_Energy=e; }
00288
00289 protected:
00290
00291
00292 private:
00293 GradientImageType* m_MetricGradientImage;
00294 MovingPointer m_RefImage;
00295 FixedPointer m_TarImage;
00296 MovingRadiusType m_MetricRadius;
00297 typename MovingType::SizeType m_RefSize;
00298 typename FixedType::SizeType m_TarSize;
00299 unsigned int m_NumberOfIntegrationPoints;
00300 unsigned int m_SolutionIndex;
00301 unsigned int m_SolutionIndex2;
00302 Float m_Sign;
00303 Float m_Temp;
00304 Float m_Gamma;
00305
00306 typename Solution::ConstPointer m_Solution;
00307 MetricBaseTypePointer m_Metric;
00308 typename TransformBaseType::Pointer m_Transform;
00309 typename InterpolatorType::Pointer m_Interpolator;
00310
00311 mutable double m_Energy;
00312 private:
00315 static const int DummyCLID;
00316
00317 };
00318
00319
00320
00321
00322 }}
00323
00324 #ifndef ITK_MANUAL_INSTANTIATION
00325 #include "itkFEMImageMetricLoad.txx"
00326 #endif
00327
00328 #endif