int
main(int argc, char * argv[])
{
if (argc < 5)
{
std::cerr << "Usage: " << argv[0]
<< " inputScalarImage outputRealPartOfComplexImage "
"outputRealImaginaryPartOfComplexImage outputComplex"
<< std::endl;
}
using PixelType = float;
FFTFilterType::Pointer fftFilter = FFTFilterType::New();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
fftFilter->SetInput(reader->GetOutput());
try
{
fftFilter->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Error: " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
using ComplexImageType = FFTFilterType::OutputImageType;
ComplexWriterType::Pointer complexWriter = ComplexWriterType::New();
complexWriter->SetFileName(argv[4]);
complexWriter->SetInput(fftFilter->GetOutput());
try
{
complexWriter->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Error: " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
using RealFilterType =
RealFilterType::Pointer realFilter = RealFilterType::New();
realFilter->SetInput(fftFilter->GetOutput());
using WritePixelType = unsigned char;
using RescaleFilterType =
RescaleFilterType::Pointer intensityRescaler = RescaleFilterType::New();
intensityRescaler->SetInput(realFilter->GetOutput());
intensityRescaler->SetOutputMinimum(0);
intensityRescaler->SetOutputMaximum(255);
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(argv[2]);
writer->SetInput(intensityRescaler->GetOutput());
try
{
writer->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Error writing the real image: " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
using ComplexImageType = FFTFilterType::OutputImageType;
using ImaginaryFilterType =
ImaginaryFilterType::Pointer imaginaryFilter = ImaginaryFilterType::New();
imaginaryFilter->SetInput(fftFilter->GetOutput());
intensityRescaler->SetInput(imaginaryFilter->GetOutput());
writer->SetFileName(argv[3]);
try
{
writer->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Error writing the imaginary image: " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
ComplexReaderType::Pointer complexReader = ComplexReaderType::New();
complexReader->SetFileName(argv[4]);
complexReader->Update();
complexReader->GetImageIO()->GetPixelTypeAsString(
complexReader->GetImageIO()->GetPixelType());
return EXIT_SUCCESS;
}