ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkMattesMutualInformationImageToImageMetricv4.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 __itkMattesMutualInformationImageToImageMetricv4_h
19 #define __itkMattesMutualInformationImageToImageMetricv4_h
20 
23 #include "itkPoint.h"
24 #include "itkIndex.h"
26 #include "itkArray2D.h"
27 
28 namespace itk
29 {
30 
95 template <class TFixedImage, class TMovingImage, class TVirtualImage = TFixedImage >
97 public ImageToImageMetricv4<TFixedImage, TMovingImage, TVirtualImage>
98 {
99 public:
105 
107  itkNewMacro(Self);
108 
111 
113  typedef typename Superclass::MeasureType MeasureType;
114  typedef typename Superclass::DerivativeType DerivativeType;
115  typedef typename DerivativeType::ValueType DerivativeValueType;
116 
117  typedef typename Superclass::FixedImageType FixedImageType;
118  typedef typename Superclass::FixedImagePointType FixedImagePointType;
119  typedef typename Superclass::FixedImageIndexType FixedImageIndexType;
120  typedef typename Superclass::FixedImagePixelType FixedImagePixelType;
121  typedef typename Superclass::FixedImageGradientType FixedImageGradientType;
122 
123  typedef typename Superclass::MovingImagePointType MovingImagePointType;
124  typedef typename Superclass::MovingImagePixelType MovingImagePixelType;
125  typedef typename Superclass::MovingImageGradientType MovingImageGradientType;
126 
127  typedef typename Superclass::MovingTransformType MovingTransformType;
128  typedef typename Superclass::JacobianType JacobianType;
129  typedef typename Superclass::VirtualImageType VirtualImageType;
130  typedef typename Superclass::VirtualIndexType VirtualIndexType;
131  typedef typename Superclass::VirtualPointType VirtualPointType;
132  typedef typename Superclass::VirtualPointSetType VirtualPointSetType;
133 
135  typedef typename Superclass::FixedSampledPointSetPointer FixedSampledPointSetPointer;
136 
137  /* Image dimension accessors */
138  itkStaticConstMacro(VirtualImageDimension, ImageDimensionType, TVirtualImage::ImageDimension);
139  itkStaticConstMacro(FixedImageDimension, ImageDimensionType, TFixedImage::ImageDimension);
140  itkStaticConstMacro(MovingImageDimension, ImageDimensionType, TMovingImage::ImageDimension);
141 
147  itkSetClampMacro( NumberOfHistogramBins, SizeValueType, 5, NumericTraits<SizeValueType>::max() );
148  itkGetConstReferenceMacro(NumberOfHistogramBins, SizeValueType);
150 
151  virtual void Initialize(void) throw ( itk::ExceptionObject );
152 
154  //NOTE: floating point precision is not as stable.
155  // Double precision proves faster and more robust in real-world testing.
156  typedef double PDFValueType;
157 
159  typedef Image<PDFValueType, 2> JointPDFType;
160  typedef Image<PDFValueType, 3> JointPDFDerivativesType;
161 
166  const typename JointPDFType::Pointer GetJointPDF () const
167  {
168  if( this->m_ThreaderJointPDF.size() == 0 )
169  {
170  return JointPDFType::Pointer(NULL);
171  }
172  return this->m_ThreaderJointPDF[0];
173  }
175 
182  const typename JointPDFDerivativesType::Pointer GetJointPDFDerivatives () const
183  {
184  if( this->m_ThreaderJointPDFDerivatives.size() == 0 )
185  {
187  }
188  return this->m_ThreaderJointPDFDerivatives[0];
189  }
191 
192 protected:
195 
197  friend class MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Superclass, Self >;
198  typedef MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedImageRegionPartitioner< Superclass::VirtualImageDimension >, Superclass, Self >
200  typedef MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Superclass, Self >
202 
203  void PrintSelf(std::ostream& os, Indent indent) const;
204 
213 
217 
220  virtual void GetValueCommonAfterThreadedExecution();
221 
222  OffsetValueType ComputeSingleFixedImageParzenWindowIndex( const FixedImagePixelType & value ) const;
223 
225  SizeValueType m_NumberOfHistogramBins;
226  PDFValueType m_MovingImageNormalizedMin;
227  PDFValueType m_FixedImageNormalizedMin;
228  PDFValueType m_FixedImageTrueMin;
229  PDFValueType m_FixedImageTrueMax;
230  PDFValueType m_MovingImageTrueMin;
231  PDFValueType m_MovingImageTrueMax;
232  PDFValueType m_FixedImageBinSize;
233  PDFValueType m_MovingImageBinSize;
234 
236  typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
237  typename CubicBSplineDerivativeFunctionType::Pointer m_CubicBSplineDerivativeKernel;
238 
241  typedef std::vector<PRatioType> PRatioArrayType;
242 
243  mutable PRatioArrayType m_PRatioArray;
244 
247  mutable std::vector<OffsetValueType> m_JointPdfIndex1DArray;
248 
250  mutable std::vector<PDFValueType> m_MovingImageMarginalPDF;
251  mutable std::vector<std::vector<PDFValueType> > m_ThreaderFixedImageMarginalPDF;
252 
254  typename std::vector<JointPDFType::Pointer> m_ThreaderJointPDF;
255  typename std::vector<JointPDFDerivativesType::Pointer> m_ThreaderJointPDFDerivatives;
256 
257  std::vector<int> m_ThreaderJointPDFStartBin;
258  std::vector<int> m_ThreaderJointPDFEndBin;
259 
260  mutable std::vector<PDFValueType> m_ThreaderJointPDFSum;
261 
264  mutable std::vector<DerivativeType> m_LocalDerivativeByParzenBin;
265 
266 private:
267  MattesMutualInformationImageToImageMetricv4(const Self &); //purposely not implemented
268  void operator = (const Self &); //purposely not implemented
269 
271  virtual void ComputeResults( void ) const;
272 
273 };
274 
275 } // end namespace itk
276 
277 #ifndef ITK_MANUAL_INSTANTIATION
278 #include "itkMattesMutualInformationImageToImageMetricv4.hxx"
279 #endif
280 
281 #endif
282