ITK/Examples/SpectralAnalysis/VnlFFTRealToComplexConjugateImageFilter

From KitwarePublic
< ITK‎ | Examples
Revision as of 19:31, 24 January 2011 by Daviddoria (talk | contribs)
Jump to navigationJump to search

VnlFFTRealToComplexConjugateImageFilter.cxx

<source lang="cpp">

  1. include "itkImage.h"
  2. include "itkRescaleIntensityImageFilter.h"
  3. include "itkVnlFFTRealToComplexConjugateImageFilter.h"
  4. include "itkComplexToRealImageFilter.h"
  5. include "itkComplexToImaginaryImageFilter.h"
  6. include "itkComplexToModulusImageFilter.h"
  7. include "itkImageFileReader.h"
  8. include "itkCastImageFilter.h"
  9. include "itkPasteImageFilter.h"
  1. include <itksys/SystemTools.hxx>
  2. include "vnl/vnl_sample.h"
  3. include <math.h>
  1. include <itkImageToVTKImageFilter.h>
  1. include "QuickView.h"

int main(int argc, char*argv[]) {

 if(argc < 2)
   {
   std::cerr << "Required: filename" << std::endl;
   return EXIT_FAILURE;
   }
 typedef itk::Image<unsigned char, 2> UnsignedCharImageType;
 typedef itk::Image<float, 2> FloatImageType;
 
 typedef itk::ImageFileReader<FloatImageType> ReaderType;
 ReaderType::Pointer reader = ReaderType::New();
 reader->SetFileName(argv[1]);
 reader->Update();
 unsigned int powerOfTwo = 0;
 for(unsigned int i = 0; i < 10; i++)
   {
   if(pow(2, i) > reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0] &&
      pow(2, i) > reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1])
     {
     powerOfTwo = i;
     break;
     }
   }
 // Create an image bigger than the input image and that has dimensions which are powers of two
 itk::Index<2> start;
 start.Fill(0);
 itk::Size<2> size;
 size.Fill(pow(2,powerOfTwo));
 itk::ImageRegion<2> region(start, size);
 
 FloatImageType::Pointer image = FloatImageType::New();
 image->SetRegions(region);
 image->Allocate();
 
 // The image dimensions must be powers of two
 typedef itk::PasteImageFilter <FloatImageType, FloatImageType >
   PasteImageFilterType;
 // The SetDestinationIndex() method prescribes where in the first input to start pasting data from the second input.
 // The SetSourceRegion method prescribes the section of the second image to paste into the first.
 itk::Index<2> destinationIndex;
 destinationIndex.Fill(0);
 
 PasteImageFilterType::Pointer pasteFilter
   = PasteImageFilterType::New ();
 pasteFilter->SetSourceImage(reader->GetOutput());
 pasteFilter->SetDestinationImage(image);
 pasteFilter->SetSourceRegion(reader->GetOutput()->GetLargestPossibleRegion());
 pasteFilter->SetDestinationIndex(destinationIndex);
 pasteFilter->Update();
 
 image->Graft(pasteFilter->GetOutput());
 
 // Take the FFT
 
 typedef itk::VnlFFTRealToComplexConjugateImageFilter<FloatImageType::PixelType, 2> FFTType;
 FFTType::Pointer fftFilter = FFTType::New();
 fftFilter->SetInput(image);
 fftFilter->Update();
 
 // Extract the real part
 typedef itk::ComplexToRealImageFilter<FFTType::OutputImageType, UnsignedCharImageType> RealFilterType;
 RealFilterType::Pointer realFilter = RealFilterType::New();
 realFilter->SetInput(fftFilter->GetOutput());
 realFilter->Update();
 // Extract the real part
 typedef itk::ComplexToImaginaryImageFilter<FFTType::OutputImageType, UnsignedCharImageType> ImaginaryFilterType;
 ImaginaryFilterType::Pointer imaginaryFilter = ImaginaryFilterType::New();
 imaginaryFilter->SetInput(fftFilter->GetOutput());
 imaginaryFilter->Update();
 // Compute the magnitude
 typedef itk::ComplexToModulusImageFilter<FFTType::OutputImageType, UnsignedCharImageType> ModulusFilterType;
 ModulusFilterType::Pointer modulusFilter = ModulusFilterType::New();
 modulusFilter->SetInput(fftFilter->GetOutput());
 modulusFilter->Update();
 QuickView viewer;
 viewer.AddImage(image.GetPointer());
 
 viewer.AddImage(realFilter->GetOutput());
 viewer.AddImage(imaginaryFilter->GetOutput());
 viewer.AddImage(modulusFilter->GetOutput());
 viewer.Visualize();
 return EXIT_SUCCESS;

} </source>

CMakeLists.txt

<source lang="cmake"> cmake_minimum_required(VERSION 2.6)

PROJECT(VnlFFTRealToComplexConjugateImageFilter)

include_directories(/home/doriad/src/ITK/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src/) include_directories(/home/doriad/ITKWikiExamples/ItkVtkGlue)

FIND_PACKAGE(VTK REQUIRED) INCLUDE(${VTK_USE_FILE})

FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(VnlFFTRealToComplexConjugateImageFilter VnlFFTRealToComplexConjugateImageFilter.cxx /home/doriad/ITKWikiExamples/ItkVtkGlue/QuickView.cxx) TARGET_LINK_LIBRARIES(VnlFFTRealToComplexConjugateImageFilter vtkHybrid ITKNumerics ITKBasicFilters ITKCommon ITKIO)


</source>