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 <itkMeanSquaresImageToImageMetric.h>
00059 #include <itkNormalizedCorrelationImageToImageMetric.h>
00060 #include <itkPatternIntensityImageToImageMetric.h>
00061
00062
00063 namespace itk
00064 {
00065 namespace fem
00066 {
00067
00091 template<class TReference,class TTarget>
00092 class ImageMetricLoad : public LoadElement
00093 {
00094 FEM_CLASS(ImageMetricLoad,LoadElement)
00095 public:
00096
00097
00098 typedef typename LoadElement::Float Float;
00099
00100 typedef TReference ReferenceType;
00101 typedef typename ReferenceType::ConstPointer ReferenceConstPointer;
00102 typedef ReferenceType* ReferencePointer;
00103 typedef TTarget TargetType;
00104 typedef TargetType* TargetPointer;
00105 typedef typename TargetType::ConstPointer TargetConstPointer;
00106
00108 itkStaticConstMacro(ImageDimension, unsigned int,
00109 ReferenceType::ImageDimension);
00110
00111 typedef ImageRegionIteratorWithIndex<ReferenceType> RefRegionIteratorType;
00112 typedef ImageRegionIteratorWithIndex<TargetType> TarRegionIteratorType;
00113
00114 typedef NeighborhoodIterator<ReferenceType>
00115 ReferenceNeighborhoodIteratorType;
00116 typedef typename ReferenceNeighborhoodIteratorType::IndexType
00117 ReferenceNeighborhoodIndexType;
00118 typedef typename ReferenceNeighborhoodIteratorType::RadiusType
00119 ReferenceRadiusType;
00120 typedef NeighborhoodIterator<TargetType>
00121 TargetNeighborhoodIteratorType;
00122 typedef typename TargetNeighborhoodIteratorType::IndexType
00123 TargetNeighborhoodIndexType;
00124 typedef typename TargetNeighborhoodIteratorType::RadiusType
00125 TargetRadiusType;
00126
00127
00128 typedef typename ReferenceType::PixelType RefPixelType;
00129 typedef typename TargetType::PixelType TarPixelType;
00130 typedef Float PixelType;
00131 typedef Float ComputationType;
00132 typedef Image< RefPixelType, itkGetStaticConstMacro(ImageDimension) > RefImageType;
00133 typedef Image< TarPixelType, itkGetStaticConstMacro(ImageDimension) > TarImageType;
00134 typedef Image< PixelType, itkGetStaticConstMacro(ImageDimension) > ImageType;
00135 typedef vnl_vector<Float> VectorType;
00136
00137
00138
00139
00140
00141
00142 typedef double CoordinateRepresentationType;
00143 typedef Transform< CoordinateRepresentationType,itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > TransformBaseType;
00144 typedef TranslationTransform<CoordinateRepresentationType, itkGetStaticConstMacro(ImageDimension) > DefaultTransformType;
00145
00147 typedef ImageToImageMetric<TargetType,ReferenceType > MetricBaseType;
00148 typedef typename MetricBaseType::Pointer MetricBaseTypePointer;
00149
00150 typedef MutualInformationImageToImageMetric< ReferenceType, TargetType > MutualInformationMetricType;
00151
00152 typedef MeanSquaresImageToImageMetric< ReferenceType, TargetType > MeanSquaresMetricType;
00153
00154 typedef NormalizedCorrelationImageToImageMetric< ReferenceType, TargetType > NormalizedCorrelationMetricType;
00155
00156 typedef PatternIntensityImageToImageMetric< ReferenceType, TargetType > PatternIntensityMetricType;
00157
00158
00159
00160
00161 typedef MeanSquaresMetricType DefaultMetricType;
00162 typedef typename DefaultTransformType::ParametersType ParametersType;
00163 typedef typename DefaultTransformType::JacobianType JacobianType;
00164
00165
00166
00167
00168
00169 typedef LinearInterpolateImageFunction< ReferenceType, double > InterpolatorType;
00170
00172 typedef float RealType;
00173 typedef CovariantVector<RealType,
00174 itkGetStaticConstMacro(ImageDimension)> GradientPixelType;
00175 typedef Image<GradientPixelType,
00176 itkGetStaticConstMacro(ImageDimension)> GradientImageType;
00177 typedef SmartPointer<GradientImageType> GradientImagePointer;
00178 typedef GradientRecursiveGaussianImageFilter< ImageType,
00179 GradientImageType >
00180 GradientImageFilterType;
00181
00182
00183
00184
00185
00187 void SetMetric(MetricBaseTypePointer MP) { m_Metric=MP; };
00188
00190 void SetReferenceImage(ReferenceType* R)
00191 {
00192 m_RefImage = R;
00193 m_RefSize=m_RefImage->GetLargestPossibleRegion().GetSize();
00194 };
00195
00196 void SetMetricReferenceImage(ReferenceType* R)
00197 {
00198 m_Metric->SetMovingImage( R );
00199 m_RefSize=R->GetLargestPossibleRegion().GetSize();
00200 };
00201
00203 void SetTargetImage(TargetType* T)
00204 {
00205 m_TarImage=T;
00206 m_TarSize=T->GetLargestPossibleRegion().GetSize();
00207 };
00208 void SetMetricTargetImage(TargetType* T)
00209 {
00210 m_Metric->SetFixedImage( T ) ;
00211 m_TarSize=T->GetLargestPossibleRegion().GetSize();
00212 };
00213
00214
00215 ReferencePointer GetReferenceImage() { return m_RefImage; };
00216 TargetPointer GetTargetImage() { return m_TarImage; };
00217
00219 void SetMetricRadius(ReferenceRadiusType T) {m_MetricRadius = T; };
00221 ReferenceRadiusType GetMetricRadius() { return m_MetricRadius; };
00222
00227 void SetNumberOfIntegrationPoints(unsigned int i){ m_NumberOfIntegrationPoints=i;}
00228 unsigned int GetNumberOfIntegrationPoints(){ return m_NumberOfIntegrationPoints;}
00229
00233 void SetSign(Float s) {m_Sign=s;}
00234
00236 void SetTemp(Float s) {m_Temp=s;}
00237
00238
00240 void SetGamma(Float s) {m_Gamma=s;}
00241
00242 void SetSolution(Solution::ConstPointer ptr) { m_Solution=ptr; }
00243 Solution::ConstPointer GetSolution() { return m_Solution; }
00244
00248 Float GetMetric (VectorType InVec);
00249 VectorType GetPolynomialFitToMetric(VectorType PositionInElement, VectorType SolutionAtPosition);
00250
00251 VectorType MetricFiniteDiff(VectorType PositionInElement, VectorType SolutionAtPosition);
00252
00253
00254 Float GetSolution(unsigned int i,unsigned int which=0)
00255 {
00256 return m_Solution->GetSolutionValue(i,which);
00257 }
00258
00259
00260
00261
00262 void InitializeMetric(void);
00263 ImageMetricLoad();
00264 Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0);
00265
00269 VectorType Fe1(VectorType);
00270 VectorType Fe(VectorType,VectorType);
00271
00272 static Baseclass* NewImageMetricLoad(void)
00273 { return new ImageMetricLoad; }
00274
00275
00277
00278 void SetMetricGradientImage(GradientImageType* g) { m_MetricGradientImage=g;}
00279 GradientImageType* GetMetricGradientImage() { return m_MetricGradientImage;}
00280
00281
00282 protected:
00283
00284
00285 private:
00286 GradientImageType* m_MetricGradientImage;
00287 ReferencePointer m_RefImage;
00288 TargetPointer m_TarImage;
00289 ReferenceRadiusType m_MetricRadius;
00290 typename ReferenceType::SizeType m_RefSize;
00291 typename TargetType::SizeType m_TarSize;
00292 unsigned int m_NumberOfIntegrationPoints;
00293 unsigned int m_SolutionIndex;
00294 unsigned int m_SolutionIndex2;
00295 Float m_Sign;
00296 Float m_Temp;
00297 Float m_Gamma;
00298
00299 typename Solution::ConstPointer m_Solution;
00300 MetricBaseTypePointer m_Metric;
00301 typename TransformBaseType::Pointer m_Transform;
00302 typename InterpolatorType::Pointer m_Interpolator;
00303
00304 private:
00307 static const int DummyCLID;
00308
00309 };
00310
00311
00312
00313
00314 }}
00315
00316 #ifndef ITK_MANUAL_INSTANTIATION
00317 #include "itkFEMImageMetricLoad.txx"
00318 #endif
00319
00320 #endif