[Insight-users] GradientAnisotropicDiffusionImageFilter

Bill Lorensen bill.lorensen at gmail.com
Tue Oct 7 13:41:42 EDT 2008


Mari,

In itk, it is good practice to enclose each Update() in a try/ctach
block. If an exception occurs you will see a more descriptive error
message.

For example, for filter->Update()

try
  {
  filter->Update();
  }
catch(itk::ExceptionObject &err)
  {
  (&err)->Print(std::cerr);
  return EXIT_FAILURE;
  }

Place similar code around each of your ->Update()'s.

Bill

On Tue, Oct 7, 2008 at 12:50 PM, mariangelalucente at inwind.it
<mariangelalucente at inwind.it> wrote:
> Hi,
> I test GradientAnisotropicDiffusionImageFilter from ITK .cxx on 3D MRI data, but occurs the error "Segmentation Fault".
> Could you help me?
> I list the code that I have used.
> Thank you
> Mari
>
>
>
>
>
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
>
> #ifdef __BORLANDC__
> #define ITK_LEAN_AND_MEAN
> #endif
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkRescaleIntensityImageFilter.h"
>
> #include "itkGradientAnisotropicDiffusionImageFilter.h"
> int main( int argc, char * argv[] )
> {
>  if( argc < 6 )
>    {
>    std::cerr << "Usage: " << std::endl;
>    std::cerr << argv[0] << "  inputImageFile  outputImageFile ";
>    std::cerr << "numberOfIterations  timeStep  conductance" << std::endl;
>    return EXIT_FAILURE;
>    }
>
> typedef    float    InputPixelType;
>  typedef    float    OutputPixelType;
>
>  typedef itk::Image< InputPixelType,  2 >   InputImageType;
>  typedef itk::Image< OutputPixelType, 2 >   OutputImageType;
>
> typedef itk::ImageFileReader< InputImageType >  ReaderType;
>
> typedef itk::GradientAnisotropicDiffusionImageFilter<
>               InputImageType, OutputImageType >  FilterType;
>  FilterType::Pointer filter = FilterType::New();
> ReaderType::Pointer reader = ReaderType::New();
>  reader->SetFileName( argv[1] );
>
> filter->SetInput( reader->GetOutput() );
> const unsigned int numberOfIterations = atoi( argv[3] );
>
>  const double       timeStep = atof( argv[4] );
>
>  const double       conductance = atof( argv[5] );
>
> filter->SetNumberOfIterations( numberOfIterations );
>  filter->SetTimeStep( timeStep );
>  filter->SetConductanceParameter( conductance );
>
>  filter->Update();
> typedef unsigned char WritePixelType;
>  typedef itk::Image< WritePixelType, 2 > WriteImageType;
>  typedef itk::RescaleIntensityImageFilter<
>               OutputImageType, WriteImageType > RescaleFilterType;
>
>  RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
>  rescaler->SetOutputMinimum(   0 );
>  rescaler->SetOutputMaximum( 255 );
>
>  typedef itk::ImageFileWriter< WriteImageType >  WriterType;
>
>  WriterType::Pointer writer = WriterType::New();
>  writer->SetFileName( argv[2] );
>
>
>  rescaler->SetInput( filter->GetOutput() );
>  writer->SetInput( rescaler->GetOutput() );
>  writer->Update();
>
>  return EXIT_SUCCESS;
> }
>
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list