[Insight-users] Re: can you send me the FFTImageFiltercxx

Luis Ibanez luis.ibanez at kitware.com
Mon Nov 15 11:46:24 EST 2004


Hi Lanlanny,

You can get files directly from the Web-CVS portal

http://www.itk.org/cgi-bin/viewcvs.cgi/?cvsroot=Insight

In particular from

http://www.itk.org/cgi-bin/viewcvs.cgi/Examples/Filtering/FFTImageFilter.cxx?rev=1.3&root=Insight&sortby=date&view=log

--------------------------

I'm attaching the files to this email anyways
in case you have trouble accessing the WebCVS site.


   Regards,


     Luis


------------------
Ñî´ºÀ¼ wrote:
> Hi,
>  luis,thanks for your sincere help! but I am a student in China, the internet of
> the schools are limited by some conditions and I can't get the updated files now.
> However, I need the FFT very anxiously now, so I was wondering if you can send me
> the FFTImageFilter.cxx and the related files directly.
>    I'll be very appreciated for your answer!if possible, can you send it to me as
> the attached file?
> 
> 
> 
> 

==========================================
-------------- next part --------------
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: FFTImageFilter.cxx,v $
  Language:  C++
  Date:      $Date: 2004/11/14 23:56:03 $
  Version:   $Revision: 1.3 $

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/


//  Software Guide : BeginLatex
//
//  In this section we assume that you are familiar with Spectral Analysis, in
//  particular with the concepts of the Fourier Transform and the numerical
//  implementation of the Fast Fourier transform. If you are not familiar with
//  these concepts you may want to consult first any of the many available
//  introductory books to spectral analysis.
//
//  This example illustrates how to use the Fast Fourier Transform filter (FFT)
//  for processing an image in the spectral domain. Given that FFT computation
//  can be CPU intensive, there are multiple hardware specific impelmentations
//  of FFT. IT is convenient in many cases to delegate the actual computation
//  of the transform to local available libraries. Particular examples of those
//  libraries are fftw and the VXL implementation of FFT. For this reason ITK
//  provides a base abstract class that factorizes the interface to multiple
//  specific implementations of FFT. This base class is the
//  \doxygen{FFTRealToComplexConjugateImageFilter}, and two of its derived
//  classes are \doxygen{VnlFFTRealToComplexConjugateImageFilter} and
//  \doxygen{FFTWRealToComplexConjugateImageFilter}.
//  
//  
//  \index{itk::FFTRealToComplexConjugateImageFilter}
//  \index{itk::VnlFFTRealToComplexConjugateImageFilter}
//  \index{itk::FFTWRealToComplexConjugateImageFilter}
//
//  Software Guide : EndLatex 


// Software Guide : BeginCodeSnippet
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkVnlFFTRealToComplexConjugateImageFilter.h"
#include "itkComplexToRealImageFilter.h"
#include "itkComplexToImaginaryImageFilter.h"
// Software Guide : EndCodeSnippet


