[Insight-users] Still some issues with reading/writing complex pixels

Martin Kavec kavec at messi.uku.fi
Tue May 24 06:45:05 EDT 2005


Hi Luis,

I have updated my Insight source from CVS this morning and the compilation 
problem I reported to you yesterday was gone. However, I still have problem 
with reading/writing (not sure yet where exactly) complex pixel images.

The code below compiles fine, but if I run it with complex-pixel image:

http://www.uku.fi/~kavec/complexImage.mhd
http://www.uku.fi/~kavec/complexImage.raw

, which is a product of a FFTImageFilter, all the real (in Analyze), imaginary 
(in Analyze) and complex (in mhd/raw) images are blank (zeros). Now I am not 
sure if there are still some issues with newly included IO of complex-pixel 
images or I have a mistake in my code.

Thanks a lot.

Martin


#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkComplexToRealImageFilter.h"
#include "itkComplexToImaginaryImageFilter.h"

#include "itkImage.h"

#include <complex>

int main( int argc, char ** argv )
{
  // Verify the number of parameters in the command line
  if( argc < 5 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImageFile  realImageFile imagImageFile                       
      complexImageFile " << std::endl;
    return EXIT_FAILURE;
    }

  typedef std::complex<double> ComplexPixelType;
  const   unsigned int        Dimension = 2;

  typedef itk::Image< ComplexPixelType, Dimension > ComplexImageType;
  typedef itk::Image< double, Dimension >           OutputImageType;

  typedef itk::ImageFileReader< ComplexImageType >  ReaderType;

  typedef itk::ImageFileWriter< OutputImageType >   WriterType;
  typedef itk::ImageFileWriter< ComplexImageType >   ComplexWriterType;

  typedef itk::ComplexToRealImageFilter< ComplexImageType, OutputImageType >         
                       RealFilterType;
  typedef itk::ComplexToImaginaryImageFilter<ComplexImageType, 
OutputImageType> ImagFilterType;

  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer realWriter = WriterType::New();
  WriterType::Pointer imagWriter = WriterType::New();
  ComplexWriterType::Pointer complexWriter = ComplexWriterType::New();

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

  const char * inputFilename  = argv[1];
  const char * realFilename = argv[2];
  const char * imagFilename = argv[3];
  const char * complexFilename = argv[4];

  reader->SetFileName( inputFilename  );
  realWriter->SetFileName( realFilename );
  imagWriter->SetFileName( imagFilename );
  complexWriter->SetFileName( complexFilename );

  realFilter->SetInput( reader->GetOutput() );
  imagFilter->SetInput( reader->GetOutput() );

  realWriter->SetInput( realFilter->GetOutput() );
  imagWriter->SetInput( imagFilter->GetOutput() );
  complexWriter->SetInput( reader->GetOutput() );

  try 
    { 
    realWriter->Update(); 
    imagWriter->Update();
    complexWriter->Update();
    } 
  catch( itk::ExceptionObject & err ) 
    { 
    std::cout << "ExceptionObject caught !" << std::endl; 
    std::cout << err << std::endl; 
    return EXIT_FAILURE;
    } 

  return EXIT_SUCCESS;
}


More information about the Insight-users mailing list