Difference between revisions of "ITK/Examples/SpectralAnalysis/InverseFFTImageFilter"

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Correct loop counter type.)
(Deprecated content that is moved to sphinx)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
==InverseFFTImageFilter.cxx==
{{warning|1=The media wiki content on this page is no longer maintained.  The examples presented on the https://itk.org/Wiki/*  pages likely require ITK version 4.13 or earlier releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}}
<source lang="cpp">
#include "itkImage.h"
#include "itkForwardFFTImageFilter.h"
#include "itkInverseFFTImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkImageFileReader.h"
#include "itkCastImageFilter.h"
#include "itkImageFileWriter.h"
 
#include "QuickView.h"
 
typedef itk::Image<float, 2> FloatImageType;
 
static void CreateImage(FloatImageType* const image);
 
int main(int argc, char*argv[])
{
  FloatImageType::Pointer image;
  // Verify input
  if(argc < 2)
    {
    image = FloatImageType::New();
    CreateImage(image);
    //std::cerr << "Required: filename" << std::endl;
    //return EXIT_FAILURE;
    }
  else
  {
    // Read the image
    typedef itk::ImageFileReader<FloatImageType> ReaderType;
    ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileName(argv[1]);
    reader->Update();
 
    image = reader->GetOutput();
  }
 
  // Define some types
  typedef itk::Image<unsigned char, 2> UnsignedCharImageType;
 
  // Compute the FFT
  typedef itk::ForwardFFTImageFilter<FloatImageType> FFTType;
  FFTType::Pointer fftFilter = FFTType::New();
  fftFilter->SetInput(image);
  fftFilter->Update();
 
  // Compute the IFFT
  //typedef itk::InverseFFTImageFilter<FFTType::OutputImageType, UnsignedCharImageType> IFFTType; // This does not work - output type seems to need to be float, but it is just an error, not a concept check error...
  typedef itk::InverseFFTImageFilter<FFTType::OutputImageType, FloatImageType> IFFTType;
  IFFTType::Pointer ifftFilter = IFFTType::New();
  ifftFilter->SetInput(fftFilter->GetOutput());
  ifftFilter->Update();
 
//  QuickView viewer;
//  viewer.AddImage(image.GetPointer());
//   viewer.AddImage(ifftFilter->GetOutput());
//  viewer.Visualize();
 
   typedef itk::CastImageFilter< FloatImageType, UnsignedCharImageType > CastFilterType;
  CastFilterType::Pointer castFilter = CastFilterType::New();
  castFilter->SetInput(ifftFilter->GetOutput());
  castFilter->Update();
 
  typedef itk::ImageFileWriter<UnsignedCharImageType> WriterType;
 
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("ifft.png");
  writer->SetInput(castFilter->GetOutput());
  writer->Update();
 
  return EXIT_SUCCESS;
}
 
void CreateImage(FloatImageType* const image)
{
  itk::Index<2> corner = {{0,0}};
 
  itk::Size<2> size = {{200,200}};
 
  itk::ImageRegion<2> region(corner, size);
 
  image->SetRegions(region);
  image->Allocate();
 
  // Make a square
  for(FloatImageType::IndexValueType r = 40; r < 100; r++)
    {
    for(FloatImageType::IndexValueType c = 40; c < 100; c++)
      {
      FloatImageType::IndexType pixelIndex = {{r,c}};
 
      image->SetPixel(pixelIndex, 100);
      }
    }
}
 
</source>
 
{{ITKVTKCMakeLists|InverseFFTImageFilter|}}

Latest revision as of 14:51, 6 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.