ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkGradientDifferenceImageToImageMetric.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkGradientDifferenceImageToImageMetric_h
19 #define itkGradientDifferenceImageToImageMetric_h
20 
21 #include "itkImageToImageMetric.h"
22 
23 #include "itkSobelOperator.h"
25 #include "itkPoint.h"
26 #include "itkCastImageFilter.h"
27 #include "itkResampleImageFilter.h"
28 
29 namespace itk
30 {
57 template< typename TFixedImage, typename TMovingImage >
58 class ITK_TEMPLATE_EXPORT GradientDifferenceImageToImageMetric:
59  public ImageToImageMetric< TFixedImage, TMovingImage >
60 {
61 public:
62  ITK_DISALLOW_COPY_AND_ASSIGN(GradientDifferenceImageToImageMetric);
63 
67 
70 
72  itkNewMacro(Self);
73 
76 
78  using RealType = typename Superclass::RealType;
79  using TransformType = typename Superclass::TransformType;
80  using TransformPointer = typename Superclass::TransformPointer;
81  using TransformParametersType = typename Superclass::TransformParametersType;
82  using TransformJacobianType = typename Superclass::TransformJacobianType;
83 
84  using MeasureType = typename Superclass::MeasureType;
85  using DerivativeType = typename Superclass::DerivativeType;
86  using FixedImageType = typename Superclass::FixedImageType;
87  using MovingImageType = typename Superclass::MovingImageType;
88  using FixedImageConstPointer = typename Superclass::FixedImageConstPointer;
89  using MovingImageConstPointer = typename Superclass::MovingImageConstPointer;
90 
91  using FixedImagePixelType = typename TFixedImage::PixelType;
92  using MovedImagePixelType = typename TMovingImage::PixelType;
93 
94  static constexpr unsigned int FixedImageDimension = TFixedImage::ImageDimension;
97  Self::FixedImageDimension >;
98 
101 
105 
108 
110 
113  static constexpr unsigned int MovedImageDimension = MovingImageType::ImageDimension;
114 
116 
119 
121 
123  void GetDerivative(const TransformParametersType & parameters,
124  DerivativeType & derivative) const override;
125 
127  MeasureType GetValue(const TransformParametersType & parameters) const override;
128 
130  void GetValueAndDerivative(const TransformParametersType & parameters,
131  MeasureType & Value, DerivativeType & derivative) const override;
132 
135  void Initialize() override;
136 
138  void WriteGradientImagesToFiles() const;
139 
142  itkSetMacro(DerivativeDelta, double);
143  itkGetConstReferenceMacro(DerivativeDelta, double);
145 
146 protected:
148  ~GradientDifferenceImageToImageMetric() override = default;
149  void PrintSelf(std::ostream & os, Indent indent) const override;
150 
152  void ComputeMovedGradientRange() const;
153 
155  void ComputeVariance() const;
156 
158  MeasureType ComputeMeasure(const TransformParametersType & parameters,
159  const double *subtractionFactor) const;
160 
163 
166 
167 private:
169  mutable MovedGradientPixelType m_Variance[FixedImageDimension];
170 
172  mutable MovedGradientPixelType m_MinMovedGradient[MovedImageDimension];
173  mutable MovedGradientPixelType m_MaxMovedGradient[MovedImageDimension];
174 
176  mutable FixedGradientPixelType m_MinFixedGradient[FixedImageDimension];
177  mutable FixedGradientPixelType m_MaxFixedGradient[FixedImageDimension];
178 
181 
184 
186  Self::FixedImageDimension >
187  m_FixedSobelOperators[FixedImageDimension];
188 
189  typename FixedSobelFilter::Pointer m_FixedSobelFilters[Self::FixedImageDimension];
190 
193 
196 
198  Self::MovedImageDimension >
199  m_MovedSobelOperators[MovedImageDimension];
200 
201  typename MovedSobelFilter::Pointer m_MovedSobelFilters[Self::MovedImageDimension];
202 
204 };
205 } // end namespace itk
206 
207 #ifndef ITK_MANUAL_INSTANTIATION
208 #include "itkGradientDifferenceImageToImageMetric.hxx"
209 #endif
210 
211 #endif
Array class with size defined at construction time.
Definition: itkArray.h:46
A function object that determines a neighborhood of values at an image boundary according to a Neuman...
TPixel PixelType
Definition: itkImage.h:95
Light weight base class for most itk classes.
Resample an image via a coordinate transform.
typename CastMovedImageFilterType::Pointer CastMovedImageFilterPointer
typename CastFixedImageFilterType::Pointer CastFixedImageFilterPointer
typename Superclass::FixedImageConstPointer FixedImageConstPointer
typename Superclass::MovingImageConstPointer MovingImageConstPointer
typename FixedGradientImageType::PixelType FixedGradientPixelType
A NeighborhoodOperator for performing a directional Sobel edge-detection operation at a pixel locatio...
ZeroFluxNeumannBoundaryCondition< FixedGradientImageType > m_FixedBoundCond
TransformMovingImageFilterType::Pointer m_TransformMovingImageFilter
Computes similarity between two objects to be registered.
typename Superclass::TransformJacobianType TransformJacobianType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename MovedGradientImageType::PixelType MovedGradientPixelType
Applies a single NeighborhoodOperator to an image region.
Computes similarity between regions of two images.
Templated n-dimensional image class.
Definition: itkImage.h:75
ZeroFluxNeumannBoundaryCondition< MovedGradientImageType > m_MovedBoundCond
Casts input pixels to output pixel type.
typename Superclass::TransformParametersType TransformParametersType