[Insight-users] SecondDerivateRecursiveGaussianImageFilter problem

Robert Maroon robertmaroon at yahoo.com
Wed Nov 10 21:20:50 EST 2004


Hi all,

I am running ITK 1.8.1 and I have been trying to use
the SecondDerivateRecursiveGaussianImageFilter found
at Examples\Filtering\SecondDerivativeRecursiveGaussianImageFilter.cxx
on a large volume (>= 700x700x700) but it always
crashes the first time it reaches the line: 

gc->Update;

The only modification I have made to the example is
that the input and output pixel type is short instead
of float. It runs fine on smaller volumes but crashes
on anything bigger than 700x700x700. 

I am posting the code as found in examples with the
float parameter changed to short. I have also posted
some code below it that creates volumes with a sphere
in it. The argument list I used to create my test
volume was: BigSphere.mhd 700 700 700 200 200 200 100.
The first parameter is the name, the next three are
the dimensions of the volume, the next three are the
center of the sphere and the last one is the radius of
the sphere. 

Does anyone have any ideas what might be causing this?

Thanks!

Robert 
Volume Creator:

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRecursiveGaussianImageFilter.h"
#include "itkImageDuplicator.h"
#include <string.h>
#include <iostream>
#include <fstream>
#include "itkCastImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include <cmath>
using namespace std;


// Function prototypes
int CastUCharTOShortVol( const char *, const char * );

int main( int argc, char ** argv)
{
  char * inputImageName = argv[1];
  char * outputImageName = argv[2];
 
  CastUCharTOShortVol(inputImageName, outputImageName );

  return 0;
}