int main( int argc, char * argv [] )
{
  if( argc < 3 )
    {
    std::cerr << "Usage: " << argv[0] << " inputScalarImage  outputRealPartOfComplexImage" << std::endl;
    }


// Software Guide : BeginLatex
//
// The first decision to make is related to the pixel type and dimension of the
// images on which we want to compute the Fourier transform. 
//
// Software Guide : EndLatex 

// Software Guide : BeginCodeSnippet
  typedef float  PixelType;
  const unsigned int Dimension = 2;

  typedef itk::Image< PixelType, Dimension > ImageType;
// Software Guide : EndCodeSnippet


  typedef itk::ImageFileReader< ImageType >  ReaderType;

  ReaderType::Pointer reader = ReaderType::New();

  reader->SetFileName( argv[1] );




// Software Guide : BeginLatex
//
// We use the same image type in order to instantiate the FFT filter. In this
// case the \doxygen{VnlFFTRealToComplexConjugateImageFilter}. Note that
// contrary to most ITK filters, the FFT filter is instantiated using the Pixel
// type and the image dimension explicitly. Once the filter type is
// instantiated, we can use it for creating one object by invoking the
// \code{New()} method and assigning the result to a SmartPointer.
// 
// Software Guide : EndLatex 


// Software Guide : BeginCodeSnippet
  typedef itk::VnlFFTRealToComplexConjugateImageFilter< PixelType, Dimension >  FFTFilterType;

  FFTFilterType::Pointer filter = FFTFilterType::New();

  filter->SetInput( reader->GetOutput() );
// Software Guide : EndCodeSnippet




// Software Guide : BeginLatex
//
// The execution of the filter can be triggered by invoking the \code{Update()}
// method.  Since this invokation can eventually throw and exception, the call
// must be placed inside a try/catch block.
//
// Software Guide : EndLatex 

// Software Guide : BeginCodeSnippet
  try
    {
    filter->Update();
    }
  catch( itk::ExceptionObject & excp )
    {
    std::cerr << "Error: " << std::endl;
    std::cerr << excp << std::endl;
    return EXIT_FAILURE;
    }
// Software Guide : EndCodeSnippet




// Software Guide : BeginLatex
//
// We instantiate now the ImageFilter that will help us to extract the real
// part from the complex image.  The Filter that  we use here is the
// \doxygen{ComplexToRealImageFilter}. It takes as first template parameter the
// type of the complex image and as second template parameter it takes the type
// of the output image pixel.
//
// Software Guide : EndLatex 

// Software Guide : BeginCodeSnippet
  typedef FFTFilterType::OutputImageType    ComplexImageType;

  typedef itk::ComplexToRealImageFilter< ComplexImageType, ImageType > RealFilterType;
// Software Guide : EndCodeSnippet

  RealFilterType::Pointer realFilter = RealFilterType::New();

  realFilter->SetInput( filter->GetOutput() );


  typedef unsigned char WritePixelType;
  typedef itk::Image< WritePixelType, Dimension > WriteImageType;




// Software Guide : BeginLatex
//
// We instantiate now the filter type that will be used for rescaling the
// intensities of the \code{real} image into a range suitable for writing in a
// file. This is done with the \doxygen{RescaleIntensityImageFilter}. 
// 
// Software Guide : EndLatex 

// Software Guide : BeginCodeSnippet
  typedef itk::RescaleIntensityImageFilter< 
                                ImageType, 
                                WriteImageType > RescaleFilterType;
// Software Guide : EndCodeSnippet



  RescaleFilterType::Pointer intensityRescaler = RescaleFilterType::New();

  intensityRescaler->SetInput( realFilter->GetOutput() );

  intensityRescaler->SetOutputMinimum(  0  );
  intensityRescaler->SetOutputMaximum( 255 );

  typedef itk::ImageFileWriter< WriteImageType > WriterType;

  WriterType::Pointer writer = WriterType::New();

  writer->SetFileName( argv[2] );

  writer->SetInput( intensityRescaler->GetOutput() );

  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & excp )
    {
    std::cerr << "Error writing the real image: " << std::endl;
    std::cerr << excp << std::endl;
    return EXIT_FAILURE;
    }



// Software Guide : BeginLatex
//
// We instantiate now the ImageFilter that will help us to extract the
// imaginary part from the complex image.  The filter that we use here is the
// \doxygen{ComplexToImaginaryImageFilter}. It takes as first template parameter the
// type of the complex image and as second template parameter it takes the type
// of the output image pixel.
//
// Software Guide : EndLatex 

// Software Guide : BeginCodeSnippet
  typedef FFTFilterType::OutputImageType    ComplexImageType;

  typedef itk::ComplexToImaginaryImageFilter< ComplexImageType, ImageType > ImaginaryFilterType;
// Software Guide : EndCodeSnippet

  ImaginaryFilterType::Pointer imaginaryFilter = ImaginaryFilterType::New();

  imaginaryFilter->SetInput( filter->GetOutput() );


  intensityRescaler->SetInput( realFilter->GetOutput() );
  writer->SetFileName( argv[3] );

  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & excp )
    {
    std::cerr << "Error writing the imaginary image: " << std::endl;
    std::cerr << excp << std::endl;
    return EXIT_FAILURE;
    }


  return EXIT_SUCCESS;
}

