ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkMaskedFFTNormalizedCorrelationImageFilter.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 __itkMaskedFFTNormalizedCorrelationImageFilter_h
19 #define __itkMaskedFFTNormalizedCorrelationImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
22 #include "itkImage.h"
23 
24 namespace itk
25 {
115 
116 template <class TInputImage, class TOutputImage, class TMaskImage=TInputImage >
118  public ImageToImageFilter< TInputImage, TOutputImage >
119 {
120 public:
126 
128  itkNewMacro(Self);
129 
131  itkTypeMacro(MaskedFFTNormalizedCorrelationImageFilter, MaskedFFTNormalizedCrossCorrelationImageFilter);
132 
135  itkStaticConstMacro(ImageDimension, unsigned int,
136  TOutputImage::ImageDimension);
137 
139  typedef TInputImage InputImageType;
140  typedef typename InputImageType::RegionType InputRegionType;
141  typedef typename InputImageType::Pointer InputImagePointer;
142  typedef typename InputImageType::ConstPointer InputImageConstPointer;
143  typedef typename InputImageType::SizeType InputSizeType;
144 
145  typedef TOutputImage OutputImageType;
146  typedef typename OutputImageType::Pointer OutputImagePointer;
147  typedef typename OutputImageType::PixelType OutputPixelType;
148 
155 
156  typedef TMaskImage MaskImageType;
157  typedef typename MaskImageType::Pointer MaskImagePointer;
158 
161 
163  void SetFixedImage(const InputImageType *input)
164  {
165  this->SetNthInput(0, const_cast<InputImageType *>(input) );
166  }
167  InputImageType * GetFixedImage()
168  {
169  return itkDynamicCastInDebugMode<InputImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(0)));
170  }
172 
174  void SetMovingImage(const InputImageType *input)
175  {
176  this->SetNthInput(1, const_cast<InputImageType *>(input) );
177  }
178  InputImageType * GetMovingImage()
179  {
180  return itkDynamicCastInDebugMode<InputImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(1)));
181  }
183 
185  void SetFixedImageMask(const MaskImageType *input)
186  {
187  this->SetNthInput(2, const_cast<MaskImageType *>(input) );
188  }
189  MaskImageType * GetFixedImageMask()
190  {
191  return itkDynamicCastInDebugMode<MaskImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(2)));
192  }
194 
196  void SetMovingImageMask(const MaskImageType *input)
197  {
198  this->SetNthInput(3, const_cast<MaskImageType *>(input) );
199  }
200  MaskImageType * GetMovingImageMask()
201  {
202  return itkDynamicCastInDebugMode<MaskImageType * >(const_cast<DataObject *>(this->ProcessObject::GetInput(3)));
203  }
205 
207  itkSetMacro(RequiredNumberOfOverlappingPixels,SizeValueType);
208  itkGetMacro(RequiredNumberOfOverlappingPixels,SizeValueType);
210 
211 #ifdef ITK_USE_CONCEPT_CHECKING
212 
213  itkConceptMacro( OutputPixelTypeIsFloatingPointCheck,
215 
217 #endif
218 
219 protected:
221  {
222  this->SetNumberOfRequiredInputs(2);
223  m_RequiredNumberOfOverlappingPixels = 0;
224  }
226  void PrintSelf(std::ostream& os, Indent indent) const;
227 
229  void VerifyInputInformation();
230 
232  void GenerateData();
233 
239  virtual void GenerateInputRequestedRegion();
240 
245  void GenerateOutputInformation();
246 
247  typename TMaskImage::Pointer PreProcessMask( const InputImageType * inputImage, const MaskImageType * inputMask );
248 
249  typename TInputImage::Pointer PreProcessImage( const InputImageType * inputImage, MaskImageType * inputMask );
250 
251  template< class LocalInputImageType >
252  typename LocalInputImageType::Pointer RotateImage( LocalInputImageType * inputImage );
253 
254  template< class LocalInputImageType, class LocalOutputImageType >
255  typename LocalOutputImageType::Pointer CalculateForwardFFT( LocalInputImageType * inputImage, InputSizeType & FFTImageSize );
256 
257  template< class LocalInputImageType, class LocalOutputImageType >
258  typename LocalOutputImageType::Pointer CalculateInverseFFT( LocalInputImageType * inputImage, RealSizeType & combinedImageSize );
259 
260  // Helper math methods.
261  template< class LocalInputImageType, class LocalOutputImageType >
262  typename LocalOutputImageType::Pointer ElementProduct( LocalInputImageType * inputImage1, LocalInputImageType * inputImage2 );
263 
264  template< class LocalInputImageType >
265  typename LocalInputImageType::Pointer ElementQuotient( LocalInputImageType * inputImage1, LocalInputImageType * inputImage2 );
266 
267  template< class LocalInputImageType >
268  typename LocalInputImageType::Pointer ElementSubtraction( LocalInputImageType * inputImage1, LocalInputImageType * inputImage2 );
269 
270  template< class LocalInputImageType >
271  typename LocalInputImageType::Pointer ElementPositive( LocalInputImageType * inputImage );
272 
273  template< class LocalInputImageType, class LocalOutputImageType >
274  typename LocalOutputImageType::Pointer ElementRound( LocalInputImageType * inputImage );
275 
276  // This function factorizes the image size uses factors of 2, 3, and
277  // 5. After this factorization, if there are any remaining values,
278  // the function returns this value.
279  int FactorizeNumber( int n );
280 
281  // Find the closest valid dimension above the desired dimension. This
282  // will be a combination of 2s, 3s, and 5s.
283  int FindClosestValidDimension( int n );
284 
285  template< class LocalInputImageType >
286  double CalculatePrecisionTolerance( LocalInputImageType * inputImage );
287 
288 private:
289  MaskedFFTNormalizedCorrelationImageFilter(const Self&); //purposely not implemented
290  void operator=(const Self&); //purposely not implemented
291 
296 };
297 } // end namespace itk
298 
299 #ifndef ITK_MANUAL_INSTANTIATION
300 #include "itkMaskedFFTNormalizedCorrelationImageFilter.hxx"
301 #endif
302 
303 #endif
304