int CastUCharTOShortVol( const char * inputFile, const char * outputFile )
{
  typedef unsigned char         PixelType;
  typedef short      OutPixelType;
  const unsigned int             Dimension = 3;

  // Define the image type and dimensions
  typedef itk::Image< PixelType, Dimension >   ImageType;
  typedef itk::Image< OutPixelType, Dimension >   OutputImageType;

  // Define typedefs for the readers and writers
  typedef itk::ImageFileReader< ImageType >  ReaderType;
  typedef itk::ImageFileWriter< OutputImageType >  WriterType;
  typedef itk::CastImageFilter<ImageType, OutputImageType >  CastToShortFilterType;
  typedef itk::RescaleIntensityImageFilter< ImageType, OutputImageType >  RescaleFilterType;

  // Initialize pointers for the readers and writers
  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();
  CastToShortFilterType::Pointer castToShortFilter = CastToShortFilterType::New();
  RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
  
  // Set the input and output file names for the reader and writer
  reader->SetFileName( inputFile );
  writer->SetFileName( outputFile );

  // We can now access the input in the variable 'image'
  ImageType::Pointer image = reader->GetOutput();

  // Convert the image to float
  castToShortFilter->SetInput( image );
//  rescaleFilter->SetInput(image);
//  rescaleFilter->SetOutputMinimum(  0);
//  rescaleFilter->SetOutputMaximum(255);  
 
  // Set the input of the writer as the output of castToFloatFilter
  writer->SetInput ( castToShortFilter->GetOutput() );

  // Update the writer to send the image to the file specified by outFileName 
  // and outDataFileName
  try 
    { 
    writer->Update(); 
    } 
  catch( itk::ExceptionObject & err ) 
    { 
    std::cout << "ExceptionObject caught !" << std::endl; 
    std::cout << err << std::endl; 
    return -1;
    }

  return 0;
}
SecondDerivativeRecursiveGaussianImageFilter
#include "itkRecursiveGaussianImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImageDuplicator.h"
#include "itkImage.h"
#include <string>


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

  if( argc < 3 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << "SecondDerivativeRecursiveGaussianImageFilter inputImage outputPrefix  [sigma] " << std::endl;
    return -1;
    }

  typedef short            PixelType;
  typedef short            OutputPixelType;

  const unsigned int  Dimension = 3;

  typedef itk::Image< PixelType,       Dimension >  ImageType;
  typedef itk::Image< OutputPixelType, Dimension >  OutputImageType;
 
  typedef itk::ImageFileReader< ImageType       >   ReaderType;
  typedef itk::ImageFileWriter< OutputImageType >   WriterType;

  typedef itk::ImageDuplicator< OutputImageType >   DuplicatorType;

  typedef itk::RecursiveGaussianImageFilter< 
                                      ImageType, 
                                      ImageType >  FilterType;

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

  DuplicatorType::Pointer duplicator  = DuplicatorType::New();

  reader->SetFileName( argv[1] );
  
  std::string outputPrefix = argv[2];
  std::string outputFileName;

  try
    {
    reader->Update();
    }
  catch( itk::ExceptionObject & excp )
    {
    std::cerr << "Problem reading the input file" << std::endl;
    std::cerr << excp << std::endl;
    return -1;
    }

  FilterType::Pointer ga = FilterType::New();
  FilterType::Pointer gb = FilterType::New();
  FilterType::Pointer gc = FilterType::New();

  ga->SetDirection( 0 );
  gb->SetDirection( 1 );
  gc->SetDirection( 2 );

  if( argc > 3 )
    {
    const float sigma = atof( argv[3] );
    ga->SetSigma( sigma );
    gb->SetSigma( sigma );
    gc->SetSigma( sigma );
    }

  ga->SetZeroOrder();
  gb->SetZeroOrder();
  gc->SetSecondOrder();

  ImageType::Pointer inputImage = reader->GetOutput();

  ga->SetInput( inputImage );
  gb->SetInput( ga->GetOutput() );
  gc->SetInput( gb->GetOutput() );

  duplicator->SetInputImage( gc->GetOutput() );


  gc->Update(); 
  duplicator->Update();

  ImageType::Pointer Izz = duplicator->GetOutput();

  writer->SetInput( Izz );
  outputFileName = outputPrefix + "-Izz.mhd";
  writer->SetFileName( outputFileName.c_str() );
  writer->Update();

  gc->SetDirection( 1 );  // gc now works along Y
  gb->SetDirection( 2 );  // gb now works along Z

  gc->Update();
  duplicator->Update();

  ImageType::Pointer Iyy = duplicator->GetOutput();

  writer->SetInput( Iyy );
  outputFileName = outputPrefix + "-Iyy.mhd";
  writer->SetFileName( outputFileName.c_str() );
  writer->Update();


  gc->SetDirection( 0 );  // gc now works along X
  ga->SetDirection( 1 );  // ga now works along Y

  gc->Update();
  duplicator->Update();

  ImageType::Pointer Ixx = duplicator->GetOutput();

  writer->SetInput( Ixx );
  outputFileName = outputPrefix + "-Ixx.mhd";
  writer->SetFileName( outputFileName.c_str() );
  writer->Update();


  ga->SetDirection( 0 );
  gb->SetDirection( 1 );
  gc->SetDirection( 2 );

  ga->SetZeroOrder();
  gb->SetFirstOrder();
  gc->SetFirstOrder();

  gc->Update();
  duplicator->Update();

  ImageType::Pointer Iyz = duplicator->GetOutput();

  writer->SetInput( Iyz );
  outputFileName = outputPrefix + "-Iyz.mhd";
  writer->SetFileName( outputFileName.c_str() );
  writer->Update();


  ga->SetDirection( 1 );
  gb->SetDirection( 0 );
  gc->SetDirection( 2 );

  ga->SetZeroOrder();
  gb->SetFirstOrder();
  gc->SetFirstOrder();

  gc->Update();
  duplicator->Update();

  ImageType::Pointer Ixz = duplicator->GetOutput();

  writer->SetInput( Ixz );
  outputFileName = outputPrefix + "-Ixz.mhd";
  writer->SetFileName( outputFileName.c_str() );
  writer->Update();

  ga->SetDirection( 2 );
  gb->SetDirection( 0 );
  gc->SetDirection( 1 );

  ga->SetZeroOrder();
  gb->SetFirstOrder();
  gc->SetFirstOrder();

  gc->Update();
  duplicator->Update();

  ImageType::Pointer Ixy = duplicator->GetOutput();

  writer->SetInput( Ixy );
  outputFileName = outputPrefix + "-Ixy.mhd";
  writer->SetFileName( outputFileName.c_str() );
  writer->Update();

  // Software Guide : EndCodeSnippet
  
return 0;
}




			
---------------------------------
Do you Yahoo!?
 Check out the new Yahoo! Front Page. www.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20041110/06d73f46/attachment-0001.htm


More information about the Insight-users mailing list