00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkImageToImageMetric_h
00018 #define __itkImageToImageMetric_h
00019
00020 #include "itkImageBase.h"
00021 #include "itkTransform.h"
00022 #include "itkInterpolateImageFunction.h"
00023 #include "itkSingleValuedCostFunction.h"
00024 #include "itkExceptionObject.h"
00025 #include "itkGradientRecursiveGaussianImageFilter.h"
00026 #include "itkSpatialObject.h"
00027
00028 namespace itk
00029 {
00030
00050 template <class TFixedImage, class TMovingImage>
00051 class ITK_EXPORT ImageToImageMetric : public SingleValuedCostFunction
00052 {
00053 public:
00055 typedef ImageToImageMetric Self;
00056 typedef SingleValuedCostFunction Superclass;
00057 typedef SmartPointer<Self> Pointer;
00058 typedef SmartPointer<const Self> ConstPointer;
00059
00061 typedef Superclass::ParametersValueType CoordinateRepresentationType;
00062
00064 itkTypeMacro(ImageToImageMetric, SingleValuedCostFunction);
00065
00067 typedef TMovingImage MovingImageType;
00068 typedef typename TMovingImage::PixelType MovingImagePixelType;
00069 typedef typename MovingImageType::ConstPointer MovingImageConstPointer;
00070
00072 typedef TFixedImage FixedImageType;
00073 typedef typename FixedImageType::ConstPointer FixedImageConstPointer;
00074 typedef typename FixedImageType::RegionType FixedImageRegionType;
00075
00077 itkStaticConstMacro(MovingImageDimension, unsigned int,
00078 TMovingImage::ImageDimension);
00079 itkStaticConstMacro(FixedImageDimension, unsigned int,
00080 TFixedImage::ImageDimension);
00082
00084 typedef Transform<CoordinateRepresentationType,
00085 itkGetStaticConstMacro(MovingImageDimension),
00086 itkGetStaticConstMacro(FixedImageDimension)> TransformType;
00087
00088 typedef typename TransformType::Pointer TransformPointer;
00089 typedef typename TransformType::InputPointType InputPointType;
00090 typedef typename TransformType::OutputPointType OutputPointType;
00091 typedef typename TransformType::ParametersType TransformParametersType;
00092 typedef typename TransformType::JacobianType TransformJacobianType;
00093
00095 typedef InterpolateImageFunction<
00096 MovingImageType,
00097 CoordinateRepresentationType > InterpolatorType;
00098
00099
00101 typedef typename NumericTraits<MovingImagePixelType>::RealType RealType;
00102 typedef CovariantVector<RealType,
00103 itkGetStaticConstMacro(MovingImageDimension)> GradientPixelType;
00104 typedef Image<GradientPixelType,
00105 itkGetStaticConstMacro(MovingImageDimension)> GradientImageType;
00106 typedef SmartPointer<GradientImageType> GradientImagePointer;
00107 typedef GradientRecursiveGaussianImageFilter< MovingImageType,
00108 GradientImageType >
00109 GradientImageFilterType;
00110 typedef typename GradientImageFilterType::Pointer GradientImageFilterPointer;
00112
00113
00114 typedef typename InterpolatorType::Pointer InterpolatorPointer;
00115
00116
00117
00120 typedef SpatialObject< itkGetStaticConstMacro(FixedImageDimension)
00121 > FixedImageMaskType;
00122 typedef typename FixedImageMaskType::Pointer FixedImageMaskPointer;
00123
00126 typedef SpatialObject< itkGetStaticConstMacro(MovingImageDimension)
00127 > MovingImageMaskType;
00128 typedef typename MovingImageMaskType::Pointer MovingImageMaskPointer;
00129
00130
00131
00133 typedef Superclass::MeasureType MeasureType;
00134
00136 typedef Superclass::DerivativeType DerivativeType;
00137
00139 typedef Superclass::ParametersType ParametersType;
00140
00142 itkSetConstObjectMacro( FixedImage, FixedImageType );
00143
00145 itkGetConstObjectMacro( FixedImage, FixedImageType );
00146
00148 itkSetConstObjectMacro( MovingImage, MovingImageType );
00149
00151 itkGetConstObjectMacro( MovingImage, MovingImageType );
00152
00154 itkSetObjectMacro( Transform, TransformType );
00155
00157 itkGetConstObjectMacro( Transform, TransformType );
00158
00160 itkSetObjectMacro( Interpolator, InterpolatorType );
00161
00163 itkGetConstObjectMacro( Interpolator, InterpolatorType );
00164
00166 itkGetConstReferenceMacro( NumberOfPixelsCounted, unsigned long );
00167
00169 itkSetMacro( FixedImageRegion, FixedImageRegionType );
00170
00172 itkGetConstReferenceMacro( FixedImageRegion, FixedImageRegionType );
00173
00175 itkSetObjectMacro( MovingImageMask, MovingImageMaskType );
00176 itkGetConstObjectMacro( MovingImageMask, MovingImageMaskType );
00178
00180 itkSetObjectMacro( FixedImageMask, FixedImageMaskType );
00181 itkGetConstObjectMacro( FixedImageMask, FixedImageMaskType );
00183
00185 itkSetMacro( ComputeGradient, bool);
00186 itkGetConstReferenceMacro( ComputeGradient, bool);
00187 itkBooleanMacro(ComputeGradient);
00189
00191 virtual void ComputeGradient();
00192
00194 itkGetConstObjectMacro( GradientImage, GradientImageType );
00195
00197 void SetTransformParameters( const ParametersType & parameters ) const;
00198
00200 unsigned int GetNumberOfParameters(void) const
00201 { return m_Transform->GetNumberOfParameters(); }
00202
00205 virtual void Initialize(void) throw ( ExceptionObject );
00206
00207 protected:
00208 ImageToImageMetric();
00209 virtual ~ImageToImageMetric() {};
00210 void PrintSelf(std::ostream& os, Indent indent) const;
00211
00212 mutable unsigned long m_NumberOfPixelsCounted;
00213
00214 FixedImageConstPointer m_FixedImage;
00215 MovingImageConstPointer m_MovingImage;
00216
00217 mutable TransformPointer m_Transform;
00218 InterpolatorPointer m_Interpolator;
00219
00220 bool m_ComputeGradient;
00221 GradientImagePointer m_GradientImage;
00222
00223 mutable FixedImageMaskPointer m_FixedImageMask;
00224 mutable MovingImageMaskPointer m_MovingImageMask;
00225
00226 private:
00227 ImageToImageMetric(const Self&);
00228 void operator=(const Self&);
00229
00230 FixedImageRegionType m_FixedImageRegion;
00231
00232
00233 };
00234
00235 }
00236
00237 #ifndef ITK_MANUAL_INSTANTIATION
00238 #include "itkImageToImageMetric.txx"
00239 #endif
00240
00241 #endif
00242
00243
00244
00245