#if ITK_VERSION_MAJOR < 4
#include "itkVnlFFTRealToComplexConjugateImageFilter.h"
#include "itkVnlFFTComplexConjugateToRealImageFilter.h"
#else
#endif
#if ITK_VERSION_MAJOR < 4
#include "itkRealAndImaginaryToComplexImageFilter.h"
#else
#endif
int main(int argc, char*argv[])
{
const unsigned int Dimension = 2;
typedef float PixelType;
if( argc < 3 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " FixedImage MovingImage"<< std::endl;;
return EXIT_FAILURE;
}
std::string fixedImageFilename = argv[1];
std::string movingImageFilename = argv[2];
ImageReaderType::Pointer fixedImageReader = ImageReaderType::New();
fixedImageReader->SetFileName( fixedImageFilename );
fixedImageReader->Update();
ImageReaderType::Pointer movingImageReader = ImageReaderType::New();
movingImageReader->SetFileName( movingImageFilename );
movingImageReader->Update();
FFTShiftFilterType::Pointer fixedFFTShiftFilter = FFTShiftFilterType::New();
fixedFFTShiftFilter->SetInput(fixedImageReader->GetOutput());
fixedFFTShiftFilter->Update();
FFTShiftFilterType::Pointer movingFFTShiftFilter = FFTShiftFilterType::New();
movingFFTShiftFilter->SetInput(movingImageReader->GetOutput());
movingFFTShiftFilter->Update();
#if ITK_VERSION_MAJOR < 4
typedef itk::VnlFFTRealToComplexConjugateImageFilter< FloatImageType > FFTFilterType;
#else
#endif
FFTFilterType::Pointer fixedFFTFilter = FFTFilterType::New();
fixedFFTFilter->SetInput( fixedFFTShiftFilter->GetOutput() );
fixedFFTFilter->Update();
FFTFilterType::Pointer movingFFTFilter = FFTFilterType::New();
movingFFTFilter->SetInput( movingFFTShiftFilter->GetOutput() );
typedef FFTFilterType::OutputImageType SpectralImageType;
RealFilterType::Pointer realFilter = RealFilterType::New();
realFilter->SetInput(movingFFTFilter->GetOutput());
ImaginaryFilterType::Pointer imaginaryFilter = ImaginaryFilterType::New();
imaginaryFilter->SetInput(movingFFTFilter->GetOutput());
#if ITK_VERSION_MAJOR < 4
#else
#endif
MultiplyConstantFilterType::Pointer flipSignFilter = MultiplyConstantFilterType::New();
#if ITK_VERSION_MAJOR < 4
flipSignFilter->SetConstant(-1);
#else
flipSignFilter->SetConstant2(-1);
#endif
flipSignFilter->SetInput(imaginaryFilter->GetOutput());
#if ITK_VERSION_MAJOR < 4
typedef itk::RealAndImaginaryToComplexImageFilter<FloatImageType> RealImageToComplexFilterType;
#else
#endif
RealImageToComplexFilterType::Pointer conjugateFilter = RealImageToComplexFilterType::New();
conjugateFilter->SetInput1(realFilter->GetOutput());
conjugateFilter->SetInput2(flipSignFilter->GetOutput());
SpectralImageType,
SpectralImageType > MultiplyFilterType;
MultiplyFilterType::Pointer multiplyFilter = MultiplyFilterType::New();
multiplyFilter->SetInput1( fixedFFTFilter->GetOutput() );
multiplyFilter->SetInput2( conjugateFilter->GetOutput() );
#if ITK_VERSION_MAJOR < 4
typedef itk::VnlFFTComplexConjugateToRealImageFilter< SpectralImageType > IFFTFilterType;
#else
#endif
IFFTFilterType::Pointer fftInverseFilter = IFFTFilterType::New();
fftInverseFilter->SetInput( multiplyFilter->GetOutput() );
RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
rescaler->SetInput( fftInverseFilter->GetOutput() );
rescaler->SetOutputMinimum(0);
rescaler->SetOutputMaximum(255);
rescaler->Update();
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( "CrossCorr.png" );
writer->SetInput( rescaler->GetOutput() );
writer->Update();
ImageCalculatorFilterType;
ImageCalculatorFilterType::Pointer imageCalculatorFilter
= ImageCalculatorFilterType::New ();
imageCalculatorFilter->SetImage(rescaler->GetOutput());
imageCalculatorFilter->Compute();
UnsignedCharImageType::IndexType maximumLocation = imageCalculatorFilter->GetIndexOfMaximum();
std::cout << maximumLocation << std::endl;
return EXIT_SUCCESS;
}