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);
00081
00083 typedef Transform<CoordinateRepresentationType,
00084 itkGetStaticConstMacro(MovingImageDimension),
00085 itkGetStaticConstMacro(FixedImageDimension)> TransformType;
00086
00087 typedef typename TransformType::Pointer TransformPointer;
00088 typedef typename TransformType::InputPointType InputPointType;
00089 typedef typename TransformType::OutputPointType OutputPointType;
00090 typedef typename TransformType::ParametersType TransformParametersType;
00091 typedef typename TransformType::JacobianType TransformJacobianType;
00092
00094 typedef InterpolateImageFunction<
00095 MovingImageType,
00096 CoordinateRepresentationType > InterpolatorType;
00097
00098
00100 typedef typename NumericTraits<MovingImagePixelType>::RealType RealType;
00101 typedef CovariantVector<RealType,
00102 itkGetStaticConstMacro(MovingImageDimension)> GradientPixelType;
00103 typedef Image<GradientPixelType,
00104 itkGetStaticConstMacro(MovingImageDimension)> GradientImageType;
00105 typedef SmartPointer<GradientImageType> GradientImagePointer;
00106 typedef GradientRecursiveGaussianImageFilter< MovingImageType,
00107 GradientImageType >
00108 GradientImageFilterType;
00109 typedef typename GradientImageFilterType::Pointer GradientImageFilterPointer;
00110
00111
00112 typedef typename InterpolatorType::Pointer InterpolatorPointer;
00113
00114
00115
00118 typedef SpatialObject< itkGetStaticConstMacro(FixedImageDimension)
00119 > FixedImageMaskType;
00120 typedef typename FixedImageMaskType::Pointer FixedImageMaskPointer;
00121
00124 typedef SpatialObject< itkGetStaticConstMacro(MovingImageDimension)
00125 > MovingImageMaskType;
00126 typedef typename MovingImageMaskType::Pointer MovingImageMaskPointer;
00127
00128
00129
00131 typedef Superclass::MeasureType MeasureType;
00132
00134 typedef Superclass::DerivativeType DerivativeType;
00135
00137 typedef Superclass::ParametersType ParametersType;
00138
00140 itkSetConstObjectMacro( FixedImage, FixedImageType );
00141
00143 itkGetConstObjectMacro( FixedImage, FixedImageType );
00144
00146 itkSetConstObjectMacro( MovingImage, MovingImageType );
00147
00149 itkGetConstObjectMacro( MovingImage, MovingImageType );
00150
00152 itkSetObjectMacro( Transform, TransformType );
00153
00155 itkGetConstObjectMacro( Transform, TransformType );
00156
00158 itkSetObjectMacro( Interpolator, InterpolatorType );
00159
00161 itkGetConstObjectMacro( Interpolator, InterpolatorType );
00162
00164 itkGetConstReferenceMacro( NumberOfPixelsCounted, unsigned long );
00165
00167 itkSetMacro( FixedImageRegion, FixedImageRegionType );
00168
00170 itkGetConstReferenceMacro( FixedImageRegion, FixedImageRegionType );
00171
00173 itkSetObjectMacro( MovingImageMask, MovingImageMaskType );
00174 itkGetConstObjectMacro( MovingImageMask, MovingImageMaskType );
00175
00177 itkSetObjectMacro( FixedImageMask, FixedImageMaskType );
00178 itkGetConstObjectMacro( FixedImageMask, FixedImageMaskType );
00179
00181 itkSetMacro( ComputeGradient, bool);
00182 itkGetConstReferenceMacro( ComputeGradient, bool);
00183 itkBooleanMacro(ComputeGradient);
00184
00186 itkGetConstObjectMacro( GradientImage, GradientImageType );
00187
00189 void SetTransformParameters( const ParametersType & parameters ) const;
00190
00192 unsigned int GetNumberOfParameters(void) const
00193 { return m_Transform->GetNumberOfParameters(); }
00194
00197 virtual void Initialize(void) throw ( ExceptionObject );
00198
00199 protected:
00200 ImageToImageMetric();
00201 virtual ~ImageToImageMetric() {};
00202 void PrintSelf(std::ostream& os, Indent indent) const;
00203
00204 mutable unsigned long m_NumberOfPixelsCounted;
00205
00206 FixedImageConstPointer m_FixedImage;
00207 MovingImageConstPointer m_MovingImage;
00208
00209 mutable TransformPointer m_Transform;
00210 InterpolatorPointer m_Interpolator;
00211
00212 bool m_ComputeGradient;
00213 GradientImagePointer m_GradientImage;
00214
00215 mutable FixedImageMaskPointer m_FixedImageMask;
00216 mutable MovingImageMaskPointer m_MovingImageMask;
00217
00218 private:
00219 ImageToImageMetric(const Self&);
00220 void operator=(const Self&);
00221
00222 FixedImageRegionType m_FixedImageRegion;
00223
00224
00225 };
00226
00227 }
00228
00229 #ifndef ITK_MANUAL_INSTANTIATION
00230 #include "itkImageToImageMetric.txx"
00231 #endif
00232
00233 #endif
00234
00235
00236