itkFEMImageMetricLoad.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkFEMImageMetricLoad_h
00018 #define __itkFEMImageMetricLoad_h
00019
00020 #include "itkFEMLoadElementBase.h"
00021
00022 #include "itkImage.h"
00023 #include "itkTranslationTransform.h"
00024
00025 #include "itkImageRegionIteratorWithIndex.h"
00026 #include "itkNeighborhoodIterator.h"
00027 #include "itkNeighborhoodIterator.h"
00028 #include "itkNeighborhoodInnerProduct.h"
00029 #include "itkDerivativeOperator.h"
00030 #include "itkForwardDifferenceOperator.h"
00031 #include "itkLinearInterpolateImageFunction.h"
00032 #include "vnl/vnl_math.h"
00033
00034 #include <itkMutualInformationImageToImageMetric.h>
00035 #include <itkMattesMutualInformationImageToImageMetric.h>
00036 #include <itkMeanSquaresImageToImageMetric.h>
00037 #include <itkNormalizedCorrelationImageToImageMetric.h>
00038
00039
00040
00041 namespace itk
00042 {
00043 namespace fem
00044 {
00045
00069 template<class TMoving,class TFixed>
00070 class ImageMetricLoad : public LoadElement
00071 {
00072 FEM_CLASS(ImageMetricLoad,LoadElement)
00073 public:
00074
00075
00076 typedef typename LoadElement::Float Float;
00077
00078 typedef TMoving MovingType;
00079 typedef typename MovingType::ConstPointer MovingConstPointer;
00080 typedef MovingType* MovingPointer;
00081 typedef TFixed FixedType;
00082 typedef FixedType* FixedPointer;
00083 typedef typename FixedType::ConstPointer FixedConstPointer;
00084
00086 itkStaticConstMacro(ImageDimension, unsigned int,
00087 MovingType::ImageDimension);
00088
00089 typedef ImageRegionIteratorWithIndex<MovingType> RefRegionIteratorType;
00090 typedef ImageRegionIteratorWithIndex<FixedType> TarRegionIteratorType;
00091
00092
00093 typedef NeighborhoodIterator<MovingType>
00094 MovingNeighborhoodIteratorType;
00095 typedef typename MovingNeighborhoodIteratorType::IndexType
00096 MovingNeighborhoodIndexType;
00097 typedef typename MovingNeighborhoodIteratorType::RadiusType
00098 MovingRadiusType;
00099 typedef NeighborhoodIterator<FixedType>
00100 FixedNeighborhoodIteratorType;
00101 typedef typename FixedNeighborhoodIteratorType::IndexType
00102 FixedNeighborhoodIndexType;
00103 typedef typename FixedNeighborhoodIteratorType::RadiusType
00104 FixedRadiusType;
00105
00106
00107
00108 typedef typename MovingType::PixelType RefPixelType;
00109 typedef typename FixedType::PixelType TarPixelType;
00110 typedef Float PixelType;
00111 typedef Float ComputationType;
00112 typedef Image< RefPixelType, itkGetStaticConstMacro(ImageDimension) > RefImageType;
00113 typedef Image< TarPixelType, itkGetStaticConstMacro(ImageDimension) > TarImageType;
00114 typedef Image< PixelType, itkGetStaticConstMacro(ImageDimension) > ImageType;
00115 typedef vnl_vector<Float> VectorType;
00116
00117
00118
00119
00120
00121
00122 typedef double CoordinateRepresentationType;
00123 typedef Transform< CoordinateRepresentationType,itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > TransformBaseType;
00124 typedef TranslationTransform<CoordinateRepresentationType, itkGetStaticConstMacro(ImageDimension) > DefaultTransformType;
00125
00127 typedef ImageToImageMetric<FixedType,MovingType > MetricBaseType;
00128 typedef typename MetricBaseType::Pointer MetricBaseTypePointer;
00129
00130 typedef MutualInformationImageToImageMetric< MovingType, FixedType > MutualInformationMetricType;
00131
00132 typedef MeanSquaresImageToImageMetric< MovingType, FixedType > MeanSquaresMetricType;
00133
00134 typedef NormalizedCorrelationImageToImageMetric< MovingType, FixedType > NormalizedCorrelationMetricType;
00135
00136 typedef MeanSquaresMetricType DefaultMetricType;
00137 typedef typename DefaultTransformType::ParametersType ParametersType;
00138 typedef typename DefaultTransformType::JacobianType JacobianType;
00139
00140
00141
00142
00143
00144 typedef LinearInterpolateImageFunction< MovingType, double > InterpolatorType;
00145
00147 typedef float RealType;
00148 typedef CovariantVector<RealType,
00149 itkGetStaticConstMacro(ImageDimension)> GradientPixelType;
00150 typedef Image<GradientPixelType,
00151 itkGetStaticConstMacro(ImageDimension)> GradientImageType;
00152 typedef SmartPointer<GradientImageType> GradientImagePointer;
00153 typedef GradientRecursiveGaussianImageFilter< ImageType,
00154 GradientImageType >
00155 GradientImageFilterType;
00156
00158
00159
00160
00161
00163 void SetMetric(MetricBaseTypePointer MP)
00164 { m_Metric=MP; }
00165
00167 void SetMovingImage(MovingType* R)
00168 {
00169 m_RefImage = R;
00170 m_RefSize=m_RefImage->GetLargestPossibleRegion().GetSize();
00171 }
00173
00174 void SetMetricMovingImage(MovingType* R)
00175 {
00176 m_Metric->SetMovingImage( R );
00177 m_RefSize=R->GetLargestPossibleRegion().GetSize();
00178 }
00179
00181 void SetFixedImage(FixedType* T)
00182 {
00183 m_TarImage=T;
00184 m_TarSize=T->GetLargestPossibleRegion().GetSize();
00185 }
00186 void SetMetricFixedImage(FixedType* T)
00187 {
00188 m_Metric->SetFixedImage( T );
00189 m_TarSize=T->GetLargestPossibleRegion().GetSize();
00190 }
00192
00193 MovingPointer GetMovingImage()
00194 { return m_RefImage; }
00195 FixedPointer GetFixedImage() { return m_TarImage; }
00196
00198 void SetMetricRadius(MovingRadiusType T) {m_MetricRadius = T; }
00199
00201 MovingRadiusType GetMetricRadius() { return m_MetricRadius; }
00202
00207 void SetNumberOfIntegrationPoints(unsigned int i)
00208 { m_NumberOfIntegrationPoints=i;}
00209 unsigned int GetNumberOfIntegrationPoints()
00210 { return m_NumberOfIntegrationPoints;}
00212
00216 void SetSign(Float s)
00217 {m_Sign=s;}
00218
00220 void SetTemp(Float s)
00221 {m_Temp=s;}
00222
00224 void SetGamma(Float s)
00225 {m_Gamma=s;}
00226
00227 void SetSolution(Solution::ConstPointer ptr)
00228 { m_Solution=ptr; }
00229 Solution::ConstPointer GetSolution()
00230 { return m_Solution; }
00231
00235 Float GetMetric (VectorType InVec);
00236 VectorType GetPolynomialFitToMetric(VectorType PositionInElement, VectorType SolutionAtPosition);
00238
00239 VectorType MetricFiniteDiff(VectorType PositionInElement, VectorType SolutionAtPosition);
00240
00241
00242 Float GetSolution(unsigned int i,unsigned int which=0)
00243 {
00244 return m_Solution->GetSolutionValue(i,which);
00245 }
00246
00247
00248
00249
00250 void InitializeMetric(void);
00251 ImageMetricLoad();
00252 Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0);
00253
00257 VectorType Fe1(VectorType);
00258 VectorType Fe(VectorType,VectorType);
00260
00261 static Baseclass* NewImageMetricLoad(void)
00262 { return new ImageMetricLoad; }
00263
00265
00266 void SetMetricGradientImage(GradientImageType* g)
00267 { m_MetricGradientImage=g;}
00268 GradientImageType* GetMetricGradientImage()
00269 { return m_MetricGradientImage;}
00271
00272
00273 void PrintCurrentEnergy()
00274 { std:: cout << " energy " << m_Energy << std::endl;}
00275 double GetCurrentEnergy()
00276 { return m_Energy; }
00277 void SetCurrentEnergy( double e )
00278 { m_Energy=e; }
00279
00280 protected:
00281
00282
00283 private:
00284 GradientImageType* m_MetricGradientImage;
00285 MovingPointer m_RefImage;
00286 FixedPointer m_TarImage;
00288 typename MovingType::SizeType m_RefSize;
00289 typename FixedType::SizeType m_TarSize;
00290 unsigned int m_NumberOfIntegrationPoints;
00291 unsigned int m_SolutionIndex;
00292 unsigned int m_SolutionIndex2;
00293 Float m_Sign;
00294 Float m_Temp;
00295 Float m_Gamma;
00296
00297 typename Solution::ConstPointer m_Solution;
00298 MetricBaseTypePointer m_Metric;
00299 typename TransformBaseType::Pointer m_Transform;
00300 typename InterpolatorType::Pointer m_Interpolator;
00301
00302 mutable double m_Energy;
00303 private:
00306 static const int m_DummyCLID;
00307
00308 };
00309
00310 }}
00311
00312 #ifndef ITK_MANUAL_INSTANTIATION
00313 #include "itkFEMImageMetricLoad.txx"
00314 #endif
00315
00316 #endif
00317