1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkPDEDeformableRegistrationFilter.h,v $
Language: C++
Date: $Date: 2004-09-29 14:20:40 $
Version: $Revision: 1.23 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef _itkPDEDeformableRegistrationFilter_h_
#define _itkPDEDeformableRegistrationFilter_h_
#include "itkDenseFiniteDifferenceImageFilter.h"
#include "itkPDEDeformableRegistrationFunction.h"
namespace itk {
/**
* \class PDEDeformableRegistrationFilter
* \brief Deformably register two images using a PDE algorithm.
*
* PDEDeformableRegistrationFilter is a base case for filter implementing
* a PDE deformable algorithm that register two images by computing the
* deformation field which will map a moving image onto a fixed image.
*
* A deformation field is represented as a image whose pixel type is some
* vector type with at least N elements, where N is the dimension of
* the fixed image. The vector type must support element access via operator
* []. It is assumed that the vector elements behave like floating point
* scalars.
*
* This class is templated over the fixed image type, moving image type
* and the deformation Field type.
*
* The input fixed and moving images are set via methods SetFixedImage
* and SetMovingImage respectively. An initial deformation field maybe set via
* SetInitialDeformationField or SetInput. If no initial field is set,
* a zero field is used as the initial condition.
*
* The output deformation field can be obtained via methods GetOutput
* or GetDeformationField.
*
* The PDE algorithm is run for a user defined number of iterations.
* Typically the PDE algorithm requires period Gaussin smoothing of the
* deformation field to enforce an elastic-like condition. The amount
* of smoothing is governed by a set of user defined standard deviations
* (one for each dimension).
*
* In terms of memory, this filter keeps two internal buffers: one for storing
* the intermediate updates to the field and one for double-buffering when
* smoothing the deformation field. Both buffers are the same type and size as the
* output deformation field.
*
* This class make use of the finite difference solver hierarchy. Update
* for each iteration is computed using a PDEDeformableRegistrationFunction.
*
* \warning This filter assumes that the fixed image type, moving image type
* and deformation field type all have the same number of dimensions.
*
* \sa PDEDeformableRegistrationFunction.
* \ingroup DeformableImageRegistration
*/
template<class TFixedImage, class TMovingImage, class TDeformationField>
class ITK_EXPORT PDEDeformableRegistrationFilter :
public DenseFiniteDifferenceImageFilter<TDeformationField,TDeformationField>
{
public:
/** Standard class typedefs. */
typedef PDEDeformableRegistrationFilter Self;
typedef DenseFiniteDifferenceImageFilter<
TDeformationField,TDeformationField> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods) */
itkTypeMacro( PDEDeformableRegistrationFilter,
DenseFiniteDifferenceImageFilter );
/** FixedImage image type. */
typedef TFixedImage FixedImageType;
typedef typename FixedImageType::Pointer FixedImagePointer;
typedef typename FixedImageType::ConstPointer FixedImageConstPointer;
/** MovingImage image type. */
typedef TMovingImage MovingImageType;
typedef typename MovingImageType::Pointer MovingImagePointer;
typedef typename MovingImageType::ConstPointer MovingImageConstPointer;
/** Deformation field type. */
typedef TDeformationField DeformationFieldType;
typedef typename DeformationFieldType::Pointer DeformationFieldPointer;
/** Types inherithed from the superclass */
typedef typename Superclass::OutputImageType OutputImageType;
/** FiniteDifferenceFunction type. */
typedef typename Superclass::FiniteDifferenceFunctionType
FiniteDifferenceFunctionType;
/** PDEDeformableRegistrationFilterFunction type. */
typedef PDEDeformableRegistrationFunction<FixedImageType,MovingImageType,
DeformationFieldType> PDEDeformableRegistrationFunctionType;
/** Inherit some enums and typedefs from the superclass. */
itkStaticConstMacro(ImageDimension, unsigned int,
Superclass::ImageDimension);
/** Set the fixed image. */
void SetFixedImage( const FixedImageType * ptr );
/** Get the fixed image. */
const FixedImageType * GetFixedImage(void) const;
/** Set the moving image. */
void SetMovingImage( const MovingImageType * ptr );
/** Get the moving image. */
const MovingImageType * GetMovingImage(void) const;
/** Set initial deformation field. */
void SetInitialDeformationField( DeformationFieldType * ptr )
{ this->SetInput( ptr ); }
/** Get output deformation field. */
DeformationFieldType * GetDeformationField()
{ return this->GetOutput(); }
/** Get the number of valid inputs. For PDEDeformableRegistration,
* this checks whether the fixed and moving images have been
* set. While PDEDeformableRegistration can take a third input as an
* initial deformation field, this input is not a required input.
*/
virtual std::vector<SmartPointer<DataObject> >::size_type GetNumberOfValidRequiredInputs() const;
/** Set/Get whether the deformation field is smoothed
* (regularized). Smoothing the deformation yields a solution
* elastic in nature. If SmoothDeformationField is on, then the
* deformation field is smoothed with a Gaussian whose standard
* deviations are specified with SetStandardDeviations() */
itkSetMacro( SmoothDeformationField, bool );
itkGetMacro( SmoothDeformationField, bool );
itkBooleanMacro( SmoothDeformationField );
/** Set the Gaussian smoothing standard deviations for the
* deformation field. The values are set with respect to pixel
* coordinates. */
itkSetVectorMacro( StandardDeviations, double, ImageDimension );
virtual void SetStandardDeviations( double value );
/** Get the Gaussian smoothing standard deviations use for smoothing
* the deformation field. */
const double * GetStandardDeviations(void)
{ return (double *) m_StandardDeviations; }
/** Set/Get whether the update field is smoothed
* (regularized). Smoothing the update field yields a solution
* viscous in nature. If SmoothUpdateField is on, then the
* update field is smoothed with a Gaussian whose standard
* deviations are specified with SetUpdateFieldStandardDeviations() */
itkSetMacro( SmoothUpdateField, bool );
itkGetMacro( SmoothUpdateField, bool );
itkBooleanMacro( SmoothUpdateField );
/** Set the Gaussian smoothing standard deviations for the update
* field. The values are set with respect to pixel coordinates. */
itkSetVectorMacro( UpdateFieldStandardDeviations, double, ImageDimension );
virtual void SetUpdateFieldStandardDeviations( double value );
/** Get the Gaussian smoothing standard deviations used for
* smoothing the update field. */
const double * GetUpdateFieldStandardDeviations(void)
{ return (double *) m_UpdateFieldStandardDeviations; }
/** Stop the registration after the current iteration. */
virtual void StopRegistration()
{ m_StopRegistrationFlag = true; }
/** Set/Get the desired maximum error of the Guassian kernel approximate.
* \sa GaussianOperator. */
itkSetMacro( MaximumError, double );
itkGetMacro( MaximumError, double );
/** Set/Get the desired limits of the Gaussian kernel width.
* \sa GaussianOperator. */
itkSetMacro( MaximumKernelWidth, unsigned int );
itkGetMacro( MaximumKernelWidth, unsigned int );
protected:
PDEDeformableRegistrationFilter();
~PDEDeformableRegistrationFilter() {}
void PrintSelf(std::ostream& os, Indent indent) const;
/** Supplies the halting criteria for this class of filters. The
* algorithm will stop after a user-specified number of iterations. */
virtual bool Halt()
{
if ( m_StopRegistrationFlag )
{
return true;
}
return this->Superclass::Halt();
}
/** A simple method to copy the data from the input to the output.
* If the input does not exist, a zero field is written to the output. */
virtual void CopyInputToOutput();
/** Initialize the state of filter and equation before each iteration.
* Progress feeback is implemented as part of this method. */
virtual void InitializeIteration();
/** Utility to smooth the deformation field (represented in the Output)
* using a Guassian operator. The amount of smoothing can be specified
* by setting the StandardDeviations. */
virtual void SmoothDeformationField();
/** Utility to smooth the UpdateBuffer using a Gaussian operator.
* The amount of smoothing can be specified by setting the
* UpdateFieldStandardDeviations. */
virtual void SmoothUpdateField();
/** This method is called after the solution has been generated. In this case,
* the filter release the memory of the internal buffers. */
virtual void PostProcessOutput();
/** This method is called before iterating the solution. */
virtual void Initialize();
/** By default the output deformation field has the same Spacing, Origin
* and LargestPossibleRegion as the input/initial deformation field. If
* the initial deformation field is not set, the output information is
* copied from the fixed image. */
virtual void GenerateOutputInformation();
/** It is difficult to compute in advance the input moving image region
* required to compute the requested output region. Thus the safest
* thing to do is to request for the whole moving image.
*
* For the fixed image and deformation field, the input requested region
* set to be the same as that of the output requested region. */
virtual void GenerateInputRequestedRegion();
private:
PDEDeformableRegistrationFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
/** Standard deviation for Gaussian smoothing */
double m_StandardDeviations[ImageDimension];
double m_UpdateFieldStandardDeviations[ImageDimension];
/** Modes to control smoothing of the update and deformation fields */
bool m_SmoothDeformationField;
bool m_SmoothUpdateField;
/** Temporary deformation field use for smoothing the
* the deformation field. */
DeformationFieldPointer m_TempField;
private:
/** Maximum error for Gaussian operator approximation. */
double m_MaximumError;
/** Limits of Guassian kernel width. */
unsigned int m_MaximumKernelWidth;
/** Flag to indicate user stop registration request. */
bool m_StopRegistrationFlag;
};
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkPDEDeformableRegistrationFilter.txx"
#endif
#endif
|