-------------- next part --------------
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkComplexToImaginaryImageFilter.h,v $
  Language:  C++
  Date:      $Date: 2004/11/14 20:16:34 $
  Version:   $Revision: 1.1 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __itkComplexToImaginaryImageFilter_h
#define __itkComplexToImaginaryImageFilter_h

#include "itkUnaryFunctorImageFilter.h"
#include "vnl/vnl_math.h"

namespace itk
{
  
/** \class ComplexToImaginaryImageFilter
 * \brief Computes pixel-wise the imaginary part of a complex image.
 * 
 * \ingroup IntensityImageFilters  Multithreaded
 */
namespace Function {  
  
template< class TInput, class TOutput>
class ComplexToImaginary
{
public:
  ComplexToImaginary() {}
  ~ComplexToImaginary() {}
  inline TOutput operator()( const TInput & A )
  { return (TOutput)( A.imag() ); }
}; 
}

template <class TInputImage, class TOutputImage>
class ITK_EXPORT ComplexToImaginaryImageFilter :
    public
UnaryFunctorImageFilter<TInputImage,TOutputImage, 
                        Function::ComplexToImaginary< 
  typename TInputImage::PixelType, 
  typename TOutputImage::PixelType>   >
{
public:
  /** Standard class typedefs. */
  typedef ComplexToImaginaryImageFilter  Self;
  typedef UnaryFunctorImageFilter<TInputImage,TOutputImage, 
                                  Function::ComplexToImaginary< typename TInputImage::PixelType, 
                                                 typename TOutputImage::PixelType> >  Superclass;
  typedef SmartPointer<Self>   Pointer;
  typedef SmartPointer<const Self>  ConstPointer;

  /** Method for creation through the object factory. */
  itkNewMacro(Self);
  
protected:
  ComplexToImaginaryImageFilter() {}
  virtual ~ComplexToImaginaryImageFilter() {}

private:
  ComplexToImaginaryImageFilter(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented

};

} // end namespace itk


#endif
-------------- next part --------------
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkComplexToRealImageFilter.h,v $
  Language:  C++
  Date:      $Date: 2004/11/14 20:16:34 $
  Version:   $Revision: 1.1 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __itkComplexToRealImageFilter_h
#define __itkComplexToRealImageFilter_h

#include "itkUnaryFunctorImageFilter.h"
#include "vnl/vnl_math.h"

namespace itk
{
  
/** \class ComplexToRealImageFilter
 * \brief Computes pixel-wise the real(x) part of a complex image.
 * 
 * \ingroup IntensityImageFilters  Multithreaded
 */
namespace Function {  
  
template< class TInput, class TOutput>
class ComplexToReal
{
public:
  ComplexToReal() {}
  ~ComplexToReal() {}
  inline TOutput operator()( const TInput & A )
  { return (TOutput)( A.real() ); }
}; 
}

template <class TInputImage, class TOutputImage>
class ITK_EXPORT ComplexToRealImageFilter :
    public
UnaryFunctorImageFilter<TInputImage,TOutputImage, 
                        Function::ComplexToReal< 
  typename TInputImage::PixelType, 
  typename TOutputImage::PixelType>   >
{
public:
  /** Standard class typedefs. */
  typedef ComplexToRealImageFilter  Self;
  typedef UnaryFunctorImageFilter<TInputImage,TOutputImage, 
                                  Function::ComplexToReal< typename TInputImage::PixelType, 
                                                 typename TOutputImage::PixelType> >  Superclass;
  typedef SmartPointer<Self>   Pointer;
  typedef SmartPointer<const Self>  ConstPointer;

  /** Method for creation through the object factory. */
  itkNewMacro(Self);
  
protected:
  ComplexToRealImageFilter() {}
  virtual ~ComplexToRealImageFilter() {}

private:
  ComplexToRealImageFilter(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented

};

} // end namespace itk


#endif


More information about the Insight-users mailing list