ITK  4.4.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 {
138 
139 template <class TInputImage, class TOutputImage, class TMaskImage=TInputImage >
141  public ImageToImageFilter< TInputImage, TOutputImage >
142 {
143 public:
149 
151  itkNewMacro(Self);
152 
154  itkTypeMacro(MaskedFFTNormalizedCorrelationImageFilter, MaskedFFTNormalizedCrossCorrelationImageFilter);
155 
158  itkStaticConstMacro(ImageDimension, unsigned int,
159  TOutputImage::ImageDimension);
160 
162  typedef TInputImage InputImageType;
163  typedef typename InputImageType::RegionType InputRegionType;
164  typedef typename InputImageType::Pointer InputImagePointer;
165  typedef typename InputImageType::ConstPointer InputImageConstPointer;
166  typedef typename InputImageType::SizeType InputSizeType;
168 
169  typedef TOutputImage OutputImageType;
170  typedef typename OutputImageType::Pointer OutputImagePointer;
171  typedef typename OutputImageType::PixelType OutputPixelType;
172 
179 
180  typedef TMaskImage MaskImageType;
181  typedef typename MaskImageType::Pointer MaskImagePointer;
182 
185 
187  void SetFixedImage(const InputImageType *input)
188  {
189  this->SetNthInput(0, const_cast<InputImageType *>(input) );
190  }
191  InputImageType * GetFixedImage()
192  {
193  return itkDynamicCastInDebugMode<InputImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(0)));
194  }
196 
198  void SetMovingImage(const InputImageType *input)
199  {
200  this->SetNthInput(1, const_cast<InputImageType *>(input) );
201  }
202  InputImageType * GetMovingImage()
203  {
204  return itkDynamicCastInDebugMode<InputImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(1)));
205  }
207 
209  void SetFixedImageMask(const MaskImageType *input)
210  {
211  this->SetNthInput(2, const_cast<MaskImageType *>(input) );
212  }
213  MaskImageType * GetFixedImageMask()
214  {
215  return itkDynamicCastInDebugMode<MaskImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(2)));
216  }
218 
220  void SetMovingImageMask(const MaskImageType *input)
221  {
222  this->SetNthInput(3, const_cast<MaskImageType *>(input) );
223  }
224  MaskImageType * GetMovingImageMask()
225  {
226  return itkDynamicCastInDebugMode<MaskImageType * >(const_cast<DataObject *>(this->ProcessObject::GetInput(3)));
227  }
229 
231  itkSetMacro(RequiredNumberOfOverlappingPixels,SizeValueType);
232  itkGetMacro(RequiredNumberOfOverlappingPixels,SizeValueType);
234 
236  itkGetMacro(RequiredFractionOfOverlappingPixels,RealPixelType);
237  void SetRequiredFractionOfOverlappingPixels(RealPixelType requiredFractionOfOverlappingPixels)
238  {
239  // The fraction must be between 0 and 1.
240  requiredFractionOfOverlappingPixels = (requiredFractionOfOverlappingPixels < 0.0) ? 0.0 : requiredFractionOfOverlappingPixels;
241  requiredFractionOfOverlappingPixels = (requiredFractionOfOverlappingPixels > 1.0) ? 1.0 : requiredFractionOfOverlappingPixels;
242  m_RequiredFractionOfOverlappingPixels = requiredFractionOfOverlappingPixels;
243  }
245 
247  itkGetMacro(MaximumNumberOfOverlappingPixels,SizeValueType);
248 
249 #ifdef ITK_USE_CONCEPT_CHECKING
250 
251  itkConceptMacro( OutputPixelTypeIsFloatingPointCheck,
253 
255 #endif
256 
257 protected:
259  {
260  this->SetNumberOfRequiredInputs(2);
261  m_RequiredNumberOfOverlappingPixels = 0;
262  m_RequiredFractionOfOverlappingPixels = 0;
263  m_MaximumNumberOfOverlappingPixels = 0;
264  }
266  void PrintSelf(std::ostream& os, Indent indent) const;
267 
269  void VerifyInputInformation();
270 
272  void GenerateData();
273 
279  virtual void GenerateInputRequestedRegion();
280 
285  void GenerateOutputInformation();
286 
287  typename TMaskImage::Pointer PreProcessMask( const InputImageType * inputImage, const MaskImageType * inputMask );
288 
289  typename TInputImage::Pointer PreProcessImage( const InputImageType * inputImage, MaskImageType * inputMask );
290 
291  template< class LocalInputImageType >
292  typename LocalInputImageType::Pointer RotateImage( LocalInputImageType * inputImage );
293 
294  template< class LocalInputImageType, class LocalOutputImageType >
295  typename LocalOutputImageType::Pointer CalculateForwardFFT( LocalInputImageType * inputImage, InputSizeType & FFTImageSize );
296 
297  template< class LocalInputImageType, class LocalOutputImageType >
298  typename LocalOutputImageType::Pointer CalculateInverseFFT( LocalInputImageType * inputImage, RealSizeType & combinedImageSize );
299 
300  // Helper math methods.
301  template< class LocalInputImageType, class LocalOutputImageType >
302  typename LocalOutputImageType::Pointer ElementProduct( LocalInputImageType * inputImage1, LocalInputImageType * inputImage2 );
303 
304  template< class LocalInputImageType >
305  typename LocalInputImageType::Pointer ElementQuotient( LocalInputImageType * inputImage1, LocalInputImageType * inputImage2 );
306 
307  template< class LocalInputImageType >
308  typename LocalInputImageType::Pointer ElementSubtraction( LocalInputImageType * inputImage1, LocalInputImageType * inputImage2 );
309 
310  template< class LocalInputImageType >
311  typename LocalInputImageType::Pointer ElementPositive( LocalInputImageType * inputImage );
312 
313  template< class LocalInputImageType, class LocalOutputImageType >
314  typename LocalOutputImageType::Pointer ElementRound( LocalInputImageType * inputImage );
315 
316  // This function factorizes the image size uses factors of 2, 3, and
317  // 5. After this factorization, if there are any remaining values,
318  // the function returns this value.
319  int FactorizeNumber( int n );
320 
321  // Find the closest valid dimension above the desired dimension. This
322  // will be a combination of 2s, 3s, and 5s.
323  int FindClosestValidDimension( int n );
324 
325  template< class LocalInputImageType >
326  double CalculatePrecisionTolerance( LocalInputImageType * inputImage );
327 
328 private:
329  MaskedFFTNormalizedCorrelationImageFilter(const Self&); //purposely not implemented
330  void operator=(const Self&); //purposely not implemented
331 
336 
341 
344 };
345 } // end namespace itk
346 
347 #ifndef ITK_MANUAL_INSTANTIATION
348 #include "itkMaskedFFTNormalizedCorrelationImageFilter.hxx"
349 #endif
350 
351 #endif
352